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

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

问题描述

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

我已经将JSON文件上传到S3并启动了一个EMR实例,但我不知道要在Hive控制台中键入要获取JSON的内容文件是一个Hive表?



有没有人有一些示例命令让我开始,我找不到任何有用的Google ...

解决方案

您需要使用JSON serde才能将您的JSON映射到表中的列。





不幸的是,JSON serde提供的并不能很好地处理嵌套的JSON,所以你可能会



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



<
dt字符串
创建外部表格展示次数(
requestBeginTime字符串,requestEndTime字符串,主机名字符串

分隔(
dt字符串

行格式
serde'com.amazon.elasticmapreduce.JsonSerde'
with serdeproperties(
'paths'='requestBeginTime,requestEndTime,hostname'

location's3://my.bucket/';


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

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?

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

解决方案

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

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天全站免登陆