【问题标题】:Hive - Extract data from nested JsonHive - 从嵌套的 Json 中提取数据
【发布时间】:2017-03-20 14:48:39
【问题描述】:

我有一个名为 newdata 的表

create external table newdata
(
data string
)
location 'something'

select data from string limit 1

{ "user": { "name": "default", "education": { "schoome": "abc", "college": "def" } } 

我需要将此结果显示为

|用户 |姓名 |学校|学院|

|--------|---------|----------|-----------|

【问题讨论】:

  • schoome? :-) ...
  • 提取"user"没有意义
  • 附言。这似乎是一个简单的案例。你有什么特别的问题吗?
  • dudu 谢谢,我有一个很大的分析,我用这个来避免巨大的select语句____ SELECT json_extract_scalar(item, '$.name') as name, json_extract_scalar(item, '$.education') as name FROM newdata cross join unnest(cast(json_extract(data, '$.user'))) as i(item),,,,, 无论如何谢谢。

标签: json amazon-web-services hive amazon-athena


【解决方案1】:
select  json_extract_scalar (data,'$.user.name')              as name
       ,json_extract_scalar (data,'$.user.education.school')  as school
       ,json_extract_scalar (data,'$.user.education.college') as college

from    newdata

【讨论】:

    猜你喜欢
    • 2019-10-27
    • 1970-01-01
    • 2020-06-28
    • 2022-07-12
    • 2020-11-07
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    相关资源
    最近更新 更多