Skip to content

[FLINK-40852][table] Return NULL from PARSE_JSON and TRY_PARSE_JSON for NULL allowDuplicateKeys - #29343

Open
manner wants to merge 3 commits into
apache:masterfrom
manner:FLINK-40852
Open

manner wants to merge 3 commits into
apache:masterfrom
manner:FLINK-40852

Conversation

@manner

@manner manner commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

PARSE_JSON and TRY_PARSE_JSON accept any BOOLEAN expression as the second argument (allowDuplicateKeys), not only literals. The runtime functions declared it as a primitive boolean, so a NULL value failed with a NullPointerException during unboxing:

SELECT PARSE_JSON('{}', CAST(NULL AS BOOLEAN));
-- java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because "null" is null

The same happens for a nullable BOOLEAN column that is NULL for a row. With this change both functions return NULL in that case. The output type strategies (nullableIfArgs / forceNullable) already allow a NULL result.

JIRA: https://issues.apache.org/jira/browse/FLINK-40852

Brief change log

  • ParseJsonFunction and TryParseJsonFunction take @Nullable Boolean allowDuplicateKeys and return NULL if it is NULL.

Verifying this change

This change added tests and can be verified as follows:

  • Added SQL cases to JsonFunctionsITCase for PARSE_JSON and TRY_PARSE_JSON with a NULL BOOLEAN column as allowDuplicateKeys, expecting NULL. Both failed with the NPE before the fix.

There are no Table API cases for this because parseJson(boolean) / tryParseJson(boolean) only accept a literal.

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? not applicable

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Opus 5.5

🤖 Generated with Claude Code

@flinkbot

flinkbot commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

CI report:

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

@raminqaf raminqaf left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update the docs sql_functions.yml for these methods too? Also update the pyDocs and JavaDocs for the TableAPI

@github-actions github-actions Bot added the community-reviewed PR has been reviewed by the community. label Sep 30, 2026
…JSON and TRY_PARSE_JSON

A NULL allowDuplicateKeys now behaves like the default false instead of
returning NULL. The docs mention this, and the TRY_PARSE_JSON docs now say
that duplicate keys return NULL instead of throwing an error.

Generated-by: Claude Opus 5.5

[FLINK-40852][table] Treat NULL allowDuplicateKeys as false in PARSE_JSON and TRY_PARSE_JSON

A NULL allowDuplicateKeys now behaves like the default false instead of
returning NULL. The docs mention this, and the TRY_PARSE_JSON docs now say
that duplicate keys return NULL instead of throwing an error.

Generated-by: Claude Opus 5.5
manner added 2 commits October 2, 2026 15:19
FLINK-40854 changed the message to "Failed to parse JSON string".

Generated-by: Claude Opus 5.5
…ity of PARSE_JSON

A NULL allowDuplicateKeys is treated as false and can't make the result
NULL, so only the JSON string decides whether the result is nullable.

Generated-by: Claude Opus 5.5

@raminqaf raminqaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @manner! LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-reviewed PR has been reviewed by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants