【发布时间】:2019-12-23 02:10:43
【问题描述】:
我在 Zeppelin 上查询 test_tbl 表。 表数据结构如下:
%sql
desc stg.test_tbl
col_name | data_type | comment
id | string |
title | string |
tags | string |
标签列的数据 JSON 类型如下:
{"name":[{"family": null, "first": "nelson"}, {"pos_code":{"house":"tlv", "id":"A12YR"}}]}
我想查看带有列的 JSON 数据,所以我的查询是:
select *, tag.*
from stg.test_tbl as t
lateral view explode(t.tags.name) name as name
lateral view explode(name.pos_code) pos_code as pos_code
但是当我查询时,它会返回
Can't extract value from tags#3423: need struct type but got string; line 3 pos 21
set zeppelin.spark.sql.stacktrace = true to see full stacktrace
我应该在where语句中以字符串形式查询吗?
【问题讨论】:
-
数据类型是字符串,不是结构。 json数据被视为字符串,所以不能使用struct。
-
@Lamanus 你说得对,我不知道列类型是字符串,而不是数组作为 json 类型。因此,我使用 get_json_object cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 查询了 String 类型的数据
标签: apache-spark apache-zeppelin