[SPARK-55647][SQL] Fix ConstantPropagation incorrectly replacing attributes with non-binary-stable collations#54435
Closed
ilicmarkodb wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-55647][SQL] Fix ConstantPropagation incorrectly replacing attributes with non-binary-stable collations#54435ilicmarkodb wants to merge 1 commit intoapache:masterfrom
ConstantPropagation incorrectly replacing attributes with non-binary-stable collations#54435ilicmarkodb wants to merge 1 commit intoapache:masterfrom
Conversation
ConstantPropagation incorrectly replacing attributes with non-binary-stable collations
cloud-fan
approved these changes
Feb 24, 2026
Contributor
|
thanks, merging to master/4.1! |
cloud-fan
pushed a commit
that referenced
this pull request
Feb 24, 2026
…tributes with non-binary-stable collations
### What changes were proposed in this pull request?
* `ConstantPropagation` optimizer rule substitutes attributes with literals derived from equality
predicates (e.g. `c = 'hello'`), then propagates them into other conditions in the same
conjunction. This is unsafe for non-binary-stable collations (e.g. `UTF8_LCASE`) where
equality is non-identity: `c = 'hello'` (case-insensitive) does not imply `c` holds exactly
the bytes `'hello'` - it could also be `'HELLO'`, `'Hello'`, etc.
* Substituting `c → 'hello'` in a second condition like `c = 'HELLO' COLLATE UNICODE` turns it
into the constant expression `'hello' = 'HELLO' COLLATE UNICODE`, which is always `false`,
producing incorrect results.
* Fixed by guarding `safeToReplace` with `isBinaryStable(ar.dataType)` so propagation is skipped
for attributes whose type is not binary-stable.
### Why are the changes needed?
Bug fix.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
New unit test.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #54435 from ilicmarkodb/fix_collation_.
Authored-by: ilicmarkodb <marko.ilic@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit ec35791)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
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.
What changes were proposed in this pull request?
ConstantPropagationoptimizer rule substitutes attributes with literals derived from equalitypredicates (e.g.
c = 'hello'), then propagates them into other conditions in the sameconjunction. This is unsafe for non-binary-stable collations (e.g.
UTF8_LCASE) whereequality is non-identity:
c = 'hello'(case-insensitive) does not implycholds exactlythe bytes
'hello'- it could also be'HELLO','Hello', etc.c → 'hello'in a second condition likec = 'HELLO' COLLATE UNICODEturns itinto the constant expression
'hello' = 'HELLO' COLLATE UNICODE, which is alwaysfalse,producing incorrect results.
safeToReplacewithisBinaryStable(ar.dataType)so propagation is skippedfor attributes whose type is not binary-stable.
Why are the changes needed?
Bug fix.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New unit test.
Was this patch authored or co-authored using generative AI tooling?
No.