Skip to content

Comments

[SPARK-51834][SQL][FOLLOW-UP][4.1] Add missing .withConstraints() in AtomicReplaceTableExec#54404

Open
yyanyy wants to merge 1 commit intoapache:branch-4.1from
yyanyy:backport-SPARK-51834-follow-up-branch-4.1
Open

[SPARK-51834][SQL][FOLLOW-UP][4.1] Add missing .withConstraints() in AtomicReplaceTableExec#54404
yyanyy wants to merge 1 commit intoapache:branch-4.1from
yyanyy:backport-SPARK-51834-follow-up-branch-4.1

Conversation

@yyanyy
Copy link
Contributor

@yyanyy yyanyy commented Feb 20, 2026

(This PR is to backport #54322)

What changes were proposed in this pull request?

SPARK-51834 added .withConstraints() to CreateTableExec and ReplaceTableExec but missed AtomicReplaceTableExec in the same file. This causes REPLACE TABLE and CREATE OR REPLACE TABLE with constraints to silently drop them when the catalog implements StagingTableCatalog.

Also fixes StagingInMemoryTableCatalog to forward constraints when constructing InMemoryTable, and adds regression tests for all four constraint types through the atomic replace path.

Why are the changes needed?

AtomicReplaceTableExec does not call .withConstraints() when building TableInfo, so REPLACE TABLE and CREATE OR REPLACE TABLE silently drop constraints when the catalog implements StagingTableCatalog.

Does this PR introduce any user-facing change?

Yes. Previously, REPLACE TABLE and CREATE OR REPLACE TABLE with constraints would silently drop constraints when using a StagingTableCatalog. After this fix, constraints are correctly passed through to the catalog.

How was this patch tested?

New unit tests in UniqueConstraintSuite, PrimaryKeyConstraintSuite, CheckConstraintSuite, and ForeignKeyConstraintSuite that exercise REPLACE TABLE with constraints through the atomic catalog path (StagingInMemoryTableCatalog). Verified that all 4 new tests fail without the fix and pass with it. All existing tests in these suites continue to pass.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.6 <noreplyanthropic.com>

Closes #54322 from yyanyy/staging_catalog_constraint.

Authored-by: Yan Yan yyanyyyy@gmail.com

…omicReplaceTableExec`

### What changes were proposed in this pull request?

SPARK-51834 added `.withConstraints()` to `CreateTableExec` and `ReplaceTableExec` but missed `AtomicReplaceTableExec` in the same file. This causes `REPLACE TABLE` and `CREATE OR REPLACE TABLE` with constraints to silently drop them when the catalog implements `StagingTableCatalog`.

Also fixes `StagingInMemoryTableCatalog` to forward constraints when constructing `InMemoryTable`, and adds regression tests for all four constraint types through the atomic replace path.

### Why are the changes needed?
`AtomicReplaceTableExec` does not call `.withConstraints()` when building `TableInfo`, so `REPLACE TABLE` and `CREATE OR REPLACE TABLE` silently drop constraints when the catalog implements `StagingTableCatalog`.

### Does this PR introduce _any_ user-facing change?

Yes. Previously, REPLACE TABLE and CREATE OR REPLACE TABLE with constraints would silently drop constraints when using a `StagingTableCatalog`. After this fix, constraints are correctly passed through to the catalog.

### How was this patch tested?
New unit tests in `UniqueConstraintSuite`, `PrimaryKeyConstraintSuite`, `CheckConstraintSuite`, and `ForeignKeyConstraintSuite` that exercise `REPLACE TABLE` with constraints through the atomic catalog path (`StagingInMemoryTableCatalog`). Verified that all 4 new tests fail without the fix and pass with it. All existing tests in these suites continue to pass.

### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.6 <noreplyanthropic.com>

Closes apache#54322 from yyanyy/staging_catalog_constraint.

Authored-by: Yan Yan <yyanyyyy@gmail.com>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
@pan3793 pan3793 changed the title [SPARK-51834][SQL][FOLLOW-UP] Add missing .withConstraints() in AtomicReplaceTableExec [SPARK-51834][SQL][FOLLOW-UP][4.1] Add missing .withConstraints() in AtomicReplaceTableExec Feb 21, 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.

1 participant