Skip to content

Read using IcebergLocal returns Nulls instead of actual rows #1545

Closed

Description

@alsugiliazova

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

  1. added
    bug
    on Mar 18, 2026
  2. self-assigned this
    on May 7, 2026
  3. il9ue commented on May 7, 2026

    @il9ue

    Status update

    The bug is wider than icebergLocal. The same code path (the allow_experimental_iceberg_read_optimization block in StorageObjectStorageSource::createReader) is hit by icebergS3,icebergAzure, icebergHDFS, and all *Cluster variants. Anyone using a non-Spark Iceberg writer on any of those is silently returning NULLs.

    Root cause

    file_meta_info IS populated on the local path — IcebergIterator always calls setFileMetaInfo() before yielding each object. The issue is what the populated DataFileMetaInfo contains: when the Iceberg manifest's per-file column statistics are absent,columns_info is an empty map, and the optimization misreads "no stats were written" as "all columns are absent from this file."

    Step by step:

    1. ManifestFile.cpp (25.8/26.1) / AvroForIcebergDeserializer.cpp (26.3) populates columns_infos from 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 returns false if the writer didn't emit them.

    2. 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_infos stays empty → DataFileMetaInfo::columns_info stays empty.

    3. In the optimization block, file_meta_data.has_value() is true (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) returns false (empty map), so the column is added to constant_columns_with_values with Field() (NULL).

    4. All nullable columns end up in constant_columns.requested_columns_copy.eraseNames(constant_columns) clears it.
      need_only_count = true.

    5. The Parquet reader runs with needOnlyCount(), returns row count only. Then generate() injects every column as createColumnConst(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.py uses 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_info case.

    Branch state

    Branch Bug present Notes
    antalya-25.8 Yes Also missing the prewhere fix 037825f31f5 — a WHERE clause on a nullable column against stats-less data hits both bugs simultaneously
    antalya-26.1 Yes Has prewhere fix
    antalya-26.3 Yes Has prewhere fix and file_schema_id plumbed into DataFileMetaInfo

    Fix 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 on DataFileMetaInfo, populated from any column ID appearing in value_counts / column_sizes / null_value_counts during 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 on DataFileMetaInfo means the cluster serialization (toJson() / JSON-ptr constructor) needs a small update.

    Plan

    PR against antalya-26.1 first, 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.

  4. added a commit that references this issue on Jun 1, 2026
    5ec03a9
  5. added a commit that references this issue on Jun 30, 2026
    1eccfc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

antalyabug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions