我创建了一个创建自动增量值的java函数,我还创建了一个基于此函数的hive UDF,它在hive中工作得很好。我基于此函数创建了一个Impala UDF,它返回'null‘而不是自动递增整数。
下面是java的UDF代码:
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.udf.UDFType;
@UDFType(stateful = true)
public class AutoIncrementUDF extends UDF {
int ctr;
public int evaluate() {
ctr++;
return ctr;
}
}创建配置单元UDF:
create function autoincr as 'AutoIncrementUDF';创建Impala UDF:
create function autoincr() returns int LOCATION '/user/acombs/AutoIncrementUDF.jar' symbol='AutoIncrementUDF';在Hive和Impala中使用它:
select autoincr() as testkey, * from mapfund 任何帮助都是非常感谢的!谢谢你,安娜
发布于 2015-04-22 05:48:53
不幸的是,Impala不支持@UDFType注释或有状态Hive UDF的概念。我们将在我们的文档中添加一条注释,以使这一限制公之于众。
但是,如果您试图返回行号,则可以使用ROW_NUMBER()等分析窗口函数。
例如,
> select ROW_NUMBER() over (order by int_col) as testkey, int_col, float_col from alltypestiny;
+---------+---------+-------------------+
| testkey | int_col | float_col |
+---------+---------+-------------------+
| 1 | 0 | 0 |
| 2 | 0 | 0 |
| 3 | 0 | 0 |
| 4 | 0 | 0 |
| 5 | 1 | 1.100000023841858 |
| 6 | 1 | 1.100000023841858 |
| 7 | 1 | 1.100000023841858 |
| 8 | 1 | 1.100000023841858 |
+---------+---------+-------------------+
Fetched 8 row(s) in 0.12s有关更多详细信息,请参阅Impala Analytic Functions。
https://stackoverflow.com/questions/29478848
复制相似问题