[FLINK-40463][table] Widen JSON_VALUE and JSON_QUERY RETURNING type support - #29063
Open
cjohnson-confluent wants to merge 1 commit into
Open
[FLINK-40463][table] Widen JSON_VALUE and JSON_QUERY RETURNING type support#29063cjohnson-confluent wants to merge 1 commit into
cjohnson-confluent wants to merge 1 commit into
Conversation
Collaborator
Contributor
|
thank you for the contribution also the doc about this is in https://github.com/apache/flink/pull/27776/changes#r2979585031 can you please switched it from |
airlock-confluentinc
Bot
force-pushed
the
json-returning-types-v2
branch
from
September 1, 2026 19:48
6127761 to
d9c96ee
Compare
…upport Generated-by: Claude <noreply@anthropic.com>
airlock-confluentinc
Bot
force-pushed
the
json-returning-types-v2
branch
from
September 1, 2026 19:50
d9c96ee to
dd9d07b
Compare
Contributor
Author
Done. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the purpose of the change
JSON_VALUEandJSON_QUERYboth accept aRETURNINGclause, but only a narrow set of types is supported. This PR widens both:JSON_VALUE: adds TINYINT, SMALLINT, BIGINT, FLOAT, and DECIMAL. Fixes the existing INTEGER and DOUBLE casts, which fail at runtime on certain JSON values (INTEGER throws on large numbers because Jayway returns Long instead of Integer; DOUBLE throws on integers because Jayway returns Integer instead of BigDecimal). All numeric casts now go through range-checked conversions that route to ON ERROR behavior on overflow. FLOAT and DOUBLE reject infinity/NaN as overflow. This matches MySQL, Oracle, and PostgreSQL, which all treat numeric overflow as a conversion error handled by ON ERROR.JSON_QUERY: adds ARRAY with numeric and boolean element types (INT, TINYINT, SMALLINT, BIGINT, FLOAT, DOUBLE, DECIMAL, BOOLEAN). Previously only ARRAY<VARCHAR> was accepted. Array element conversions use the same range-checked methods.String coercion: JSON string values (e.g.
"42") are parsed as numbers when the RETURNING clause requests a numeric type, matching MySQL and PostgreSQL semantics. Boolean string coercion follows PostgreSQL's bool input function (true/t/yes/1,false/f/no/0, case-insensitive). Non-parseable strings route to ON ERROR.Architectural approach
Type conversion and error handling live in testable Java methods in
SqlJsonUtils(convertJsonScalar,convertJsonArray) rather than in Scala codegen string templates. The codegen files emit a single method call each instead of inline type-dispatch + try/catch + error-fallback blocks. This eliminates a class of string-template bugs where generated variable names can be misreferenced.A custom
JsonConversionExceptionreplacesClassCastExceptionas the internal control-flow mechanism, preventing unrelated ClassCastExceptions (from actual codegen bugs) from being silently swallowed by ON ERROR handling.A shared
isSupportedJsonReturningType()method serves as the single source of truth for accepted types, preventing validation and codegen type lists from diverging.Also fixes:
123456789.99 RETURNING DECIMAL(5,2)) silently returning null instead of triggering ON ERRORCompileExceptionJsonQueryCallGenwhere the unsupported-type error message said "JSON_VALUE" instead of "JSON_QUERY"Brief change log
convertJsonScalarandconvertJsonArraymethods toSqlJsonUtilswith full type conversion, string coercion, and ON ERROR handlingtoCheckedInt,toCheckedFloat,toCheckedDouble,parseStringAsBoolean, etc.) toSqlJsonUtilsJsonConversionException(package-private) for conversion control flowisSupportedJsonReturningTypeas a shared type allowlistJsonValueCallGencodegen to a singleconvertJsonScalarcall for non-VARCHAR typesJsonQueryCallGencodegen to a singleconvertJsonArraycall for typed arraysRAW_ARRAYvariant toJsonQueryReturnTypefor raw Jayway object arraysSqlJsonQueryFunctionWrapperto use the shared type allowlistSqlJsonUtilsConversionTest) for all conversion methods: 60 tests covering overflow, string coercion, error behaviors, boundary valuesVerifying this change
This change added tests and can be verified as follows:
Unit tests (SqlJsonUtilsConversionTest, 60 tests):
Integration tests (JsonFunctionsITCase, 933 tests):
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code