You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@impala.apache.org by Santanu Chatterjee <sa...@gmail.com> on 2017/08/14 20:39:28 UTC

how to pass constant parameter to Init() function of UDAF

I am trying to develop a UDAF which takes three parameters. SQL syntax
would look like this :

select myudaf(col1, 1, 100) from mytab;

Here col1 is from table mytab and of type numeric (double/int etc.). The
other two parameters are constants. The third parameter determines memory
allocation for intermediate results. Therefore, I need to access it from
Init() function. Here is how I developed my update and init functions :

void myUDAFInit(FunctionContext *ctx, StringVal *dst);
void myUDAFUpdate(FunctionContext *ctx, const DoubleVal& d, const IntVal&,
const IntVal&, StringVal* result);

Also, I am defining my UDAF like this :

create aggregate function myUDAF(double, int, int) returns... ;

However, when I try to access function arguments in my Init() function, it
says the arguments are non-constant. Is there a different way to define
constant arguments?

Thanks in Advance.

Re: how to pass constant parameter to Init() function of UDAF

Posted by Tim Armstrong <ta...@cloudera.com>.
If you're running an older version of Impala you could be hitting
https://issues.apache.org/jira/browse/IMPALA-2379

On Mon, Aug 14, 2017 at 1:49 PM, Tim Armstrong <ta...@cloudera.com>
wrote:

> Hi Santanu,
>   Thanks for your interest. I can probably help you out given a bit more
> info. Whether the arguments are constant or not is determined based on
> analysis of the input expression to your function. In your case 1 and 100
> are definitely constant.
>
> What version of Impala are you running? Could you also show us the actual
> code for your UDAF (or an simplified reproduction of the problem), the SQL
> commands you ran and the output?
>
> - Tim
>
> On Mon, Aug 14, 2017 at 1:39 PM, Santanu Chatterjee <
> santanu.chatter@gmail.com> wrote:
>
>> I am trying to develop a UDAF which takes three parameters. SQL syntax
>> would look like this :
>>
>> select myudaf(col1, 1, 100) from mytab;
>>
>> Here col1 is from table mytab and of type numeric (double/int etc.). The
>> other two parameters are constants. The third parameter determines memory
>> allocation for intermediate results. Therefore, I need to access it from
>> Init() function. Here is how I developed my update and init functions :
>>
>> void myUDAFInit(FunctionContext *ctx, StringVal *dst);
>> void myUDAFUpdate(FunctionContext *ctx, const DoubleVal& d, const IntVal&,
>> const IntVal&, StringVal* result);
>>
>> Also, I am defining my UDAF like this :
>>
>> create aggregate function myUDAF(double, int, int) returns... ;
>>
>> However, when I try to access function arguments in my Init() function, it
>> says the arguments are non-constant. Is there a different way to define
>> constant arguments?
>>
>> Thanks in Advance.
>>
>
>

Re: how to pass constant parameter to Init() function of UDAF

Posted by Tim Armstrong <ta...@cloudera.com>.
Hi Santanu,
  Thanks for your interest. I can probably help you out given a bit more
info. Whether the arguments are constant or not is determined based on
analysis of the input expression to your function. In your case 1 and 100
are definitely constant.

What version of Impala are you running? Could you also show us the actual
code for your UDAF (or an simplified reproduction of the problem), the SQL
commands you ran and the output?

- Tim

On Mon, Aug 14, 2017 at 1:39 PM, Santanu Chatterjee <
santanu.chatter@gmail.com> wrote:

> I am trying to develop a UDAF which takes three parameters. SQL syntax
> would look like this :
>
> select myudaf(col1, 1, 100) from mytab;
>
> Here col1 is from table mytab and of type numeric (double/int etc.). The
> other two parameters are constants. The third parameter determines memory
> allocation for intermediate results. Therefore, I need to access it from
> Init() function. Here is how I developed my update and init functions :
>
> void myUDAFInit(FunctionContext *ctx, StringVal *dst);
> void myUDAFUpdate(FunctionContext *ctx, const DoubleVal& d, const IntVal&,
> const IntVal&, StringVal* result);
>
> Also, I am defining my UDAF like this :
>
> create aggregate function myUDAF(double, int, int) returns... ;
>
> However, when I try to access function arguments in my Init() function, it
> says the arguments are non-constant. Is there a different way to define
> constant arguments?
>
> Thanks in Advance.
>