Skip to content

Do not infer Nullable(Tuple) in Arrow, ArrowStream, ORC, Parquet and Avro schema inference unless the type is enabled - #109185

Merged
Avogar merged 7 commits into
ClickHouse:masterfrom
nihalzp:fix-nullable-tuple-schema-inference
Jul 6, 2026
Merged

Avogar merged 7 commits into
ClickHouse:masterfrom
nihalzp:fix-nullable-tuple-schema-inference

Conversation

@nihalzp

@nihalzp nihalzp commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

Related: #101272

Since #101272 (26.4), schema inference in the Arrow-based readers returns Nullable(Tuple(...)) for optional (nullable) struct columns. The Nullable(Tuple) type is gated by allow_experimental_nullable_tuple_type (disabled by default), and validateDataType rejects it when creating columns. As a result, under default settings DESCRIBE s3(...) succeeds while CREATE TABLE ... AS s3(...) or INSERT ... SELECT from the inferred schema fails:

Code: 44. DB::Exception: Cannot create column with type 'Nullable(Tuple(...))' because Nullable Tuple
type is not allowed. Set setting allow_experimental_nullable_tuple_type = 1 in order to allow it.

The affected readers are Arrow, ArrowStream, ORC with input_format_orc_use_fast_decoder = 0, and the legacy Arrow-based Parquet reader (used when input_format_parquet_use_native_reader_v3 = 0; removed in 26.5). The native Parquet v3 and native ORC readers were never affected.

cc: @fm4v

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix schema inference for the Arrow, ArrowStream, Avro formats and the legacy ORC and Parquet readers returning Nullable(Tuple) for nullable struct columns while the Nullable(Tuple) type is not allowed (allow_experimental_nullable_tuple_type is disabled). DESCRIBE returned a type that CREATE TABLE rejects, so creating a table or inserting data using the inferred schema failed with the error Nullable Tuple type is not allowed.

Version info

  • Merged into: 26.7.1.549 (included in 26.7 and later)
  • Backported to: 26.6.2.34, 26.5.6.27, 26.4.5.114

@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [25ba1dc]

Summary: ✅


AI Review

Summary

This PR fixes the Nullable(Tuple) schema-inference failure for Arrow-based readers and Avro, and it also updates the relevant schema-cache keys. The cache-key and explicit-type-hint fixes look correct, but the new Arrow fallback still turns NULL struct values into non-NULL tuples with the underlying child values, so it replaces a loud failure with silent wrong data.

Findings

❌ Blockers

  • [src/Processors/Formats/Impl/ArrowColumnToCHColumn.cpp:2447] When allow_experimental_nullable_tuple_type = 0, nullable Arrow STRUCT columns now skip the outer Nullable(Tuple) wrapper and fall back to the plain Tuple path, but that path never propagates the parent struct null map into the tuple elements. StructArray::field(i) only slices each child column, so rows where the whole struct is NULL keep the child values stored underneath instead of becoming null/default elements. The new 04493 reference already shows the regression: the default Arrow read returns (10, 'x') for a row whose s value in the file was NULL, and CREATE TABLE ... AS file(..., 'Arrow') will persist those wrong values.
    Suggested fix: if Nullable(Tuple) is disallowed, still read the outer nullable struct and then unwrap it by propagating the struct null map into the tuple elements before returning the plain Tuple, e.g. with the same Nested::unwrapNullableTuple pattern already used for Nested array elements.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: preserve parent struct nulls when falling back from Nullable(Tuple) to Tuple in the Arrow path instead of materializing the child buffer values for rows where the whole struct is NULL.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 2, 2026
@nihalzp
nihalzp requested a review from Avogar July 2, 2026 13:40
arrow_column->type()->id() != arrow::Type::LARGE_LIST &&
arrow_column->type()->id() != arrow::Type::FIXED_SIZE_LIST &&
arrow_column->type()->id() != arrow::Type::MAP &&
(arrow_column->type()->id() != arrow::Type::STRUCT || allow_nullable_struct) &&

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.

This fallback still loses the parent STRUCT null map. When allow_experimental_nullable_tuple_type = 0, nullable structs skip the outer Nullable(Tuple) wrapper here and fall through to the plain Tuple path, but the STRUCT reader below only re-reads struct_chunk.field(i) for each child and never merges the parent struct null bitmap into those children. For Arrow, that means a row where the whole struct is NULL keeps the child values stored underneath instead of becoming null/default elements. The new 04493 reference already shows it: the default Arrow read returns (10, 'x') for a row whose s value in the file was NULL. So CREATE TABLE ... AS file(..., 'Arrow') now succeeds by silently materializing wrong data instead of preserving the null semantics.

If we need to fall back from Nullable(Tuple) to Tuple, please still read the outer nullable struct and then propagate its null map into the tuple elements before returning it, e.g. with the same Nested::unwrapNullableTuple pattern already used for Nested array elements.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is old behavior pre-#101272.

