【发布时间】:2019-12-31 23:51:24
【问题描述】:
我们正在尝试在 Athena 中创建一个 Unnest 视图,它等效于其中包含数组字段的 JSON 数据的 Hive 横向视图,然后如果 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 |
+----------------------+----------------------+--+
但是当我们尝试使用 CROSS JOIN UNNEST 在 Athena 中创建视图时,输出如下:
可乐可乐
1 a
1 b
1 c
如果 JSON 数据没有我们在其上创建 UNNEST 的字段的值,则该行将从输出中删除,而 hive 也会为该行提供相应缺失值的 NULL 值。
/hive 中使用的 DDL/
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;
/用于雅典娜的 DDL/
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);
【问题讨论】:
标签: amazon-web-services hive presto amazon-athena