我试着在配置单元中加载这个json数据
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}
使用ddl命令
ADD JAR /home/cloudera/Downloads/json-serde-1.3.6-SNAPSHOT-jar-with-dependencies.jar;
CREATE EXTERNAL TABLE format.json_serde (
`id` string,
`type` string,
`name` string,
`ppu` float,
batters` struct < `batter`:array < struct <`bid`:string, `btype`:string >>>,
`topping`:array < struct<`tid`:int, `ttype`:string>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe';
给我带来了错误
FAILED: ParseException line 7:11 cannot recognize input near ':' 'array' '<' in column type </b>
2条答案
按热度按时间busg9geu1#
你有打字错误
ttype
:字符串应为ttype:string battersstruct应为batters struct topping:array should 打顶阵 json serdeMap是按名称完成的。 您的结构域名称应该与实际名称匹配,例如。
id而不是
bid或者
tid` ,否则将得到这些字段的空值。已经有一个json serde whicg是hive安装的一部分。https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#languagemanualddl-行格式和序列
mzaanser2#
当我去掉顶端附近的分号时,它就起作用了。谢谢
创建外部表格式.json\u serde(
id
字符串,type
字符串,name
字符串,ppu
浮动,batters
结构<batter
:数组<struct<bid
:字符串,btype
:字符串>>>,topping
数组<结构<tid
:字符串,ttype
:字符串>>)