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

时间:2016-05-12 06:28:35

标签: hive arguments constants rounding

以下内容:

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;

给出了这个错误:

  

失败:SemanticException [错误10014]:第1行:7错误的参数   'digit':ROUND第二个参数只取常量

它在黑斑羚中工作正常。

有人可以帮我指出错误的来源吗?

2 个答案:

答案 0 :(得分:1)

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

感谢Mark的快速回复。

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

答案 1 :(得分:0)

错误说ROUND的secund参数必须是costant。即使用hive,您不能使用列作为ROUND函数的secund参数。如果您需要这样做,我建议您创建UDF。