在配置单元中检索udf结果

vaqhlq81  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(320)

在以下hiveql代码中,我想向现有表添加分区:

-- 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

但是,上面的代码不起作用,为什么?还有别的办法吗?

qoefvg9y

qoefvg9y1#

配置单元需要alter分区中的文本

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

另外,当前的\u日期只能从Hive2.0中获得,因此基于您的错误,您可能正在使用较低的版本。
解决方法。
用以下语句编写一个文件

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

并调用hive-like(在linux中)

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

我希望这对你有帮助。
ps:我想在Hive2.0中尝试使用alter命令和current\u date,无论如何,您应该像current\u date一样使用它,而不是current\u date()

相关问题