ROUND 第二个参数只需要常量 + hive

ROUND second argument only takes constant + hive

以下:

hive> create table t1 (val double, digit int);
hive> insert into t1 values(10,2);
hive> insert into t1 values(156660,3);
hive> insert into t1 values(8765450,4);
hive> select round(val, digit) from round_test;

出现此错误:

FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments 'digit': ROUND second argument only takes constant

它在 impala 中工作正常。

谁能帮我指出错误的来源?

错误说 ROUND 的第二个参数必须是一个常数。即对于配置单元,您不能将列用作 ROUND 函数的第二个参数。如果您需要这样做,我建议您创建 UDF。

    BigDecimal a = new BigDecimal(value);
    BigDecimal roundOff = a.setScale(places, BigDecimal.ROUND_HALF_EVEN);
    return roundOff.doubleValue();

感谢马克的快速回复。

我已经用UDF解决了这个问题。因为这是一个已知问题 HIVE-4523。以为已经应用了一些补丁。