我正在使用 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"
}
我无法提取“短袖”字段。
以下是我正在使用的查询:
从表中选择 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
or
presto:default> select json_extract_scalar('{"attributes":{"Sleeve Length": "Short Sleeves"}}','$["attributes"]["Sleeve Length"]');
_col0
---------------
Short Sleeves
JSON 函数变更
:func:json_extract
和:功能:json_extract_scalar
现在功能
支持方括号语法:
SELECT json_extract(json, '$.store[book]');
SELECT json_extract(json,'$.store["book name"]');
作为此更改的一部分,字符集
允许在非括号路径段中被限制为
字母数字、下划线和冒号。此外,冒号不能
用于未加引号的括号路径段。使用新的括号语法
用引号来匹配包含特殊字符的元素。
https://github.com/prestodb/presto/blob/c73359fe2173e01140b7d5f102b286e81c1ae4a8/presto-docs/src/main/sphinx/release/release-0.75.rst https://github.com/prestodb/presto/blob/c73359fe2173e01140b7d5f102b286e81c1ae4a8/presto-docs/src/main/sphinx/release/release-0.75.rst
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)