Skip to content

[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

Merged
merged 4 commits into from
Apr 30, 2025

Conversation

gustavodemorais
Copy link
Contributor

@gustavodemorais gustavodemorais commented Apr 17, 2025

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:

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\"}'))

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:)

  • Check if the JSON call is for any of the VALUES param inside a JSON_OBJECT and not only the first one

Verifying this change

This change added tests and can be verified as follows:

  • Added unit tests

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (already covered by docs / JavaDocs)

@flinkbot
Copy link
Collaborator

flinkbot commented Apr 17, 2025

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

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.")
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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()

Copy link
Contributor

@snuyanzin snuyanzin left a 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

@snuyanzin snuyanzin merged commit 45588b3 into apache:master Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants