Partitioned INSERT computes partition values from the wrong columns when the input plan ends in a projection
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Start in crates/datafusion/src/physical_plan/project.rs, then trace PartitionExpr::children, PartitionValueCalculator::calculate, project_with_partition, and IcebergWriteExec. Run the INSERT reproduction with the aliased and reordered columns, inspect the optimized plan and written partition paths, and confirm that partition pruning returns the expected rows after the fix.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
For partitioned tables, insert_into adds a ProjectionExec that computes the _partition column with PartitionExpr. PartitionExpr reads its source columns by position: PartitionValueCalculator::calculate indexes batch.columns() with positions precomputed from the table schema. But PartitionExpr::children() returns an empty list (project.rs#L210-L212).
Because the expression appears to reference no columns, DataFusion's ProjectionPushdown rule merges the partition projection into a ProjectionExec beneath it and leaves PartitionExpr unchanged. PartitionExpr then runs against the input batch of the lower projection, which has a different column layout.
The data columns are still written correctly, but each data file gets partition values computed from another column. Reads that prune by partition then silently skip those files.
To Reproduce
-- pt: id INT NOT NULL, val INT NOT NULL, partitioned by identity(id)
-- src (MemTable): a INT NOT NULL, b INT NOT NULL, rows (1, 100), (2, 200)
INSERT INTO pt SELECT b AS id, a AS val FROM src;
Optimized physical plan:
IcebergCommitExec: table=ns.pt
IcebergWriteExec: table=ns.pt
ProjectionExec: expr=[b@1 as id, a@0 as val, iceberg_partition_values(id) as _partition]
DataSourceExec: partitions=1, partition_sizes=[1]
The partition values come from column 0 of the source batch (a) instead of from id (b):
- data files are written under
data/id=1anddata/id=2instead ofdata/id=100anddata/id=200 SELECT * FROM ptreturns(100, 1)and(200, 2)SELECT * FROM pt WHERE id = 100returns no rows
Expected behavior
Partition values are computed from the columns being written, however the optimizer rearranges the projections.
Additional context
Any INSERT whose physical input ends in a ProjectionExec that renames, reorders or drops columns is exposed (column aliases, inserts from joins, ...). VALUES and SELECT * from a source with the table's column order work only because the positions happen to line up. The schema check in project_with_partition runs before physical optimization, so it doesn't catch this.
Possible fixes:
- expose the source columns as
Columnchildren, so projection rewrites update them - check the batch schema in
evaluateand resolve source columns by name or field id - compute partition values inside
IcebergWriteExecinstead of in aPhysicalExpr
- 主要言語
- Rust
- スター
- 30
- フォーク
- 30
- 平均マージ
- 3日 19時間
- マージ済み PR(30日)
- 15
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/datafusion-iceberg のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
apache/datafusion-iceberg#100 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
apache/datafusion-iceberg#85 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
apache/datafusion-iceberg#84 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
apache/datafusion-iceberg#75 ·
メンテナーはふだん 1 日以内に返信
-
Slow CI runnersオープン
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
apache/datafusion-iceberg#74 ·
メンテナーはふだん 1 日以内に返信
apache/datafusion-iceberg の issue をすべて見る
似ている issue
-
binding:python bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
coollabsio/orbit#72 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
bug order-flow studies ui
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
userFRM/egui-charts#2417 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信