Java Autoincrement UDF在配置单元中工作,但在Impala中返回null
我创建了一个java函数来创建自动增量值,我还基于这个函数创建了一个hive UDF,它在hive中工作得非常好。我基于这个函数创建了一个Impala UDF,它返回'null'而不是自动递增整数 以下是java UDF代码:Java Autoincrement UDF在配置单元中工作,但在Impala中返回null,java,impala,udf,Java,Impala,Udf,我创建了一个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 AutoInc
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';
在蜂巢和黑斑羚中使用它:
select autoincr() as testkey, * from mapfund
非常感谢您的帮助!
非常感谢。
Anna不幸的是,Impala不支持
@UDFType
注释或有状态蜂巢UDF的概念。我们将在文档中添加一个注释,以说明此限制
但是,如果要返回行号,可以使用分析窗口函数,如row\u 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
有关更多详细信息,请参阅