2017-03-16 73 views
1

我有一個要求,從一個配置單元結構的所有列中選擇*。選擇Hive結構的所有列

蜂巢創建表的腳本是在這裏下面

Create Table script

SELECT * FROM表顯示每個結構爲一列 select * from table

我有要求,是顯示一個結構集合中的所有領域作爲蜂巢中的一列。

用戶不必分別編寫列名。有沒有人有UDF來做到這一點?

+0

請替換文字圖片,包括一些數據樣本 –

回答

0

您可以在表格頂部使用視圖,或根據需要的架構將數據轉儲到其他表格中。 語法觀點: -

create view foodmart.customerfs_view as select rcrm.customer_id ..... 
from foodmart.customerfs_view 
1

演示

create table t 
(
    i int 
    ,s1 struct<id:int,birthday:date,fname:string> 
    ,s2 struct<id:int,lname:string> 
) 
; 

insert into t 
select 1 
     ,named_struct('id',333,'birthday',date '1941-10-13','fname','Paul') 
     ,named_struct('id',444,'lname','Simon') 
; 

insert into t 
select 2 
     ,named_struct('id',777,'birthday',date '1941-11-05','fname','Art') 
     ,named_struct('id',888,'lname','Garfunkel') 
; 

select * from t 
; 

+-----+---------------------------------------------------+--------------------------------+ 
| t.i |      t.s1      |    t.s2    | 
+-----+---------------------------------------------------+--------------------------------+ 
| 1 | {"id":333,"birthday":"1941-10-13","fname":"Paul"} | {"id":444,"lname":"Simon"}  | 
| 2 | {"id":777,"birthday":"1941-11-05","fname":"Art"} | {"id":888,"lname":"Garfunkel"} | 
+-----+---------------------------------------------------+--------------------------------+ 

select i 
     ,i1.* 
     ,i2.* 

from t 
     lateral view inline (array(s1)) i1 
     lateral view inline (array(s2)) i2 
; 

+---+-------+-------------+----------+-------+-----------+ 
| i | i1.id | i1.birthday | i1.fname | i2.id | i2.lname | 
+---+-------+-------------+----------+-------+-----------+ 
| 1 | 333 | 1941-10-13 | Paul  | 444 | Simon  | 
| 2 | 777 | 1941-11-05 | Art  | 888 | Garfunkel | 
+---+-------+-------------+----------+-------+-----------+ 

array
inline

+0

這奇妙的作品顯示蜂巢結構的所有列,BTW。非常感謝! – wardw123