Skip to content

fix: refuse CREATE TABLE … AS rows in any input partition - #169

Closed
NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:fix/ctas-rows-in-any-partition
Closed

NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:fix/ctas-rows-in-any-partition

Conversation

@NoahKusaba

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #168.

Rationale for this change

This crate can't write CREATE TABLE … AS rows, so register_table refuses input that has any. The check read only partition 0, but DataFusion passes the input with the query's partitioning. A query whose rows were all in later partitions created an empty table and reported success.

What changes are included in this PR?

ensure_table_is_empty reads every partition of the input in turn and stops at the first row. As before, it asks each partition for at most one row.

Not changed:

Are these changes tested?

Yes, create_table_as_checks_every_input_partition in tests/catalog_provider.rs, through SQL:

  • CREATE TABLE … AS from a source whose only row is in the middle of three partitions, after an empty batch, is refused.
  • The same query filtered to no rows then creates the table, which also shows the refused statement created nothing.

The test fails on main. It also fails for a check that reads only the last partition, only the first batch of each partition, or that refuses any input with several partitions.

Are there any user-facing changes?

Yes: CREATE TABLE … AS now fails for a query with rows outside its first partition, instead of creating an empty table.

This crate can't write `CREATE TABLE … AS` rows, so `register_table`
refuses input that has any. It checked only partition 0, but DataFusion
passes the input with the query's partitioning. With rows only in later
partitions, the statement succeeded and created an empty table.
@NoahKusaba NoahKusaba closed this Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CREATE TABLE … AS creates an empty table when the query's first partition has no rows

1 participant