如何将字符串设置为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; 

但有一些优雅的方式如何只使用一个变量,一旦为一个字符串,一旦作为表名的一部分吗?

+0

我知道我可以这样做:'设置变量= 123;'然后'选择 '{hiveconf:变量}' 从表_ $ {hiveconf:变量};',但如何走另一条路回合? – ira

+0

这是一个不好的例子,因为'select 123'和'select'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 
+0

是的,但我想反过来。即'set sub_name =“abc”;从table _ $ {hiveconf:sub_name}中选择$ {hiveconf:sub_name};'我将在table_部分中执行某些操作以删除引号 – ira

+0

@ira - **(1)**不会发生** 2)**它仍然比你的建议解决方案更清洁,有两个变量 –

+0

你确定没有办法吗?或者是你不知道如何做到这一点?例如,在shell脚本中,这可以完成。我想直接在hql中执行此操作,尽管 – ira