hive语句 partition(dt=substr('2016-12-01',1,7))取分区问题

来源:互联网 发布:程序员交流 编辑:程序博客网 时间:2024/06/09 19:15
今天帮助一个朋友排查hive语句的问题,如下:
insert overwrite table database.table
partition(dt=substr('2016-12-01',1,7))
select substr('2016-12-01',1,7) as month,...

报错:
cannot recognize input near 'substring' '(' ''2016-12-01'' in constant

问题出现partition(dt=substr('2016-12-01',1,7))这部分


执行这个查询语句没有问题
select substr('2016-12-01',1,7) as month,...

网上查找到:
for dynamic partitions the partition clause must look like
PARTITION(year, month, edate)
the actual expressions should be included in the select list. So in your
example the select list should look something like
SELECT sh.EVENT_TIME, sh.person_NAME, substring(event_time, 0, 4) as year,

解决方法:
insert overwrite table database.table
partition(dt)
select substr('2016-12-01',1,7) as dt,...

dt是分区的字段名称


参考:http://mail-archives.apache.org/mod_mbox/hive-user/201204.mbox/%3CCAOn+50K1LYvBN4LGz=CHDNeoqYAgg0f+uGA5bb2noH0VmidSsA@mail.gmail.com%3E

0 0
原创粉丝点击