[FLINK-40241][table-runtime] Support VARIANT as column type in the 'raw' format - #29010
Open
raminqaf wants to merge 1 commit into
Open
[FLINK-40241][table-runtime] Support VARIANT as column type in the 'raw' format#29010raminqaf wants to merge 1 commit into
raminqaf wants to merge 1 commit into
Conversation
Collaborator
…aw' format The 'raw' format now accepts a single VARIANT column, treating the bytes as a JSON document. On read the bytes are parsed like PARSE_JSON with duplicate keys rejected; on write the value is rendered with Variant#toJson. The round trip is value-lossless but not byte-lossless: insignificant whitespace is dropped and object keys are ordered. Reads decode with 'raw.charset'. For the default UTF-8 the bytes are parsed directly through a new BinaryVariantInternalBuilder#parseJson(byte[]) overload, which lets Jackson decode straight from the byte array and avoids an intermediate String. Other charsets are decoded to a String first so 'raw.charset' stays honored and read remains symmetric with write. 'raw.endianness' does not apply to VARIANT. Combined with 'raw.line-delimiter' this reads and writes newline-delimited JSON, one row per line.
raminqaf
force-pushed
the
FLINK-40241-raw-format
branch
from
August 24, 2026 12:35
31f70e1 to
3b54633
Compare
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
The
rawformat is for reading and writing schemaless topics and files, andVARIANTis Flink's type for semi-structured data, but the two could not be combined:CREATE TABLE t (payload VARIANT) WITH ('format' = 'raw', ...)failed at plan time. Users had to declare the column asSTRINGand callPARSE_JSONin every query on read, and flatten withJSON_STRINGon write, which misrepresents the column type in catalogs and downstream consumers.This change makes the
rawformat accept a singleVARIANTcolumn, treating the bytes as a JSON document. The change is purely additive; no existing type behavior changes.Brief change log
LogicalTypeRoot.VARIANTtoRawFormatFactory's supported types.Variant, matchingPARSE_JSONdefaults (duplicate object keys rejected, malformed JSON fails the job). For the default UTF-8 the bytes are parsed directly via a new@Internal BinaryVariantInternalBuilder#parseJson(byte[])overload, letting Jackson decode straight from the byte array with no intermediateString. Other charsets are decoded to aStringwithraw.charsetfirst, so the option stays honored and read is symmetric with write.VariantwithVariant#toJson, encoded withraw.charset.Verifying this change
This change added tests and can be verified as follows:
RawFormatFactoryTest: aVARIANTcolumn is accepted and produces the expected schemas.RawFormatSerDeSchemaTest: value-lossless round trips for objects, arrays, and JSON scalars; SQLNULL; a UTF-16 round trip (exercises the decode-then-parse branch); malformed JSON, duplicate keys, and empty message all raiseDeserializationException.RawFormatLineDelimiterTest: newline-delimited JSON round trips one row per line when combined withraw.line-delimiter.Does this pull request potentially affect one of the following parts:
@Public(Evolving): no (the new builder method is@Internal)VARIANTcolumns on the raw read/write path)Documentation
Notes for reviewers
Variant#toJsondrops insignificant whitespace and orders object keys.raw.endiannessdoes not apply toVARIANT.Variant#toJson().getBytes(charset). A byte-direct emitter would avoid the intermediateString, but it needs a new flink-coreVariantAPI with a byte-level JSON escaper, so it is deferred as a follow-up. The read-side byte path was taken here becausecreateParser(byte[])already exists and is algorithmically faster, not just one fewer allocation.Variantfrom a token source) is complementary but targets callers that have already tokenized their JSON; it does not help this bytes-in path or the write side, so it is out of scope here.Was generative AI tooling used to co-author this PR?