You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Dan Fan <df...@appnexus.com> on 2014/09/24 20:42:02 UTC

HiveException: Stateful expressions cannot be used inside of CASE

Hi Hive Users:

I have a hive generic hive udf which is called protect_column.
The udf works fine when I call it along.
But when I run the following query:



 select case when id = 5 then protect_column(id, 'age', 12L) else id end from one_row_table ;


It says


Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Stateful expressions cannot be used inside of CASE


I was reading the source code. And I think it is related to GenericCase and GenericWhen according to

https://svn.apache.org/repos/asf/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ExprNodeGenericFuncEvaluator.java?p=1197837

Could anyone help explain explicitly what exactly is genericCase GenericWhen and why we cannot put the udf inside a case when ?

Thanks for your time helping me out

Best

Dan

Re: HiveException: Stateful expressions cannot be used inside of CASE

Posted by Navis류승우 <na...@nexr.com>.
Stateful function should be called for all input rows but in if/when
clause, it cannot be guaranteed.

Any reason to declare "protect_column" function to be stateful?

Thanks,
Navis

2014-09-25 3:42 GMT+09:00 Dan Fan <df...@appnexus.com>:

>  Hi Hive Users:
>
>  I have a hive generic hive udf which is called protect_column.
> The udf works fine when I call it along.
> But when I run the following query:
>
>
>   select case when id = 5 then protect_column(id, 'age', 12L) else id end
> from one_row_table ;
>
>
>  It says
>
>
>  Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Stateful
> expressions cannot be used inside of CASE
>
>
>  I was reading the source code. And I think it is related to GenericCase
> and GenericWhen according to
>
>
> https://svn.apache.org/repos/asf/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ExprNodeGenericFuncEvaluator.java?p=1197837
>
>  Could anyone help explain explicitly what exactly is genericCase
> GenericWhen and why we cannot put the udf inside a case when ?
>
>  Thanks for your time helping me out
>
>  Best
>
>  Dan
>