今天帮助一个朋友排查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
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,...
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
本文介绍了在使用Hive进行动态分区插入时遇到的问题及解决方法。问题出现在使用substr函数设置分区字段时,通过调整字段名称和将表达式包含在select列表中解决了问题。
752





