你如何用 JSON 数据制作一个 HIVE 表? [英] How do you make a HIVE table out of JSON data?

查看:46
本文介绍了你如何用 JSON 数据制作一个 HIVE 表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一些 JSON 数据(嵌套)中创建一个 Hive 表并对其运行查询?这甚至可能吗?

I want to create a Hive table out of some JSON data (nested) and run queries on it? Is this even possible?

我已经将 JSON 文件上传到 S3 并启动了一个 EMR 实例,但我不知道在 hive 控制台中输入什么才能使 JSON 文件成为 Hive 表?

I've gotten as far as uploading the JSON file to S3 and launching an EMR instance but I don't know what to type in the hive console to get the JSON file to be a Hive table?

有没有人有一些示例命令可以帮助我入门,我在 Google 上找不到任何有用的东西...

Does anyone have some example command to get me started, I can't find anything useful with Google ...

推荐答案

您需要使用 JSON serde 以便 Hive 将您的 JSON 映射到表中的列.

You'll need to use a JSON serde in order for Hive to map your JSON to the columns in your table.

一个很好的例子,向您展示这里的情况:

A really good example showing you how is here:

http://aws.amazon.com/articles/2855

不幸的是,提供的 JSON serde 不能很好地处理嵌套的 JSON,因此您可能需要展平 JSON 才能使用它.

Unfortunately the JSON serde supplied doesn't handle nested JSON very well so you might need to flatten your JSON in order to use it.

以下是文章中正确语法的示例:

Here's an example of the correct syntax from the article:

create external table impressions (
    requestBeginTime string, requestEndTime string, hostname string
  )
  partitioned by (
    dt string
  )
  row format 
    serde 'com.amazon.elasticmapreduce.JsonSerde'
    with serdeproperties ( 
      'paths'='requestBeginTime, requestEndTime, hostname'
    )
  location 's3://my.bucket/' ;

这篇关于你如何用 JSON 数据制作一个 HIVE 表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