我正在尝试在 Hive 中执行以下操作
设置今天=“2013-11-04”;//这有效
设置今天 = to_date(from_unixtime(unix_timestamp()));//这不是..
今天设置; TODAY=to_date(from_unixtime(unix_timestamp()))
有什么建议吗?
最佳答案
SET TODAY = to_date(from_unixtime(unix_timestamp()));
这在 Hive 中不可用。 你能做的是
select concat ('set TODAY=',to_date(from_unixtime(unix_timestamp())),'\;') from testTableName limit 1 >>/path/to/HQL/file/fileName.sql
现在在文件fileName.sql中,您将看到
set TODAY=2013-11-05;
在运行其他相关查询之前需要加载文件fileName.sql。你可以这样做:
hive -f hiveQueries.sql
您的文件hiveQueries.sql应包含如下内容:
use testDB;
source /path/to/HQL/file/fileName.sql;
select * from testTable where someColumn=${hiveconf:TODAY};
希望这有帮助..:)
关于hadoop - Hive 变量替换为函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19775040/