-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[FLINK-37695][table] Fix parsing for built-in function JSON in JSON_OBJECT for all positions #26474
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
Conversation
...-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/ExprCodeGenerator.scala
Outdated
Show resolved
Hide resolved
...-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/JsonGenerateUtils.scala
Outdated
Show resolved
Hide resolved
...-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/JsonGenerateUtils.scala
Outdated
Show resolved
Hide resolved
8396f7e
to
e30c207
Compare
...able-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java
Show resolved
Hide resolved
STRING().notNull()) | ||
.testSqlValidationError( | ||
"JSON_OBJECT(KEY JSON('{}') VALUE 'value' ABSENT ON NULL)", | ||
"The JSON() function is currently only supported inside a JSON_OBJECT() or JSON_ARRAY() function.") |
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.
The error message is confusing though. JSON()
function is indeed inside JSON_OBJECT
. We need to make it more accurate that it also needs to be in value position?
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.
The full message contains examples that should help the user understand the expected use. See:
The JSON() function is currently only supported inside a JSON_OBJECT() or JSON_ARRAY()" +
" function. Example: JSON_OBJECT('a', JSON('{"key": "value"}')) or " +
"JSON_ARRAY(JSON('{"key": "value"}')).
Do you think that's clear enough? Let me know if you have a specific suggestion
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.
The JSON() function is currently only supported inside a JSON_OBJECT() or JSON_ARRAY() as values
? Is this more accurate?
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.
The param is actually called VALUE
. What do you think:
The JSON() function is currently only supported inside JSON_ARRAY() or as the VALUE param of JSON_OBJECT()
9db8444
to
199815d
Compare
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.
Thanks @gustavodemorais for the contribution
Thanks @lihaosky for the review
What is the purpose of the change
Parsing for a JSON() function call fails if its position is not the first param of JSON_OBJECT.
SELECT JSON_OBJECT('key' VALUE JSON('{}'), 'key_2' VALUE JSON('{}'));
Outputs:
This is incorrect, we were too strict with the limitations. We're strictly allowing json to be called only as the second param in the function, when it should be allowed for every second.
Brief change log
(for example:)
JSON
call is for any of the VALUES param inside aJSON_OBJECT
and not only the first oneVerifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (no)Documentation