我正在使用Presto(0.163)查询数据,并尝试从json提取字段。
我有一个像下面给出的json,它出现在'style_attributes'列中:
"attributes": {
"Brand Fit Name": "Regular Fit",
"Fabric": "Cotton",
"Fit": "Regular",
"Neck or Collar": "Round Neck",
"Occasion": "Casual",
"Pattern": "Striped",
"Sleeve Length": "Short Sleeves",
"Tshirt Type": "T-shirt"
}
Run Code Online (Sandbox Code Playgroud)
我无法提取“短袖”字段。以下是我正在使用的查询:
从表中选择JSON_EXTRACT(style_attributes,'$。attributes.Sleeve Length')作为长度;
查询失败,并显示以下错误-无效的JSON路径:“ $。attributes.Sleeve Length”
对于没有''(空格)的字段,查询运行良好。
我试图在Presto文档中找到分辨率,但是没有成功。
presto:default> select json_extract_scalar('{"attributes":{"Sleeve Length": "Short Sleeves"}}','$.attributes["Sleeve Length"]');
_col0
---------------
Short Sleeves
Run Code Online (Sandbox Code Playgroud)
要么
presto:default> select json_extract_scalar('{"attributes":{"Sleeve Length": "Short Sleeves"}}','$["attributes"]["Sleeve Length"]');
_col0
---------------
Short Sleeves
Run Code Online (Sandbox Code Playgroud)
JSON功能变更
:func:
json_extract和:func:json_extract_scalar函数现在支持方括号语法:Run Code Online (Sandbox Code Playgroud)SELECT json_extract(json, '$.store[book]'); SELECT json_extract(json,'$.store["book name"]');作为此更改的一部分,在非括号路径段中允许的字符集已限制为字母数字,下划线和冒号。此外,冒号不能用在未引号括起来的路径段中。使用带括号的新括号语法来匹配包含特殊字符的元素。