INSERT nullability: unpartitioned path skips the runtime NULL check; partitioned path rejects nullable sources at plan time

Open
#22 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust, sql
Domain
database

Research direction

Start in crates/datafusion/src/table/mod.rs at project_with_partition and crates/datafusion/src/physical_plan/write.rs at execute_input_stream; compare the unpartitioned and partitioned paths with DataFusion's check_not_null_constraints. Reproduce the MemTable INSERT with a nullable id, then verify both paths use the table schema, catch actual NULLs at runtime, and allow nullable sources when no NULL is present.

Written by the indexing model from the issue text.

Description

Reported by @mbutrovich in #19.

Unpartitioned tables: NULLs are written into required columns

The unpartitioned path skips project_with_partition (table/mod.rs), and IcebergWriteExec passes the input's own schema as the sink schema to execute_input_stream (write.rs).

DataFusion only runs check_not_null_constraints for columns that are non-nullable in the sink schema and nullable in the input. Because both schemas are the input's here, the check never runs.

Repro: inserting SELECT * FROM source into an unpartitioned table with a required id: int column, from a MemTable whose nullable id holds [1, NULL], succeeds and reads back 0, 1. The NULL is written as 0.

Partitioned tables: nullable sources are rejected at plan time

The partitioned path goes the other way. project_with_partition rejects any source column that is nullable where the table column is required, even when the source holds no nulls. DataFusion's own sinks accept that case and check at runtime.

Possible fix

Passing the table's Arrow schema (plus the partition column) as the sink schema to execute_input_stream would likely fix both: nulls would be caught at runtime on either path, and the plan-time rejection of nullable sources could be relaxed.

Dominant language
Rust
Stars
30
Forks
30
Avg merge
3d 19h
Merged PRs (30d)
15

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/datafusion-iceberg

All issues in apache/datafusion-iceberg

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.