我需要从配置单元结构的所有列中选择*。配置单元创建表脚本如下创建表脚本selectfrom表格将每个结构显示为列selectfrom表格我的要求是在配置单元中将结构集合的所有字段显示为列。用户不必单独编写列名。有人有自定义项来做这个吗?
rggaifut1#
令人惊叹的!谢谢你,我也在找。实际上,似乎可以重用相同的列名。
select s1.*from tlateral view inline (array(s1)) s1;+-------+--------------+----------+| s1.id | s1.birthday | s1.fname |+-------+--------------+----------+| 333 | 10/13/1941 | Paul || 777 | 11/5/1941 | Art |+-------+--------------+----------+
select s1.*
from t
lateral view inline (array(s1)) s1
;
+-------+--------------+----------+
| s1.id | s1.birthday | s1.fname |
| 333 | 10/13/1941 | Paul |
| 777 | 11/5/1941 | Art |
gdx19jrr2#
您可以使用表顶视图,也可以根据所需的模式将数据转储到其他一些表中。视图的语法:-
create view foodmart.customerfs_view as select rcrm.customer_id ..... from foodmart.customerfs_view
create view foodmart.customerfs_view as select rcrm.customer_id .....
from foodmart.customerfs_view
enxuqcxy3#
演示
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');
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')
select 2
,named_struct('id',777,'birthday',date '1941-11-05','fname','Art')
,named_struct('id',888,'lname','Garfunkel')
select * from t;
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"} |+-----+---------------------------------------------------+--------------------------------+
+-----+---------------------------------------------------+--------------------------------+
| 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;
select i
,i1.*
,i2.*
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 |+---+-------+-------------+----------+-------+-----------+
+---+-------+-------------+----------+-------+-----------+
| 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 |
数组内联
3条答案
按热度按时间rggaifut1#
令人惊叹的!谢谢你,我也在找。实际上,似乎可以重用相同的列名。
gdx19jrr2#
您可以使用表顶视图,也可以根据所需的模式将数据转储到其他一些表中。视图的语法:-
enxuqcxy3#
演示
数组
内联