选择配置单元结构的所有列

lvmkulzt  于 2021-06-26  发布在  Hive
关注(0)|答案(3)|浏览(461)

我需要从配置单元结构的所有列中选择*。
配置单元创建表脚本如下
创建表脚本
selectfrom表格将每个结构显示为列selectfrom表格
我的要求是在配置单元中将结构集合的所有字段显示为列。
用户不必单独编写列名。有人有自定义项来做这个吗?

rggaifut

rggaifut1#

令人惊叹的!谢谢你,我也在找。实际上,似乎可以重用相同的列名。

  1. select s1.*
  2. from t
  3. lateral view inline (array(s1)) s1
  4. ;
  5. +-------+--------------+----------+
  6. | s1.id | s1.birthday | s1.fname |
  7. +-------+--------------+----------+
  8. | 333 | 10/13/1941 | Paul |
  9. | 777 | 11/5/1941 | Art |
  10. +-------+--------------+----------+
gdx19jrr

gdx19jrr2#

您可以使用表顶视图,也可以根据所需的模式将数据转储到其他一些表中。视图的语法:-

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

enxuqcxy3#

演示

  1. create table t
  2. (
  3. i int
  4. ,s1 struct<id:int,birthday:date,fname:string>
  5. ,s2 struct<id:int,lname:string>
  6. )
  7. ;
  8. insert into t
  9. select 1
  10. ,named_struct('id',333,'birthday',date '1941-10-13','fname','Paul')
  11. ,named_struct('id',444,'lname','Simon')
  12. ;
  13. insert into t
  14. select 2
  15. ,named_struct('id',777,'birthday',date '1941-11-05','fname','Art')
  16. ,named_struct('id',888,'lname','Garfunkel')
  17. ;
  1. select * from t
  2. ;
  1. +-----+---------------------------------------------------+--------------------------------+
  2. | t.i | t.s1 | t.s2 |
  3. +-----+---------------------------------------------------+--------------------------------+
  4. | 1 | {"id":333,"birthday":"1941-10-13","fname":"Paul"} | {"id":444,"lname":"Simon"} |
  5. | 2 | {"id":777,"birthday":"1941-11-05","fname":"Art"} | {"id":888,"lname":"Garfunkel"} |
  6. +-----+---------------------------------------------------+--------------------------------+
  1. select i
  2. ,i1.*
  3. ,i2.*
  4. from t
  5. lateral view inline (array(s1)) i1
  6. lateral view inline (array(s2)) i2
  7. ;
  1. +---+-------+-------------+----------+-------+-----------+
  2. | i | i1.id | i1.birthday | i1.fname | i2.id | i2.lname |
  3. +---+-------+-------------+----------+-------+-----------+
  4. | 1 | 333 | 1941-10-13 | Paul | 444 | Simon |
  5. | 2 | 777 | 1941-11-05 | Art | 888 | Garfunkel |
  6. +---+-------+-------------+----------+-------+-----------+

数组
内联

展开查看全部

相关问题