-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fix Update json_extract to Produce Canonicalized Output #24614
base: master
Are you sure you want to change the base?
Conversation
LGTM. Maybe also add a verifier run? |
29fb500
to
d7fc7ce
Compare
} | ||
|
||
@Test | ||
public void testParseNullIfJsonInvalid() |
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.
test for the expected exception here instead of checking for null you can use assertInvalidFunction() once you change to throwing an invalid_function_argument error code.
SORTED_MAPPER.writeValue((OutputStream) dynamicSliceOutput, SORTED_MAPPER.readValue(jsonParser, Object.class)); | ||
// nextToken() returns null if the input is parsed correctly, | ||
// but will throw an exception if there are trailing characters. | ||
jsonParser.nextToken(); |
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.
catch the exception and throw a PrestoException with an invalid_function_argument error code. include the failing jsonInput in the error message. Also, when there is no exception, test that the value is null (non-null and no exception means there's another valid json object after this one) and throw a PrestoException with invalid_function_argument for that case too.
Also let's gate this change behind a configuration/session property. You can look at usages of other properties in SqlFunctionProperties for examples |
Description
Canonicalize json_extract output by replacing the copy operation with writing the JSON to output stream with sorted keys
Motivation and Context
This relates to issue #24563.
Ensuring JSON output canonicalization guarantees the accuracy of JSON comparisons and aligns the behavior with json_parse
Impact
low impact
Test Plan
Unit test is self-explanatory
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.