Skip to content

Backport #116129 to 26.6: Fix iceberg identity partitioned reading - #116675

Closed
robot-ch-test-poll2 wants to merge 6 commits into
26.6from
backport/26.6/116129
Closed

robot-ch-test-poll2 wants to merge 6 commits into
26.6from
backport/26.6/116129

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #116129
Cherry-pick pull-request #116574

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

@robot-ch-test-poll2 robot-ch-test-poll2 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default labels Aug 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [f6fe813]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 3/8) FAIL
test_storage_iceberg_no_spark/test_identity_partition_column_projection.py::test_identity_partition_column_with_row_policy FAIL cidb
test_storage_iceberg_no_spark/test_identity_partition_column_projection.py::test_identity_partition_column_renamed_after_write FAIL cidb
Integration tests (amd_tsan, 2/6) FAIL
test_storage_iceberg_no_spark/test_identity_partition_column_projection.py::test_identity_partition_column_with_row_policy FAIL cidb
test_storage_iceberg_no_spark/test_identity_partition_column_projection.py::test_identity_partition_column_renamed_after_write FAIL cidb

@scanhex12

Copy link
Copy Markdown
Member

@groeneai could you please resolve the conflicts and fix builds?

@groeneai

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

I resolved this locally against current 26.6 (2483867) and got a green build. I do not have push access to ClickHouse/ClickHouse, so here is the resolution rather than a push.

The conflict is one hunk, in src/Storages/ObjectStorage/StorageObjectStorageSource.cpp. 26.6 already has the has_schema_transform / keep_in_reader block, so the only real difference is the tail: keep this branch's side (the identity-substituted row_level_filter / prewhere_info, which is the point of #116129) and drop the assignment to FormatFilterInfo::current_schema_column_mapper:

const bool keep_in_reader = format_supports_prewhere && !has_schema_transform;
return std::make_shared<FormatFilterInfo>(
    format_filter_info->filter_actions_dag, format_filter_info->context.lock(),
    mapper,
    keep_in_reader ? row_level_filter : nullptr,
    keep_in_reader ? prewhere_info : nullptr);

That is also the failure on all 7 builds. current_schema_column_mapper was added by #104435 (GeoParquet row group pruning, pr-performance), which is not on 26.6, and nothing on 26.6 reads it.

Two more -Werror failures show up once that one is fixed, both because the cherry-pick carries fragments of master commits that 26.6 does not have:

  • StorageObjectStorageSource.cpp: hasAttachedDeletes() is defined but never called, since its call sites in the need_only_count path are not part of Fix iceberg identity partitioned reading #116129. -Wunused-function.
  • Iceberg/Compaction.cpp: const auto & data_file_path = ... is dead, since 26.6 still keys path_to_data_file by the manifest path. -Wunused-variable.

Deleting both is enough; diff at the bottom.

Two things I would rather leave to you. Comparing this branch's diff against #116129 per file, added lines are ProtocolDefines.h 7 vs 2, Compaction.cpp 11 vs 4, StorageObjectStorageSource.cpp 173 vs 122, test_storage_s3/test.py 0 vs 36:

  1. ProtocolDefines.h here also declares versions 7 and 8 and sets DBMS_CLUSTER_PROCESSING_PROTOCOL_VERSION = 9, but 26.6 does not implement version 8: its ClusterFunctionReadTask.cpp has no read_source_index at all. The sender gates on min(worker_version, local_version), so a 26.6 server advertising 9 makes a newer initiator write a read_source_index field the 26.6 reader never reads, and a 26.6 initiator omit the field a newer worker does read. Keeping 26.6 at 6 avoids that and still fixes the plain iceberg path (the new integration test is single node, no cluster function), at the cost of leaving icebergCluster unfixed on 26.6.
  2. test_row_policy_over_csv from Fix iceberg identity partitioned reading #116129 did not make it onto this branch. It is the regression test for the row level filter substitution, so it looks worth adding back.

Verified: merged 26.6 at 2483867 into 384d37b, applied the three deletions below, full Debug build with clang-21 (the ToolSet pin on 26.6) is green, and the binary reports 26.6.5.1.

Build fixups, applying on top of the merge
diff --git a/src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp b/src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp
--- a/src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp
+++ b/src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp
@@ -192,13 +192,6 @@ static Plan getPlan(
                     persistent_table_components.path_resolver.resolve(data_file->parsed_entry->file_path_key),
                     0,
                     Iceberg::getIdentityPartitionColumnValues(*data_file, *persistent_table_components.schema_processor));
