我们正在雅典娜中创建一个Unnest视图,这相当于JSON数据的Hive横向视图,JSON数据中包含数组字段,如果unnest为null,则父ky将被删除。
下面是我们尝试创建视图的示例JSON。
{"root":{"colA":"1","colB":["a","b","c"]}}
{"root":{"colA":"2"}}Hive视图中上述数据的输出如下:
+----------------------+----------------------+--+
| test_lateral_v.cola | test_lateral_v.colb |
+----------------------+----------------------+--+
| 1 | a |
| 1 | b
| 1 | c |
| 2 | NULL |
+----------------------+----------------------+--+ 但是,当我们试图创建带有交叉连接的雅典娜视图时,下面是输出:
可乐可乐
1 a
1 b
1 c如果JSON数据没有我们为其创建UNNEST的字段的值,则该行将从输出中删除,而hive则为该行提供相应的缺失值的空值。
/DDLs用于蜂箱/
create external table if not exists test_lateral(
root struct<
colA: string,
colB: array<
string
>
>
)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
Stored as textfile
location "<hdfs_location>";
create view test_lateral_v
(colA,colB)
as select
root.colA,
alias
from test_lateral
lateral view outer explode (root.colB) t as alias;/DDLs用于雅典娜/
create external table if not exists test_lateral(
root struct<
colA: string,
colB: array<
string
>
>
)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
Stored as textfile
location "<s3_location>";
create view test_lateral_v
as select
root.colA,
alias as colB
from test_lateral
cross join unnest (root.colB) as t (alias);发布于 2019-08-27 21:06:05
选择* FROM (test_lateral交叉连接UNNEST)(合并(“根”.“colb”,arraynull)) t(别名)
作品
发布于 2019-10-02 19:05:52
https://stackoverflow.com/questions/57680760
复制相似问题