INSERT fails after a column is added to the table, until the provider is rebuilt

Abierto
#56 0 comentarios 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
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Start with insert_into in crates/datafusion/src/table_provider/catalog_table_provider.rs, where the cached Arrow schema is used to plan the input, then read IcebergWriteExec in crates/datafusion/src/write/exec.rs, where the Parquet writer takes the table's current schema. Reproduce by adding a column to the table outside the session and running an INSERT. Done means either the missing columns are filled with NULL, or the INSERT fails with a clear schema-changed error, and a test covers the case. The fix choice is a design decision, so confirm it with maintainers first.

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

Descripción

bug
Describe the bug

IcebergCatalogTableProvider caches the table's Arrow schema when it is built (catalog_table_provider.rs#L81-L84). IcebergCatalogProvider builds one provider per table when it is constructed and keeps it (schema.rs#L64-L94). insert_into plans its input against the cached schema, but IcebergWriteExec builds the Parquet writer from the table's current schema (write/exec.rs#L244-L250).

Once a column has been added to the table, by another engine or another session, the input batches lack that column and the Parquet writer fails on it:

Execution error: DataInvalid => Field id 3 not found in struct array

Every INSERT through that provider fails this way, with or without a column list, including after other sessions have written with the new schema. Scans through the same provider keep working and return only the cached columns. Writing works again only once the provider is rebuilt, which for IcebergCatalogProvider means registering the catalog again.

To Reproduce

Tested with an unpartitioned table in a MemoryCatalog:

  1. Create ns.t(id INT NOT NULL, name STRING NOT NULL), register an IcebergCatalogProvider as c in a session, and run INSERT INTO c.ns.t VALUES (1, 'a').
  2. Outside that session, add an optional column, for example with Transaction::update_schema().add_column(AddColumn::optional("email", Type::Primitive(PrimitiveType::String))) or ALTER TABLE t ADD COLUMN email STRING from Spark.
  3. In the same session, run INSERT INTO c.ns.t VALUES (2, 'b') or INSERT INTO c.ns.t (id, name) VALUES (2, 'b'). Both fail with the error above.

In a session that registers the catalog after step 2, INSERT INTO c.ns.t (id, name) VALUES (2, 'b') succeeds and email reads back as NULL.

Expected behavior

The INSERT succeeds and writes NULL for email, as it does through a provider built after the change. At the least, it should fail with an error saying that the table's schema changed after the provider was built.

Additional context
  • This is a concrete case of #24 §2: the provider plans with its cached schema but writes with the table's current metadata. It persists because of #24 §1: IcebergCatalogProvider never rebuilds its providers.
  • #48 adds a constructor so that Ballista can rebuild a provider on the scheduler with the schema the client planned against. Ballista runs DML through that rebuilt provider, so it fails the same way.
  • Possible fixes:
    • have IcebergWriteExec fill the columns the input lacks with NULL, or with their write default
    • have insert_into compare the cached schema with the table's current schema and return a clear error
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.