在Hive中检索udf结果 [英] retrieve udf results in Hive
问题描述
- my_table被定义和分区通过'dt字符串,这是日期
- 现在我想添加分区
alter table my_table add如果不存在
分区(dt = current_date()); ('expect')接近'< EOF>'
alter table my_table如果不存在,则添加
partition(dt = $ {current_date() }); #FAILED:ParseException行1:60无法识别在
蜂巢希望在alter partition中使用文字
NoViableAltException(26 @ [215:1:constant:(Number | dateLiteral | timestampLiteral | StringLiteral | stringLiteralSequence | BigintLiteral | SmallintLiteral | TinyintLiteral | DecimalLiteral | charSetStringLiteral | booleanValue);]])
另外,CURRENT_DATE只能在Hive 2.0中使用,所以根据你的错误,可能你正在工作使用较低版本。
解决方法。
使用以下语句编写文件
ALTER TABLE my_table如果不存在则添加partition(dt ='$ {hiveconf:mytime}')
并调用配置单元(在linux中)
mydate = $(date +%m-%d-%y)
hive -S -hiveconf mytime = $ mydate -f test.hql
我希望有所帮助。
PS:我想在Hive 2.0中用CURRENT_DATE尝试alter命令,无论如何,你应该像CURRENT_DATE而不是CURRENT_DATE()一样使用它。 b
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?
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()
这篇关于在Hive中检索udf结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!