@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.60% +0.10%
Functions 92.70% 92.70% +0.00%
Branches 77.70% 77.80% +0.10%

Changed lines: Changed C/C++ lines covered: 87/89 (97.75%) · Uncovered code

Full report · Diff report

@fm4v

fm4v commented Jul 6, 2026

Copy link
Copy Markdown
Member

@nihalzp Can be merged?

@nihalzp

nihalzp commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@fm4v After review from @Avogar, it should be good to merge.

@Avogar
Avogar added this pull request to the merge queue Jul 6, 2026
Merged via the queue into ClickHouse:master with commit 8fee341 Jul 6, 2026
175 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 6, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 6, 2026
Copilot AI added a commit that referenced this pull request Jul 6, 2026
…d Avro schema inference unless the type is enabled

Cherry-pick of #109185 to 26.5.

Without `allow_experimental_nullable_tuple_type`, schema inference for Arrow, ArrowStream, ORC, Parquet,
and Avro formats must not infer `Nullable(Tuple)` for nullable struct/record columns, because
`CREATE TABLE` rejects that type by default. Instead, the struct null map is propagated
into the tuple elements as it worked before `Nullable(Tuple)` was supported.

Also adds `schema_inference_allow_nullable_tuple_type` to the schema inference cache keys
for all row-based formats, Arrow, ArrowStream, ORC, and Avro/AvroConfluent.
clickhouse-gh Bot pushed a commit that referenced this pull request Jul 6, 2026
…rowStream, ORC, Parquet and Avro schema inference unless the type is enabled
clickhouse-gh Bot added a commit that referenced this pull request Jul 6, 2026
Backport #109185 to 26.6: Do not infer `Nullable(Tuple)` in Arrow, ArrowStream, ORC, Parquet and Avro schema inference unless the type is enabled
robot-ch-test-poll3 added a commit that referenced this pull request Jul 6, 2026
Cherry pick #109185 to 26.5: Do not infer `Nullable(Tuple)` in Arrow, ArrowStream, ORC, Parquet and Avro schema inference unless the type is enabled
robot-clickhouse added a commit that referenced this pull request Jul 6, 2026
…rowStream, ORC, Parquet and Avro schema inference unless the type is enabled
Copilot AI added a commit that referenced this pull request Jul 7, 2026
…e + PR changes

Replace all files changed by PR #109185 with 26.4-compatible versions by
applying only the PR-specific changes to the 26.4 base, instead of using
the master versions that caused merge conflicts.

Changes made:
- EscapingRuleUtils.cpp: add schema_inference_allow_nullable_tuple_type to format string
- ArrowBlockInputFormat.cpp: add schema_inference_allow_nullable_tuple_type to both Arrow/ArrowStream cache getters
- ArrowColumnToCHColumn.cpp: add allow_nullable_struct guard for STRUCT type
- AvroRowInputFormat.cpp: add allow_nullable_tuple_type parameter to avroNodeToDataTypeImpl, add cache getter
- AvroRowInputFormat.h: update avroNodeToDataType/avroNodeToDataTypeImpl signatures
- ORCBlockInputFormat.cpp: add schema_inference_allow_nullable_tuple_type, use_fast_decoder, dictionary_as_low_cardinality to ORC cache getter
- 03212/03526/03627 reference files: add schema_inference_allow_nullable_tuple_type=false to cache key strings
- Remove 04262_skip_first_lines_with_names_schema_cache.{reference,sh} (not in 26.4 base, only modified by PR not created)
@nihalzp nihalzp removed pr-synced-to-cloud The PR is synced to the cloud repo pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Jul 7, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 7, 2026
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
nihalzp added a commit that referenced this pull request Jul 8, 2026
Cherry pick #109185 to 26.4: Do not infer `Nullable(Tuple)` in Arrow, ArrowStream, ORC, Parquet and Avro schema inference unless the type is enabled
robot-clickhouse added a commit that referenced this pull request Jul 8, 2026
…rowStream, ORC, Parquet and Avro schema inference unless the type is enabled
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 8, 2026
nihalzp added a commit that referenced this pull request Jul 8, 2026
Backport #109185 to 26.5: Do not infer `Nullable(Tuple)` in Arrow, ArrowStream, ORC, Parquet and Avro schema inference unless the type is enabled
nihalzp added a commit that referenced this pull request Jul 8, 2026
Backport #109185 to 26.4: Do not infer `Nullable(Tuple)` in Arrow, ArrowStream, ORC, Parquet and Avro schema inference unless the type is enabled
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…schema-inference

Do not infer `Nullable(Tuple)` in Arrow, ArrowStream, ORC, Parquet and Avro schema inference unless the type is enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport v26.5-must-backport v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants