【问题标题】:Hive Variables in Where ClauseWhere 子句中的 Hive 变量
【发布时间】:2019-02-07 14:37:11
【问题描述】:

SELECT * FROM 表名 其中 1=1 (AND COL1=VALUE1 AND COL2=VALUE2) --->$(VAR)

SELECT * FROM 表名 其中 1=1 $(VAR)

这在 Hive 中可行吗?

【问题讨论】:

标签: hive


【解决方案1】:

是的,有可能。

set hivevar:var1='and col1=10 and col2=10';

! echo "select * from table where 1=1 ${hivevar:var1}";
select ${hivevar:var1}


[prjai@lnx0689 prvys]$ hive -f test.hql
"select * from table where 1=1 'and col1=10 and col2=10'"
OK
and col1=10 and col2=10
Time taken: 2.152 seconds, Fetched: 1 row(s)

有关如何使用 hivevar 和 hiveconf 的更多详细信息,请参阅 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+VariableSubstitution

What is the difference between -hivevar and -hiveconf?

【讨论】:

    【解决方案2】:

    先设置hive变量变量。

     set hivevar:queryPortion='and col1=value1 and col2=value2';
    

    然后在您的查询中检索它

     select * from table where 1=1 ${queryPortion}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 2015-01-30
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 2014-04-11
      相关资源
      最近更新 更多