Merge pull request #53470 from KevinyhZou/bug_fix_json_query_path_numberic

Fix JSON_QUERY Function parse error while path is all number
This commit is contained in:
Kruglov Pavel 2023-08-23 12:01:55 +02:00 committed by GitHub
commit 8e6b8fc2d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -58,6 +58,10 @@ bool ParserJSONPathMemberAccess::parseImpl(Pos & pos, ASTPtr & node, Expected &
member_name = std::make_shared<ASTIdentifier>(String(last_begin, pos->end));
++pos;
}
else if (!pos.isValid() && pos->type == TokenType::EndOfStream)
{
member_name = std::make_shared<ASTIdentifier>(String(last_begin, last_end));
}
else
{
return false;

View File

@ -77,6 +77,10 @@ SELECT JSON_QUERY('{"array":[[0, 1, 2, 3, 4, 5], [0, -1, -2, -3, -4, -5]]}', '$.
[0, 1, 4, 0, -1, -4]
SELECT JSON_QUERY('{"1key":1}', '$.1key');
[1]
SELECT JSON_QUERY('{"123":1}', '$.123');
[1]
SELECT JSON_QUERY('{"123":1}', '$[123]');
SELECT JSON_QUERY('{"hello":1}', '$[hello]');
[1]
SELECT JSON_QUERY('{"hello":1}', '$["hello"]');

View File

@ -43,6 +43,8 @@ SELECT JSON_QUERY( '{hello:{"world":"!"}}}', '$.hello'); -- invalid json => defa
SELECT JSON_QUERY('', '$.hello');
SELECT JSON_QUERY('{"array":[[0, 1, 2, 3, 4, 5], [0, -1, -2, -3, -4, -5]]}', '$.array[*][0 to 2, 4]');
SELECT JSON_QUERY('{"1key":1}', '$.1key');
SELECT JSON_QUERY('{"123":1}', '$.123');
SELECT JSON_QUERY('{"123":1}', '$[123]');
SELECT JSON_QUERY('{"hello":1}', '$[hello]');
SELECT JSON_QUERY('{"hello":1}', '$["hello"]');
SELECT JSON_QUERY('{"hello":1}', '$[\'hello\']');