Unix_TIMESTAMP for hive在Shell脚本中不起作用

时间:2018-02-16 13:56:30

标签: shell hive hiveql

我正在运行配置单元查询

Map<Integer, List<Record>> map = list.stream() .collect(Collectors.groupingBy( Record::getId, Collectors.collectingAndThen( Collectors.toList(), records -> records.stream() .sorted(Comparator.comparing(Record::getName)) .limit(limit) .collect(Collectors.toList()))));

它返回NULL。 prvate是hive -hiveconf prvDate=$prvDate -S -e "select max(ID) from Employee where unix_timestamp(date,'dd-MM-yyyy') > unix_timestamp('${hiveconf:prvDate}','dd-MM-yyyy')"

但是当我在Hive中运行相同的脚本时

15-12-2017

我能看到结果。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

如果您在shell脚本中使用内联SQL运行配置单元,则不需要传递-hiveconf变量,而是使用shell替换。

示例(shell):

prvDate="01-01-2017"

hive -S -e "select unix_timestamp('$prvDate','dd-MM-yyyy')"

输出: 1483257600

仅在执行SQL脚本文件时使用--hiveconf:

hive --hiveconf bla="$bla" -f myscript.hql

答案 1 :(得分:0)

这是因为您正在调用hiveconf var,更改名称并且它应该可以正常工作

obj.method