INSERT into a partitioned table with fanout disabled always fails: the optimizer removes the partition sort

Abierto
#38 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Read crates/datafusion/src/table/mod.rs#L200-L220 and crates/datafusion/src/physical_plan/write.rs#L143-L151, then run test_insert_plan_fanout_disabled_has_sort and reproduce the partitioned INSERT with fanout disabled. Done means physical optimization preserves or restores the partition sort and hash repartition, and the insert succeeds with the writer receiving input clustered by partition.

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

Descripción

bug
Describe the bug

With write.datafusion.fanout.enabled=false, insert_into places a SortExec on _partition, and a hash RepartitionExec on _partition, in front of IcebergWriteExec (table/mod.rs#L200-L220), because ClusteredWriter needs its input grouped by partition.

IcebergWriteExec doesn't declare required_input_ordering or required_input_distribution. It reports maintains_input_order() == [true] but advertises no output ordering (write.rs#L143-L151). DataFusion's EnforceSorting therefore treats the sort as unnecessary and removes it, and EnforceDistribution replaces the hash repartition.

To Reproduce
  1. Create t6(id INT NOT NULL, cat INT NOT NULL), partitioned by identity(cat), with write.datafusion.fanout.enabled=false.
  2. Run INSERT INTO t6 SELECT id, cat FROM src, where src has 200 rows with cat = id % 10 and batch_size = 8.

Optimized plan with target_partitions = 4:

IcebergCommitExec: table=ns.t6
  CoalescePartitionsExec
    IcebergWriteExec: table=ns.t6
      ProjectionExec: expr=[id@0 as id, cat@1 as cat, iceberg_partition_values(cat) as _partition]
        RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
          DataSourceExec: partitions=1, partition_sizes=[1]

All 10 runs failed, at both target_partitions = 1 and 4:

The input is not sorted! Cannot write to partition that was previously closed: PartitionKey { ... }
Expected behavior

The insert succeeds, with the writer receiving its input clustered by partition.

Additional context
  • test_insert_plan_fanout_disabled_has_sort passes because it inspects the plan that insert_into returns, which hasn't been through physical optimization.
  • Declaring the requirements on IcebergWriteExec would let the optimizer keep or re-insert them: required_input_ordering on _partition when fanout is disabled, and a hash required_input_distribution on _partition.
  • With fanout enabled (the default), the hash repartition is also replaced by round-robin, so every write task writes every partition. The data is correct, but there are more and smaller files than intended.
  • Even with the sort kept, clustered writes still fail for a second reason: #39. The unpartitioned case of this setting fails separately: #43.
Lenguaje dominante
Rust
Estrellas
33
Forks
34
Merge medio
4 d 14 h
PR fusionados (30 d)
10

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.