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

未关闭
#56 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Rust
星标
33
派生
34
平均合并
4 天 14 小时
30 天内合并 PR
10

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion-iceberg 的其他 Issue

查看 apache/datafusion-iceberg 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。