retrieve udf results in Hive

Deadly 提交于 2019-12-12 04:33:11

问题


In the following HiveQL code, I want to add partition to an existing table:

-- my_table was defined and partitioned by `dt string`, which is date
-- now I want to add partition
alter table my_table add if not exists
partition (dt=current_date());   #FAILED: ParseException line 1:72 extraneous input '(' expecting ) near '<EOF>'

alter table my_table add if not exists
partition (dt=${current_date()});   # FAILED: ParseException line 1:60 cannot recognize input near '$' '{' 'current_date' in constant

However, the above code won't work, why? Any other way to do it?


回答1:


Hive expect literals in the alter partition

NoViableAltException(26@[215:1: constant : ( Number | dateLiteral | timestampLiteral | StringLiteral | stringLiteralSequence | BigintLiteral | SmallintLiteral | TinyintLiteral | DecimalLiteral | charSetStringLiteral | booleanValue );])

Also, the CURRENT_DATE is only available from Hive 2.0, so based in your error, probably you are working with a lower version.

Workaround.

Write a file with the following statement

ALTER TABLE my_table add if not exists partition(dt= '${hiveconf:mytime}')

and call hive like (in linux)

mydate=$(date +"%m-%d-%y")
hive -S -hiveconf mytime=$mydate-f test.hql

I hope that help.

PS: I would like to try the alter command with CURRENT_DATE in Hive 2.0, anyway you should use it like CURRENT_DATE instead of CURRENT_DATE()



来源:https://stackoverflow.com/questions/41825726/retrieve-udf-results-in-hive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!