1

我创建了一个创建自动增量值的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;
    }
}

创建 Hive 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 

非常感谢任何帮助!谢谢你,安娜

4

1 回答 1

2

不幸的是,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 分析函数

于 2015-04-21T21:48:53.340 回答