如何加载在 HIVE 中压缩的 json snappy [英] How to load json snappy compressed in HIVE

查看:96
本文介绍了如何加载在 HIVE 中压缩的 json snappy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 HDFS 中有一堆 json snappy 压缩文件.它们是 HADOOP snappy 压缩的(不是 python,参见其他 SO 问题)并且有嵌套结构.

I have a bunch of json snappy compressed files in HDFS. They are HADOOP snappy compressed (not python, cf other SO questions) and have nested structures.

找不到加载它们的方法进入 HIVE(使用 json_tuple)?

Could not find a method to load them into into HIVE (using json_tuple) ?

我可以获得一些有关如何加载它们的资源/提示

Can I get some ressources/hints on how to load them

以前的参考文献(没有有效答案)

Previous references (does not have valid answers)

pyspark 如何加载压缩的 snappy 文件

Hive:解析 JSON

推荐答案

  1. 将所有文件放在 HDFS 文件夹中,并在其上创建外部表.如果文件的名称类似于 .snappy Hive 将自动识别它们.您可以指定用于写表的 SNAPPY 输出格式:


set hive.exec.compress.output=true;
set mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;
set mapreduce.map.output.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;
set mapreduce.output.fileoutputformat.compress.type=BLOCK;
 


CREATE EXTERNAL TABLE mydirectory_tbl(
  id   string,
  name string
)
ROW FORMAT SERDE
  'org.openx.data.jsonserde.JsonSerDe'
LOCATION '/mydir' --this is HDFS/S3 location
;

  1. JSONSerDe 可以解析所有复杂的结构,比使用 json_tuple 容易多了.json 中的简单属性按原样映射到列.方括号中的所有 [] 是数组<>,{} 中的所有是结构<>或映射<>,可以嵌套复杂类型.仔细阅读自述文件:https://github.com/rcongiu/Hive-JSON-Serde.有一节是关于嵌套结构的,还有很多 CREATE TABLE 的例子.

  1. JSONSerDe can parse all complex structures, it is much easier than using json_tuple. Simple attributes in json are mapped to columns as is All in the square brackets [] is an array<>, in {} is a struct<> or map<>, complex types can be nested. Carefully read Readme: https://github.com/rcongiu/Hive-JSON-Serde. There is a section about nested structures and many examples of CREATE TABLE.

如果您仍然想使用 json_tuple,则创建具有单个 STRING 列的表,然后使用 json_tuple 进行解析.但这要困难得多.

If you still want to use json_tuple, then create table with single STRING column then parse using json_tuple. But it is much more difficult.

所有 JSON 记录都应该在单行中(JSON 对象内没有换行符,以及 ).这里也提到了同样的内容 https://github.com/rcongiu/Hive-JSON-Serde

All JSON records should be in single line (no newlines inside JSON objects, as well as ) . The same is mentioned here https://github.com/rcongiu/Hive-JSON-Serde

这篇关于如何加载在 HIVE 中压缩的 json snappy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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