1.hive复合数据类型
ARRAY < data_type >
MAP < primitive_type, data_type >
STRUCT < col_name : data_type [COMMENT col_comment], …>
2.json建构于两种结构
“名称/值”对的集合(A collection of name/value pairs)。不同的语言中,它被理解为对象(object),纪录(record),结构(struct),字典(dictionary),哈希表(hash table),有键列表(keyed list),或者关联数组 (associative array)。 JSON对象封装在大括号内{ }。空对象可以表示为{ }
值的有序列表(An ordered list of values)。在大部分语言中,它被理解为数组(array)。数组封装在方括号内[ ]。空数组可以表示为 [ ]
3.json结构和hive复合数据类型对应关系
| json对象 | MAP < primitive_type, data_type >/STRUCT < col_name : data_type [COMMENT col_comment], …> |
| json数组 | ARRAY < data_type > |
注意:1.在最外层对象内的key:val,直接为表的字段
2.最内层对象最好定义为map类型,其他嵌套对象定义为struct。map比struct优点是不需要知道kv键值对的个数,struc必须要指定字段值。缺点是map的key是primitive_type(原始数据类型)
例子:
原始数据
{
"error": 0,
"status": "success",
"results": [
{
"currentCity": "青岛",
"index": [
{
"title": "穿衣",
"zs": "较冷",
"tipt": "穿衣指数",
"des": "建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。"
},
{
"title": "紫外线强度",
"zs": "中等",
"tipt": "紫外线强度指数",
"des": "属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。"
}
]
}
]
}
建表语句
create table test
(
error int,
status string,
results array<STRUCT<currentCity:string,index:array<map<string,string>>>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
STORED AS TEXTFILE;
```
5万+

被折叠的 条评论
为什么被折叠?



