You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@drill.apache.org by Muhammad Gelbana <m....@gmail.com> on 2017/01/17 16:39:00 UTC

How to create a UDF with variable length parameters ?

Is there a way to create a UDF that supports typically 1 or more parameters
? Parameters may be columns, literals or NULLs and the return may be NULL
or a value.

It would be still possible to overload such a UDF by declaring one with a
different type of variables, correct ?

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana

Re: How to create a UDF with variable length parameters ?

Posted by Muhammad Gelbana <m....@gmail.com>.
Thanks a lot but this doesn't entirely solve my problem.

Is there a way to pass an *array* of parameters instead ? As in: SELECT
my_udf*([*column1, column2*])* from cp.`employees.json`
It will eventually be a single parameter, but will hold the values I need.

I tried so but I couldn't find a valid syntax to pass an array to a UDF, is
that possible ?

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana

On Tue, Jan 17, 2017 at 7:31 PM, Arina Yelchiyeva <
arina.yelchiyeva@gmail.com> wrote:

> You can create several functions with the same name but with different
> parameters types and / or quantity.
>
> Example:
> *bool_or* [1] function can have different input parameter: BitHolder or
> NullableBitHolder
> *maxdir* [2] can have one or two input parameters (but code is in template
> you have to build Drill project to see generated DirectoryExplorers.class).
>
>
> [1] https://github.com/apache/drill/blob/5a4ad2a88331dfe7561
> ee76fc87e882afe170681/exec/java-exec/src/main/java/org/
> apache/drill/exec/expr/fn/impl/BooleanAggrFunctions.java
> [2] https://github.com/apache/drill/blob/1e6fa00cd4b0b1db416
> 14749f6d12c03f0ca7990/exec/java-exec/src/main/codegen/
> templates/DirectoryExplorers.java
>
> On Tue, Jan 17, 2017 at 6:39 PM, Muhammad Gelbana <m....@gmail.com>
> wrote:
>
> > Is there a way to create a UDF that supports typically 1 or more
> parameters
> > ? Parameters may be columns, literals or NULLs and the return may be NULL
> > or a value.
> >
> > It would be still possible to overload such a UDF by declaring one with a
> > different type of variables, correct ?
> >
> > *---------------------*
> > *Muhammad Gelbana*
> > http://www.linkedin.com/in/mgelbana
> >
>

Re: How to create a UDF with variable length parameters ?

Posted by Arina Yelchiyeva <ar...@gmail.com>.
You can create several functions with the same name but with different
parameters types and / or quantity.

Example:
*bool_or* [1] function can have different input parameter: BitHolder or
NullableBitHolder
*maxdir* [2] can have one or two input parameters (but code is in template
you have to build Drill project to see generated DirectoryExplorers.class).


[1] https://github.com/apache/drill/blob/5a4ad2a88331dfe7561
ee76fc87e882afe170681/exec/java-exec/src/main/java/org/
apache/drill/exec/expr/fn/impl/BooleanAggrFunctions.java
[2] https://github.com/apache/drill/blob/1e6fa00cd4b0b1db416
14749f6d12c03f0ca7990/exec/java-exec/src/main/codegen/
templates/DirectoryExplorers.java

On Tue, Jan 17, 2017 at 6:39 PM, Muhammad Gelbana <m....@gmail.com>
wrote:

> Is there a way to create a UDF that supports typically 1 or more parameters
> ? Parameters may be columns, literals or NULLs and the return may be NULL
> or a value.
>
> It would be still possible to overload such a UDF by declaring one with a
> different type of variables, correct ?
>
> *---------------------*
> *Muhammad Gelbana*
> http://www.linkedin.com/in/mgelbana
>