Repository navigation
Closed
Description
Describe the bug
Introduced in docker://altinity/clickhouse-server:25.8.9.20207.altinityantalya-alpine and has been like that in all new versions.
SELECT *
FROM icebergLocal('/var/lib/clickhouse/user_files/iceberg_local_basic', 'Parquet', SETTINGS iceberg_metadata_table_uuid = 'fbb0a4ea-488e-4387-9cdc-23888ec32fae')
FORMAT TSV
Query id: 53c9aef3-fa0b-43e5-b386-eeb9f8c316a6
\N \N \N
\N \N \N
\N \N \N
3 rows in set. Elapsed: 0.004 sec.
DESCRIBE TABLE icebergLocal('/var/lib/clickhouse/user_files/iceberg_local_basic', 'Parquet', SETTINGS iceberg_metadata_table_uuid = 'fbb0a4ea-488e-4387-9cdc-23888ec32fae')
Query id: 088a7662-7801-44e3-8b1c-13b818762105
┌─name────┬─type──────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
1. │ name │ Nullable(String) │ │ │ │ │ │
2. │ double │ Nullable(Float64) │ │ │ │ │ │
3. │ integer │ Nullable(Int64) │ │ │ │ │ │
└─────────┴───────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘
3 rows in set. Elapsed: 0.001 sec.
Expected result
SELECT version()
Query id: d2049702-453b-49fd-b210-26a16e02905c
┌─version()────────────────────┐
1. │ 25.6.5.20420.altinityantalya │
└──────────────────────────────┘
1 row in set. Elapsed: 0.001 sec.
clickhouse1 :) SELECT *
FROM icebergLocal(
'/var/lib/clickhouse/user_files/iceberg_local_basic',
'Parquet',
SETTINGS iceberg_metadata_table_uuid = 'fbb0a4ea-488e-4387-9cdc-23888ec32fae'
)
ORDER BY name
FORMAT TSV
SELECT *
FROM icebergLocal('/var/lib/clickhouse/user_files/iceberg_local_basic', 'Parquet', SETTINGS iceberg_metadata_table_uuid = 'fbb0a4ea-488e-4387-9cdc-23888ec32fae')
ORDER BY name ASC
FORMAT TSV
Query id: f05099d2-f358-4718-a389-44f866c7a05d
Alice 195.23 20
Bob 123.45 30
Charlie 67.89 40
3 rows in set. Elapsed: 0.006 sec.
clickhouse1 :)
Root cause is PR #1069
When allow_experimental_iceberg_read_optimization is turned off, I can see rows again.
SET allow_experimental_iceberg_read_optimization = 0
Query id: 8e051545-d639-4097-8005-606c0ed2875b
Ok.
0 rows in set. Elapsed: 0.001 sec.
SELECT *
FROM icebergLocal('/var/lib/clickhouse/user_files/iceberg_local_basic', 'Parquet', SETTINGS iceberg_metadata_table_uuid = 'fbb0a4ea-488e-4387-9cdc-23888ec32fae')
ORDER BY name ASC
FORMAT TSV
Query id: ab4c2f6b-7051-4b32-bec0-065828fd8128
Alice 195.23 20
Bob 123.45 30
Charlie 67.89 40
3 rows in set. Elapsed: 0.010 sec.
Activity
il9ue commentedon May 7, 2026
Status update
The bug is wider than
icebergLocal. The same code path (theallow_experimental_iceberg_read_optimizationblock inStorageObjectStorageSource::createReader) is hit byicebergS3,icebergAzure,icebergHDFS, and all*Clustervariants. Anyone using a non-Spark Iceberg writer on any of those is silently returning NULLs.Root cause
file_meta_infoIS populated on the local path —IcebergIteratoralways callssetFileMetaInfo()before yielding each object. The issue is what the populatedDataFileMetaInfocontains: when the Iceberg manifest's per-file column statistics are absent,columns_infois an empty map, and the optimization misreads "no stats were written" as "all columns are absent from this file."Step by step:
ManifestFile.cpp(25.8/26.1) /AvroForIcebergDeserializer.cpp(26.3) populatescolumns_infosfrom three optional Avro fields in the manifest:data_file.value_counts,data_file.column_sizes,data_file.null_value_counts. All three are["null", map]union types per the Iceberg spec — optional.hasPath()queries the file's actual embedded Avro schema and returnsfalseif the writer didn't emit them.Simple Iceberg writers (pyiceberg with default settings, format v1 writers, ClickHouse's own test fixtures) typically omit these fields entirely. All three
hasPath()calls return false →columns_infosstays empty →DataFileMetaInfo::columns_infostays empty.In the optimization block,
file_meta_data.has_value()istrue(the object IS there). Loop 1 (populate constants from hyperrectangle stats) iterates zero times. Loop 2 iterates over every requested column and, for each nullable column,columns_info.contains(column_name)returnsfalse(empty map), so the column is added toconstant_columns_with_valueswithField()(NULL).All nullable columns end up in
constant_columns.requested_columns_copy.eraseNames(constant_columns)clears it.need_only_count = true.The Parquet reader runs with
needOnlyCount(), returns row count only. Thengenerate()injects every column ascreateColumnConst(num_rows, Field())— constant NULL columns at correct row count.The optimization conflates "absent from stats" with "absent from file." The absent-column→NULL logic is correct for schema evolution (a nullable column added to the table after a file was written genuinely should return NULL for that file). But when stats are just missing entirely, the same logic produces silent data loss for every row.
Why existing tests don't catch this
test_read_constant_columns_optimization.pyuses Spark-written tables exclusively, and Spark always writes full column statistics. The bug only triggers on stats-free manifests.Why PR #1076's fixes didn't catch it
037825f31f5("Fix Iceberg read optimization replacing prewhere columns with constant NULLs", on 26.1 and 26.3, not on 25.8) fixed a related but different bug: prewhere/row-level filter result columns being treated as NULL constants. Different cause.063c885a7d2("Set file_meta_info only when filled", on 26.1 only) is an accessor refactor with a null guard against deserialized nullopt overwriting an iterator-set value. Doesn't address the empty-columns_infocase.Branch state
antalya-25.8037825f31f5— a WHERE clause on a nullable column against stats-less data hits both bugs simultaneouslyantalya-26.1antalya-26.3file_schema_idplumbed intoDataFileMetaInfoFix plan
The minimal
!columns_info.empty()guard is partial — it handles the no-stats-at-all case but not partial-stats + schema-evolved-absent-column. So I'm tracking column-ID presence as a separate set onDataFileMetaInfo, populated from any column ID appearing invalue_counts/column_sizes/null_value_countsduring manifest parsing. The optimization's second loop will check presence by ID instead of by stats-map containment. This handles both the empty-stats and partial-stats cases. New state onDataFileMetaInfomeans the cluster serialization (toJson()/ JSON-ptr constructor) needs a small update.Plan
PR against
antalya-26.1first, then forward-port to 26.3. For 25.8, the missing prewhere fix (037825f31f5) is an independent backport that should travel as its own PR — I'll handle that separately rather than bundling it with the absent-stats fix.Fix Iceberg read optimization returning NULLs for stats-less manifests
Fix Iceberg read optimization returning NULLs for stats-less manifests