Repository navigation
fix: reject multiple UPDATE assignments to the same column - #27100
Open
vshalpnjabi wants to merge 2 commits into
Open
vshalpnjabi wants to merge 2 commits into
vshalpnjabi wants to merge 2 commits into
Conversation
UPDATE t SET a = 1, a = 2 planned successfully and kept the last assignment. Detect a duplicate SET target while building the assignment map and return a planning error, matching PostgreSQL. Closes apache#27096
Author
|
@alamb Ready for review when you have a moment — thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
UPDATE t SET a = 1, a = 2planned successfully and applied only the last assignment. The SQL standard doesn't allow the same column twice in a SET list, and PostgreSQL and DuckDB reject it. A typo likeSET a = x, a = y(meantb = y) would silently update the wrong data.What changes are included in this PR?
SqlToRel::update_to_plannow inserts SET targets into the column map one at a time and returns a planning error on a repeat:Error during planning: multiple assignments to same column "a"t.aandacount as the same target, since the planner already keys SET columns by the last identifier.Are these changes tested?
Yes:
update_rejects_duplicate_assignmentindatafusion/sql/tests/sql_integration.rs(adjacent duplicates, a duplicate after another column, qualified + unqualified). It fails onmainand passes with the fix.update.slt: the issue's reproducer, plus a normalSET a = 1, b = 2that still updates.Ran locally:
cargo test -p datafusion-sqlcargo test --profile=ci -p datafusion-sqllogictest --test sqllogictests -- update.sltcargo clippy -p datafusion-sql --all-targets --all-features -- -D warningscargo fmt --all -- --checkAre there any user-facing changes?
Yes. An
UPDATEthat assigns the same column more than once is now a planning error instead of keeping the last value. No public API changes.One assumption to flag: the check compares the same key the planner already used (
Ident.value, as written), so it doesn't add any identifier normalization of its own.AI-assisted; I reviewed the full diff and ran the tests myself.