-
Notifications
You must be signed in to change notification settings - Fork 2.3k
evalengine: make JSON_EXTRACT work with non-static arguments
#19035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d44393b
Make `JSON_EXTRACT` work with non-static arguments.
arthurschreiber d16406f
Split up test cases into one per function.
arthurschreiber 4153731
Make compiled `JSON_EXTRACT` calls handle first argument being `NULL`
arthurschreiber 52fbaf5
Add current JSON path errors to list of known differences.
arthurschreiber d32b8c7
Small tweak.
arthurschreiber 5c4dabe
Fix handling of static values from functions.
arthurschreiber 89dcdbc
Fix typo.
arthurschreiber 3f12ed4
Update comment.
arthurschreiber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,9 @@ import ( | |
|
|
||
| var Cases = []TestCase{ | ||
| {Run: JSONExtract, Schema: JSONExtract_Schema}, | ||
| {Run: JSONPathOperations}, | ||
| {Run: FnJSONKeys}, | ||
| {Run: FnJSONExtract}, | ||
| {Run: FnJSONContainsPath}, | ||
| {Run: JSONArray}, | ||
| {Run: JSONObject}, | ||
| {Run: CharsetConversionOperators}, | ||
|
|
@@ -176,18 +178,67 @@ var Cases = []TestCase{ | |
| {Run: RegexpReplace}, | ||
| } | ||
|
|
||
| func JSONPathOperations(yield Query) { | ||
| func FnJSONKeys(yield Query) { | ||
| for _, obj := range inputJSONObjects { | ||
| yield(fmt.Sprintf("JSON_KEYS('%s')", obj), nil, false) | ||
|
|
||
| for _, path1 := range inputJSONPaths { | ||
| yield(fmt.Sprintf("JSON_KEYS('%s', '%s')", obj, path1), nil, false) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func FnJSONExtract(yield Query) { | ||
| for _, obj := range inputJSONObjects { | ||
| for _, path1 := range inputJSONPaths { | ||
| yield(fmt.Sprintf("JSON_EXTRACT('%s', '%s')", obj, path1), nil, false) | ||
|
|
||
| for _, path2 := range inputJSONPaths { | ||
| yield(fmt.Sprintf("JSON_EXTRACT('%s', '%s', '%s')", obj, path1, path2), nil, false) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| yield(`JSON_EXTRACT('{"a": 1}', '$.a')`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', '$.*')`, nil, false) | ||
| yield(`JSON_EXTRACT('[1, 2, 3]', '$[0 to 2]')`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1, "b": 2}', '$.a', '$.b')`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', '$.a', '$.z')`, nil, false) | ||
|
|
||
| yield(`JSON_EXTRACT(CONCAT('{', '"a"', ':', ' ', '1', '}'), '$.a')`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', CONCAT('$', '.', 'a'))`, nil, false) | ||
|
|
||
| yield(`JSON_EXTRACT(NULL, '$.a')`, nil, false) | ||
| yield(`JSON_EXTRACT(NULL, NULL)`, nil, false) | ||
|
|
||
| yield(`JSON_EXTRACT('{"a": 1}', NULL)`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', '$.a', NULL)`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', NULL, '$.a')`, nil, false) | ||
|
|
||
| yield(`JSON_EXTRACT('{"a": 1}', '$.b')`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', '$.b', '$.c')`, nil, false) | ||
| yield(`JSON_EXTRACT('[1,2,3]', '$[10]')`, nil, false) | ||
|
|
||
| yield(`JSON_EXTRACT('{invalid}', '$.a')`, nil, false) | ||
| yield(`JSON_EXTRACT('not json', '$.a')`, nil, false) | ||
| yield(`JSON_EXTRACT('', '$.a')`, nil, false) | ||
| yield(`JSON_EXTRACT('{invalid}', NULL)`, nil, false) | ||
|
|
||
| yield(`JSON_EXTRACT('{"a": 1}', '$.b[ 1 ].')`, nil, false) | ||
|
|
||
| yield(`JSON_EXTRACT(NULL, 'invalid-path')`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', NULL, 'invalid-path')`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', 'invalid-path', NULL)`, nil, false) | ||
| yield(`JSON_EXTRACT('{"a": 1}', '$.a', 'invalid')`, nil, false) | ||
|
Comment on lines
+202
to
+232
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these could be handled by adding them to |
||
| } | ||
|
|
||
| func FnJSONContainsPath(yield Query) { | ||
| for _, obj := range inputJSONObjects { | ||
| for _, path1 := range inputJSONPaths { | ||
| yield(fmt.Sprintf("JSON_CONTAINS_PATH('%s', 'one', '%s')", obj, path1), nil, false) | ||
| yield(fmt.Sprintf("JSON_CONTAINS_PATH('%s', 'all', '%s')", obj, path1), nil, false) | ||
| yield(fmt.Sprintf("JSON_KEYS('%s', '%s')", obj, path1), nil, false) | ||
|
|
||
| for _, path2 := range inputJSONPaths { | ||
| yield(fmt.Sprintf("JSON_EXTRACT('%s', '%s', '%s')", obj, path1, path2), nil, false) | ||
| yield(fmt.Sprintf("JSON_CONTAINS_PATH('%s', 'one', '%s', '%s')", obj, path1, path2), nil, false) | ||
| yield(fmt.Sprintf("JSON_CONTAINS_PATH('%s', 'all', '%s', '%s')", obj, path1, path2), nil, false) | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's currently some differences in the error messages generated by the evalengine vs what MySQL generates when JSON Path parsing runs into issues.
For now, I'd like to ignore these differences - but I do believe we should be able to change our implementation in the future to mimic MySQL more closely.