2013-03-07 27 views
0

我試圖解析一些存儲在Hive表中的數據。在配置單元中使用Xpath

比方說。

Hive> SELECT * FROM fulldatatable LIMIT 1; 

SELECT xpath('xml data from the previous command') SELECT src LIMIT 1; 

我的問題是如何加載第一個在xpath查詢?

感謝,

回答

2

您可以創建從第一選擇一個view,然後查詢這個與XPath的UDF。
E.g:

Initial tables: 
hive> describe table1; 
id int 
f1 string 
f2 string 
f3 string 
f4 string 

hive> select * from table1; 
1 <a> <b>1</b> <b>1</b> </a> 
2 <a> <b>1</b> <b>2</b> </a> 
3 <a> <b>1</b> <b>3</b> </a> 

Another table: 

hive> describe ranks; 
id int 
text string  

hive> select * from ranks; 
1 good 
2 bad 
3 worst 

Create a view: 
hive> create view xmlout(id, line) as select id, concat(f1,f2,f3,f4) from table1; 

Then: 
hive> select xpath_short(x.line, 'sum(a/b)'), r.text from xmlout x 
     join ranks r on (x.id = r.id); 
2 good 
3 bad 
4 worst