-                /// One DataFilePlan per source *data file*, keyed by the data file's own path.
-                /// Keying by the manifest path made every data file after the first in a
-                /// manifest reuse the first file's plan, so writeDataFiles rewrote only one
-                /// file per manifest and the rest of the manifest's data silently disappeared
-                /// from the compacted table. The map still deduplicates the same data file
-                /// referenced from multiple snapshots' manifest lists.
-                const auto & data_file_path = data_file->parsed_entry->file_path_key;
                 std::shared_ptr<DataFilePlan> data_file_ptr;
                 if (!plan.path_to_data_file.contains(manifest_file.manifest_file_path))
                 {
diff --git a/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp b/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
--- a/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
+++ b/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
@@ -122,26 +122,6 @@ static void logIcebergFileStats(const ObjectInfoPtr & object_info, const LoggerP
 #endif
 }
 
-/// Whether reading this object goes through row-level delete transformers (Iceberg
-/// position/equality deletes, Delta Lake deletion vectors). The count-from-files cache
-/// is keyed only by the file path and its modification time, but delete files change the
-/// number of rows the file contributes WITHOUT touching the file itself, so both
-/// directions are unsafe: a count cached before a delete resurfaces deleted rows, and a
-/// count cached after it goes stale once the deletes are compacted away. Such files must
-/// neither use nor populate the cache.
-static bool hasAttachedDeletes(const ObjectInfo & object_info)
-{
-#if USE_AVRO
-    if (const auto * iceberg_object = dynamic_cast<const IcebergDataObjectInfo *>(&object_info))
-    {
-        if (!iceberg_object->info.position_deletes_objects.empty() || !iceberg_object->info.equality_deletes_objects.empty())
-            return true;
-    }
-#endif
-    return object_info.data_lake_metadata && object_info.data_lake_metadata->excluded_rows
-        && object_info.data_lake_metadata->excluded_rows->size() > 0;
-}
-
 static bool readsIdentityPartitionColumn(
     const ActionsDAG & dag, const std::vector<std::pair<String, Field>> & identity_partition_columns)
 {
@@ -996,18 +976,11 @@ StorageObjectStorageSource::ReaderHolder StorageObjectStorageSource::createReade
                             stripped_prewhere_info = format_filter_info->prewhere_info;
                     }
                     const bool keep_in_reader = format_supports_prewhere && !has_schema_transform;
-                    auto result = std::make_shared<FormatFilterInfo>(
+                    return std::make_shared<FormatFilterInfo>(
                         format_filter_info->filter_actions_dag, format_filter_info->context.lock(),
                         mapper,
                         keep_in_reader ? row_level_filter : nullptr,
                         keep_in_reader ? prewhere_info : nullptr);
-                    /// `mapper` is scoped to the schema this specific file was written under, so it
-                    /// maps field_id -> the column name *that file* used. Keep the current/query-side
-                    /// mapper around too (see `current_schema_column_mapper` doc comment) for readers
-                    /// that need to resolve query-side filter column names (e.g. GeoParquet spatial
-                    /// pruning) back to a field_id.
-                    result->current_schema_column_mapper = format_filter_info->column_mapper;
-                    return result;
                 }
             }

alexey-milovidov and others added 5 commits September 13, 2026 17:51
…r` here

The cherry-pick carried master's tail that assigns
`result->current_schema_column_mapper`, so the build failed:

  error: no member named 'current_schema_column_mapper' in 'DB::FormatFilterInfo'

That member keeps the query-side mapper for readers that resolve
filter column names back to a field id (GeoParquet spatial pruning),
and it does not exist in this branch. Return the newly built
`FormatFilterInfo` directly, which leaves the same shape as
`backport/26.3/116129`.
The branch was 375 commits behind and GitHub reported it
`CONFLICTING`, which is why it had no CI at all.

The only conflict is `StorageObjectStorageSource.cpp`, in two places,
both resolved in favour of this pull request:

- The identity-partition helpers (`readsIdentityPartitionColumn`,
  `substituteIdentityPartitionColumns`,
  `buildIdentityPartitionColumnsDag`) are what the pull request adds
  and 26.6 has nothing there.
- The `FormatFilterInfo` built for a schema-changed file must be given
  the local `row_level_filter` / `prewhere_info`, not
  `format_filter_info->...`. Those locals are where the identity
  partition values have just been substituted into the filters, which
  is the whole point of this change; taking 26.6's spelling would
  bypass the substitution. `master` passes the locals in the same way.
Every build failed on

    Compaction.cpp:201: error: unused variable 'data_file_path' [-Werror,-Wunused-variable]

The cherry-pick brought the comment and the declaration of #111617's keying
fix as context of the changed constructor call, but not the code: the three
lookups still used `manifest_file.manifest_file_path`, which the comment right
above them explains makes every data file after the first in a manifest reuse
the first file's plan, so the rest of the manifest's data silently disappears
from the compacted table. 26.6 never received that part of #111617 (#119206
carried only the trivial-count fix), so `-Werror` caught a real hole, not a
stylistic one. Use `data_file_path` for the `contains` check and both map
accesses, which is what `master` does and how the 26.3 backport resolved the
same conflict.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… test

The backport moves `DBMS_CLUSTER_PROCESSING_PROTOCOL_VERSION` from 6 straight
to 9, defining 7 and 8 as constants so the number space matches `master`. But
26.6 has no code for version 8, `read_source_index` from #95181, which was
never backported. The version is negotiated as `min(worker, own)` and the task
response is written straight onto the connection, so in a mixed 26.6/26.7+
cluster both sides would agree on 9, one would write a field the other never
reads, and the stream would misalign in both directions.

Carry the version-8 field exactly as `master` does: this release never sets
`read_source_index`, so it writes an empty one, and a 26.6 worker that receives
a set one throws `UNKNOWN_PROTOCOL` instead of reading the wrong shards, which
is the same fail-closed rule `master` applies on the sending side.

Also restore `test_row_policy_over_csv`, which the cherry-pick dropped because
it appends after a test that does not exist on 26.6; the change it covers is
carried verbatim.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@maxknv
maxknv deleted the backport/26.6/116129 branch November 13, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants