Skip to content

ClickHouse Parquet reader incorrectly throws ICEBERG_SPECIFICATION_VIOLATION for v3 tables #107343

Closed

Description

@snicholasbarton

Company or project name

No response

Describe what's wrong

When reading an Iceberg table with the native (V3) Parquet reader, ClickHouse throws ICEBERG_SPECIFICATION_VIOLATION if a data file physically contains the reserved, required row-lineage columns _row_id (field id 2147483540) or _last_updated_sequence_number (field id 2147483539). These are reserved, required metadata field ids defined by the Iceberg spec; the reader treats them as ordinary unknown field ids and refuses the file. The exception fires even for queries that do not select those columns.

Does it reproduce on the most recent release?

Yes

How to reproduce

Which ClickHouse version: any version with the native V3 Parquet reader + Iceberg field-id column mapping (master).

  1. Create an Iceberg v3 table (which requires row lineages to be written) using any external engine (e.g. Spark/pyiceberg).
  2. Perform some action that causes data files to materialise the row-lineage columns with non-null values, for example a table maintenance action like RewriteDataFiles via Spark. Per the spec the columns are written into the Parquet schema with their reserved field ids.
  3. Query the table from ClickHouse, e.g. SELECT count() FROM iceberg(...). It does not matter if you try to select the row lineage columns or not.

Expected behavior

The read query should succeed and not throw ICEBERG_SPECIFICATION_VIOLATION.

The Iceberg spec resolves columns by field id and requires readers to ignore file columns that are not part of the projected schema; reserved metadata ids are specifically meant to be understood by readers, not rejected.

Error message and/or stacktrace

Code: 743. DB::Exception: Parquet file has column _row_id with field_id 2147483540 that is not in datalake metadata: (in file/uri <object-storage>/<warehouse>/<namespace>/<partition>/<filename>.parquet): While executing ParquetV3BlockInputFormat: While executing ReadFromObjectStorage. (ICEBERG_SPECIFICATION_VIOLATION) (version 26.4.2.10 (official build))

Related issues and pull requests

No response

Additional context

Row lineages in the Iceberg spec

Minimally it would be great if ClickHouse could tolerate the existence of row lineage field IDs even if it doesn't yet fully support writing them.

Version info

