【问题标题】:Autoincrement UDF works in hive but returns null in Impala自动增量 UDF 在 hive 中工作,但在 Impala 中返回 null
【发布时间】:2015-04-06 20:09:37
【问题描述】:

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

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

【问题讨论】:

    标签: java impala udf


    【解决方案1】:

    不幸的是,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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-19
      • 1970-01-01
      • 2020-02-15
      • 2015-09-19
      • 1970-01-01
      相关资源
      最近更新 更多