shivadarshan-devadiga commented on code in PR #60756:
URL: https://github.com/apache/spark/pull/60756#discussion_r4651422045
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ApplyCharTypePaddingHelper.scala:
##########
@@ -68,16 +90,46 @@ object ApplyCharTypePaddingHelper {
private[sql] def paddingForStringComparison(
plan: LogicalPlan,
padCharCol: Boolean): LogicalPlan = {
-
plan.resolveOperatorsUpWithSubqueriesAndPruning(_.containsAnyPattern(BINARY_COMPARISON,
IN)) {
+ plan.resolveOperatorsUpWithSubqueriesAndPruning(
+ _.containsAnyPattern(BINARY_COMPARISON, IN, IN_SUBQUERY)) {
case operator =>
-
operator.transformExpressionsUpWithPruning(_.containsAnyPattern(BINARY_COMPARISON,
IN)) {
+ withRawTypesOfInput(operator).transformExpressionsUpWithPruning(
+ _.containsAnyPattern(BINARY_COMPARISON, IN, IN_SUBQUERY)) {
case e if !e.childrenResolved => e
case withChildrenResolved =>
singleNodePaddingForStringComparison(withChildrenResolved,
padCharCol)
}
}
}
+ /**
+ * A reference resolved before its operator, such as a column of a
DataFrame, keeps the raw type
+ * its column had then, which a set operation can widen since. This gives
the CHAR references of
+ * the operator the raw types of the columns of its children, which
comparisons pad to.
+ */
+ private def withRawTypesOfInput(operator: LogicalPlan): LogicalPlan = {
Review Comment:
Both are gone. With the padding during analysis, the set operation's output
carries the widest length from the start, and no reference has to be refreshed
afterwards.
On the pushdown from your earlier comment: the analysis-time padding now
sits over the scan's own `readSidePadding(c, 3)`.
`CharVarcharUtils.ReadSidePadding` matches `readSidePadding(readSidePadding(c,
3), 5)` as `readSidePadding(c, 5)`, so the V2 translation still gives the
source one padding of the column, and the union test checks that the optimized
plan has it.
--
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]