所以我有一个 Hive 外部表,其架构如下所示:
{
.
.
`x` string,
`y` ARRAY<struct<age:string,cId:string,dmt:string>>,
`z` string
}
所以基本上我需要查询一列(列“y”),它是嵌套 json 数组, 我可以从配置单元看到“y”列的数据,但该列中的数据对 presto 来说似乎是不可见的,即使 presto 知道该字段的模式,如下所示:
array(row(age varchar,cid varchar,dmt varchar))
正如你所看到的,很快就知道这个字段是行数组。
备注:
1.该表是Hive外部表。
2.我使用 ODBC 驱动程序获取字段“y”的模式,但数据都是空的,但是我可以在 hive 中看到类似的内容: [{“年龄”:“12”,“cId”:“bx21hdg”,“dmt”:“120”}]
3.Presto 查询 hivemetastore 的 schema。
4.表格存储为镶木地板格式。
那么我怎样才能看到“y”字段中的数据?
请尝试以下操作。这应该适用于 Presto。
“如果数组元素是行数据类型,则结果是元素数据类型中每个行字段一列的表。结果表列数据类型与相应的数组元素行字段数据类型匹配”
select
y,age,cid,dmt
from
table
cross join UNNEST(y) AS nested_data(age,cid,dmt)
参考:https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0055064.html