如何将字符串设置为hiveconf变量转换为可用作表名的一部分的对象
问题描述:
我正在寻找一种方法来从hiveconf
变量字符串中删除引号,以便我可以将其用作表名的一部分:如何将字符串设置为hiveconf变量转换为可用作表名的一部分的对象
Basicaly,我有一些像
set sub_name = "123";
select ${hiveconf:sub_name} from table_${hiveconf:sub_name};
和执行的时候,我需要它的工作,如:
select "123" from table_123;
对于这一点,我可以像运行:
set variable = "123";
set table_subname = 123;
select ${hiveconf:variable} from table_${hiveconf:table_subname};
,然后这些工作为
select "123" from table_123;
但有一些优雅的方式如何只使用一个变量,一旦为一个字符串,一旦作为表名的一部分吗?
答
hive> create table table_abc as select 'X' as x;
OK
x
hive> set sub_name=abc;
hive> select "${hiveconf:sub_name}" from table_${hiveconf:sub_name};
OK
_c0
abc
我知道我可以这样做:'设置变量= 123;'然后'选择 '{hiveconf:变量}' 从表_ $ {hiveconf:变量};',但如何走另一条路回合? – ira
这是一个不好的例子,因为'select 123'和'select'123''''' –