Skip to content

fix(clickhouse): VariantSubcolumn inserts strings without type inference - #33

Merged
fm4v merged 1 commit into
ClickHouse:mainfrom
groeneai:fix-clickhouse-variantsubcolumn-string-inference
Nov 25, 2026
Merged

fm4v merged 1 commit into
ClickHouse:mainfrom
groeneai:fix-clickhouse-variantsubcolumn-string-inference

Conversation

@groeneai

Copy link
Copy Markdown

The 2026-11-25 master nightly (SQLancer (arm_release), reproducer) reported:

variant/json subcolumn roundtrip mismatch (Variant.String subcolumn) at row 32: Java expects null but read NULL.
Q: SELECT toString(variantElement(v, 'String')) FROM ...var_12580_t ORDER BY k

Row 32 was inserted as CAST('null' AS String) into v Variant(Int64, String), and asciiWord happened to generate the word null. ClickHouse converts the VALUES result to the column type with CAST, and a String to Variant CAST parses the text when cast_string_to_variant_use_inference = 1 (the default, documented). The text null parses to NULL, so the row is stored as NULL (variantType = None) and every subcolumn read returns NULL correctly. The server is right and the oracle's model is wrong:

INSERT ... VALUES (2, CAST('null' AS String))                                                 -- variantType None
INSERT ... SETTINGS cast_string_to_variant_use_inference = 0 VALUES (2, CAST('null' AS String)) -- variantType String

Now the oracle's Variant INSERT sets cast_string_to_variant_use_inference = 0, so every generated word stays a String, as the model assumes. The subcolumn reads under test are unchanged; this INSERT no longer exercises String to Variant inference, which the oracle never asserted on.

Checked: mvn verify -DskipTests=true -Djacoco.skip=true passes. --oracle VariantSubcolumn against master 1c87825f446d (debug build, .claude/clickhouse-config/ overrides), before and after on one server:

run before with this PR
biased (asciiWord returns null 1 in 5, local patch), 4 threads, 3 min 1,197 findings 0 findings, 20,804 INSERTs
unbiased, 10 threads, 10 min 3 findings (this signature), 145,038 INSERTs 0 findings, 137,880 INSERTs

Related: ClickHouse/ClickHouse#128538

🤖 Generated with Claude Code

The oracle inserts each String row as CAST('<word>' AS String) into a
Variant(Int64, String) column and expects it to stay a String. The VALUES
result is converted to the column type with CAST, and with
cast_string_to_variant_use_inference = 1 (the default since 25.4) a String
is parsed into the Variant, so the word `null` is stored as NULL
(variantType None). Every subcolumn read then correctly returns NULL and the
oracle reports "Java expects null but read NULL".

Turn the inference off for this INSERT only, so every word lands in the
String variant as the model assumes. The subcolumn reads under test are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fm4v
fm4v merged commit be7d21f into ClickHouse:main Nov 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants