uros-b commented on code in PR #56499:
URL: https://github.com/apache/spark/pull/56499#discussion_r3430497100
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/QueryPlanConstraints.scala:
##########
@@ -77,6 +77,27 @@ trait ConstraintHelper {
inferredConstraints ++= replaceConstraints(predicates - eq -
EqualNullSafe(l, r), l, r)
case _ => // No inference
}
+
+ // Second pass: substitute (attr = literal) bindings into range/inequality
predicates.
+ // When a.pt = '20260610' and b.pt >= f(a.pt) are both in the constraint
set,
+ // substituting yields b.pt >= f('20260610'), which ConstantFolding then
reduces to a
+ // literal comparison that can be pushed into the right-side scan as a
partition filter.
+ val attrToLiteral: Map[Attribute, Literal] = predicates.collect {
Review Comment:
Can we reuse the existing machinery, instead of a hand-rolled second pass?
The file already has `replaceConstraints` (which substitutes via
`semanticEquals`). The natural implementation would be to add cases to the
existing pattern match, e.g.
```
case eq @ EqualTo(l: Attribute, r: Literal) =>
inferredConstraints ++= replaceConstraints(predicates - eq, l, r)
// (as well as the literal-on-left mirror)
```
rather than building a parallel `attrToLiteral` map with manual `transform`.
This would be simpler, remove the extra `if (attrToLiteral.nonEmpty), and
avoid an equality-semantics inconsistency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]