Partitioned INSERT computes partition values from the wrong columns when the input plan ends in a projection

Abierto
#35 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@NoahKusaba ya está trabajando en esto.

Desde el 29/10/2026.

  • #92 de @NoahKusaba — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust, sql
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
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=1 and data/id=2 instead of data/id=100 and data/id=200
  • SELECT * FROM pt returns (100, 1) and (200, 2)
  • SELECT * FROM pt WHERE id = 100 returns 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 Column children, so projection rewrites update them
  • check the batch schema in evaluate and resolve source columns by name or field id
  • compute partition values inside IcebergWriteExec instead of in a PhysicalExpr
Lenguaje dominante
Rust
Estrellas
30
Forks
30
Merge medio
3 d 19 h
PR fusionados (30 d)
15

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/datafusion-iceberg

Todos los issues de apache/datafusion-iceberg

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.