Merge pull request #31003 from kssenii/sql-json-fix

Allow spaces in JSONPath.
This commit is contained in:
Anton Popov 2021-11-03 00:59:54 +03:00 committed by GitHub
commit 2a617e6a5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 7 deletions

View File

@ -17,22 +17,17 @@ namespace DB
bool ParserJSONPathMemberAccess::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
if (pos->type != TokenType::Dot)
{
return false;
}
++pos;
if (pos->type != TokenType::BareWord)
{
if (pos->type != TokenType::BareWord && pos->type !=TokenType::QuotedIdentifier)
return false;
}
ParserIdentifier name_p;
ASTPtr member_name;
if (!name_p.parse(pos, member_name, expected))
{
return false;
}
auto member_access = std::make_shared<ASTJSONPathMemberAccess>();
node = member_access;

View File

@ -9,6 +9,7 @@ null
"bar"
--JSON_QUERY--
[{"hello":1}]
[1]

View File

@ -11,6 +11,7 @@ SELECT JSON_VALUE('{"hello":["world","world2"]}', '$.hello');
SELECT JSON_VALUE('{"hello":{"world":"!"}}', '$.hello');
SELECT JSON_VALUE('{hello:world}', '$.hello'); -- invalid json => default value (empty string)
SELECT JSON_VALUE('', '$.hello');
SELECT JSON_VALUE('{"foo foo":"bar"}', '$."foo foo"');
SELECT '--JSON_QUERY--';
SELECT JSON_QUERY('{"hello":1}', '$');