今天帮助一个朋友排查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