Activity

  1. added
    potential bug
    on Jun 12, 2026
  2. clickgapai commented on Jun 12, 2026

    @clickgapai
    Contributor

    Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

    TL;DR

    ClickHouse Parquet reader incorrectly throws ICEBERG_SPECIFICATION_VIOLATION for v3 tables

    ClickGap verified: reproduced it with the script below on master; tested 4 version(s) — 2 affected, 2 clean (see Affects); bisected the regression to a single PR (#102362).

    Reproduction

    #!/bin/bash
    # Repro for issue #107343 — Iceberg native V3 Parquet reader wrongly throws
    # ICEBERG_SPECIFICATION_VIOLATION for a data file that physically carries a
    # field_id absent from the Iceberg metadata schema map.
    #
    # Real-world trigger: Iceberg v3 row-lineage columns (_row_id=2147483540,
    # _last_updated_sequence_number=2147483539) are written into the Parquet by an
    # external engine but are not in the table's field-id map. ClickHouse cannot
    # itself emit a reserved field_id, so we reproduce the IDENTICAL code defect by
    # orphaning a normal field_id: write an Iceberg table with columns (c0,c1) — the
    # Parquet physically gets field_ids {1,2} — then drop field c1 from the metadata
    # schema, leaving the Parquet's field_id 2 unmapped. The V3 reader then throws
    # the very same Code:743 ICEBERG_SPECIFICATION_VIOLATION even for a query that
    # does NOT select the orphan column.
    #
    # Contract: bash <script> <clickhouse-binary>
    #   exit 1   = bug reproduces (read wrongly throws ICEBERG_SPECIFICATION_VIOLATION)
    #   exit 0   = clean: the read SUCCEEDED and returned the expected value
    #   exit 125 = inconclusive: iceberg write / V3 reader feature absent on this build
    #   exit 124 = timed out
    set -uo pipefail
    BIN="${1:?usage: repro.sh <clickhouse-binary>}"
    WORK="$(mktemp -d /tmp/ice107343.XXXXXX)"
    trap 'rm -rf "$WORK"' EXIT
    cd "$WORK" || exit 125
    TBL="$WORK/ice"
    
    # 1) Write a real on-disk Iceberg table (Parquet data file with field_ids {1,2}).
    timeout 60 "$BIN" local --path "$WORK/chdb" --query "
    SET allow_experimental_insert_into_iceberg = 1;
    CREATE TABLE t (c0 String, c1 Int64) ENGINE = IcebergLocal('$TBL', 'Parquet');
    INSERT INTO t (c0, c1) SELECT 'a', 7;
    " >/dev/null 2>&1
    [ $? -eq 124 ] && exit 124
    
    # 2) Sanity: the table must read back cleanly BEFORE surgery. If not, the
    #    iceberg-write / reader feature is absent on this build -> inconclusive.
    pre=$(cd "$WORK" && timeout 60 "$BIN" local --query "SELECT c0 FROM icebergLocal('$TBL')" 2>&1)
    [ $? -eq 124 ] && exit 124
    echo "$pre" | grep -qx "a" || { echo "[125] iceberg write/read feature absent: $pre" >&2; exit 125; }
    
    # 3) Surgery: drop field c1 from the metadata schema, orphaning its field_id in
    #    the Parquet. Require that a field was actually removed, else inconclusive.
    removed=$(python3 - "$TBL" <<'PY'
    import json, glob, sys
    tbl = sys.argv[1]
    n = 0
    for f in glob.glob(tbl + "/metadata/v*.metadata.json"):
        d = json.load(open(f))
        def strip(fields):
            global n
            out = [x for x in fields if x.get("name") != "c1"]
            n += len(fields) - len(out)
            return out
        for s in d.get("schemas", []):
            s["fields"] = strip(s.get("fields", []))
        if "schema" in d and isinstance(d["schema"], dict):
            d["schema"]["fields"] = strip(d["schema"].get("fields", []))
        json.dump(d, open(f, "w"), indent=2)
    print(n)
    PY
    )
    [ "${removed:-0}" -ge 1 ] 2>/dev/null || { echo "[125] could not patch metadata (removed=$removed)" >&2; exit 125; }
    
    # 4) Read a column that is NOT the orphan. Buggy build throws Code:743.
    out=$(cd "$WORK" && timeout 60 "$BIN" local ${CLICKGAP_REPRO_SETTINGS:+--$CLICKGAP_REPRO_SETTINGS} --query "SELECT c0 FROM icebergLocal('$TBL')" 2>&1)
    rc=$?
    [ $rc -eq 124 ] && exit 124
    echo "OBSERVED: $out" >&2
    if echo "$out" | grep -qiE "ICEBERG_SPECIFICATION_VIOLATION|not in datalake metadata|Code: 743"; then
        echo "[1] BUG: V3 reader rejected the file for an unmapped field_id" >&2
        exit 1
    fi
    if echo "$out" | grep -qx "a"; then
        echo "[0] CLEAN: read tolerated the unmapped field_id and returned 'a'" >&2
        exit 0
    fi
    echo "[125] inconclusive read result" >&2
    exit 125
    

    Bisect

    Affects

    • Reproduces on: master, 26.5
    • Does NOT reproduce on: 26.4, 26.3
    • Could not test (binary unavailable): 25.8

    Suggested next step

    Review PR #102362 for the introducing change in comp-datalake. If a forward-fix or revert is intended, the bisect data above narrows the search space.

    Component: comp-datalake
    Severity: P2

    cc introducing PR author: @scanhex12
    cc introducing PR reviewer: @clickhouse-gh[bot] @asya-ch


    ClickGap · Finding: h_issue_107343

    Triage metadata

  3. gregakinman commented on Jun 13, 2026

    @gregakinman
    Contributor

    Heads-up that the updated automated triage looks confounded: the reader defect is older than #102362, and this does affect 26.3 / 26.4.

    The current repro reports "clean" on 26.3/26.4 because it writes the data file with ClickHouse and then orphans a column via the metadata — but pre-26.5 ClickHouse writes no field_ids, so there is nothing to orphan and the reader falls back to name-matching. The real-world trigger is an external, spec-compliant Iceberg writer emitting the reserved row-lineage ids (_row_id / _last_updated_sequence_number). A writer-independent repro — inject the reserved field_id directly into the data file — reproduces across 25.11 → master.

    Fix + writer-independent regression test: #107377 (should be backported to 26.3 and 26.4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    potential bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions