2017-09-04 75 views
1

我正在尋找一種方法來從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''''' –

回答

0
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