【问题标题】:Hive Variable Substitution with function带函数的 Hive 变量替换
【发布时间】:2013-11-04 19:00:41
【问题描述】:

我正在尝试在 Hive 中进行以下操作

设置 TODAY="2013-11-04"; //这行得通

今天设置 = to_date(from_unixtime(unix_timestamp())); //这不是..

设置今天; TODAY=to_date(from_unixtime(unix_timestamp()))

有什么建议吗?

【问题讨论】:

  • 是的,如果 HQL 添加一些控制功能会很棒,但现在,会从 shell 中传入,例如 hive --hiveconf TODAY=$(date +"%Y-%m-%d")

标签: hadoop hive


【解决方案1】:
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};

希望这会有所帮助..:)

【讨论】:

    猜你喜欢
    • 2014-09-11
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多