Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Drill >> mail # dev >> abs() function implementation


Copy link to this message
-
Re: abs() function implementation
You don't need to register the "abs" function twice. You can just have one
CallProvider that will define the "abs" function for all applicable types.
You could use "absolute value" as the name. And then in the function
template, all absolute value functions will use the "absolute value" name.
The code generator figures out which function to use based on the input
type.
On Wed, Aug 21, 2013 at 9:21 PM, Tanujit Ghosh <[EMAIL PROTECTED]>wrote:

> Hi,
>
> I'm trying to implement the abs() function within drill.
>
> Now the abs() function can work with int,bigint as well as other numeric
> types.
>
> so i have done this, but this is failing as we cannot register twice. How
> do we handle this situation where the corresponding function implementation
> is called based on the input parameter data type.
>
> I'm bit lost here.
>
> @FunctionTemplate(name = "absolute_int",
>     scope = FunctionTemplate.FunctionScope.SIMPLE,
>     nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
>   public static class AbsoluteInt implements DrillFunc {
>
>     @Param IntHolder input;
>     @Output IntHolder out;
>
>     public void setup(RecordBatch b){}
>
>     public void eval(){
>       out.value = Math.abs(input.value);
>     }
>
>     public static class Provider implements CallProvider {
>
>       @Override
>       public FunctionDefinition[] getFunctionDefintions() {
>         return new FunctionDefinition[] {
>           FunctionDefinition.simple("absolute_int",
>             new BasicArgumentValidator(new Arg(Types.required(
> TypeProtos.MinorType.INT))),
>             new OutputTypeDeterminer.SameAsFirstInput(),
>             "abs")
>         };
>       }
>     }
>   }
>
>   @FunctionTemplate(name = "absolute_bigint",
>     scope = FunctionTemplate.FunctionScope.SIMPLE,
>     nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
>   public static class AbsoluteBigInt implements DrillFunc {
>
>     @Param BigIntHolder input;
>     @Output BigIntHolder out;
>
>     public void setup(RecordBatch b){}
>
>     public void eval(){
>       out.value = Math.abs(input.value);
>     }
>
>     public static class Provider implements CallProvider {
>
>       @Override
>       public FunctionDefinition[] getFunctionDefintions() {
>         return new FunctionDefinition[] {
>           FunctionDefinition.simple("absolute_bigint",
>             new BasicArgumentValidator(new
> Arg(Types.required(TypeProtos.MinorType.BIGINT))),
>             new OutputTypeDeterminer.SameAsFirstInput(),
>             "abs")
>         };
>       }
>     }
>   }
>
>
> Thanks and Regards,
> Tanujit
>
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB