根据JSON数据创建配置单元表 [英] Create hive table from JSON data
问题描述
我有一个包含Json数据的文件,其格式如下:
I have a file with Json data which takes the below form:
例如:
{
"Name": "xxxx",
"Address": [{
"Street": "aa",
"City": "bbb"
}, {
"Street": "ccc",
"City": "ddd",
"Country": "eee"
}]
}
以上Json是有效的Json.我想使用JsonSerde在上述形式的数据之上创建一个配置单元表.
The above Json is a valid Json. I want to create a hive table on top of data of above form using JsonSerde.
推荐答案
使用已定义的所有可能字段创建表.如果json中不存在该字段,则select将返回NULL:
Create table with all possible fields defined. If field is not present in json, select will return NULL:
CREATE EXTERNAL TABLE your_table (
Name string,
Address array<struct<Street:string,City:string,Country:string>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
如果JSON文件中的名称与Hive保留字冲突,则添加映射并在表定义中重命名名称:
if you have names in JSON file which conflict with Hive reserved words then add mapping and rename names in table definition:
WITH SERDEPROPERTIES ('mapping.renamed_column'='original_column')
并重命名表列.
将文件放在表格位置.
另请参见带有一些示例的文档: https://github.com/rcongiu/Hive -JSON-Serde
See also docs with some examples here: https://github.com/rcongiu/Hive-JSON-Serde
这篇关于根据JSON数据创建配置单元表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!