选择* FROM表名 在1 = 1 (AND COL1 = VALUE1 AND COL2 = VALUE2)---> $(VAR)
选择* FROM表名 在1 = 1 $(VAR)
在Hive中有可能吗?
答案 0 :(得分: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
答案 1 :(得分:0)
首先设置蜂巢变量变量。
set hivevar:queryPortion='and col1=value1 and col2=value2';
之后,只需在查询中对其进行检索
select * from table where 1=1 ${queryPortion}