shivadarshan-devadiga commented on code in PR #60756:
URL: https://github.com/apache/spark/pull/60756#discussion_r4652420962


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala:
##########
@@ -393,12 +415,26 @@ object CharVarcharUtils extends Logging with 
SparkCharVarcharUtils {
 
   /**
    * Matches the read-side CHAR padding that [[addPaddingForScan]] wraps a 
column in (when
-   * standard semantics are off) and extracts the padded expression and the 
CHAR length.
+   * standard semantics are off) and extracts the padded expression and the 
CHAR length. A padding
+   * over another one to a length that is not longer, or a narrowing to a 
length that is not longer,
+   * matches as one padding of its value.
    */
   private[sql] object ReadSidePadding {
     def unapply(e: Expression): Option[(Expression, Int)] = e match {
       case s @ StaticInvoke(_, _, READ_SIDE_PADDING, Seq(child, Literal(n: 
Int, _)), _, _, _, _,
           None) if s.staticObject == classOf[CharVarcharCodegenUtils] =>
+        child match {
+          // The padding of a set operation over the padding of a scan, to a 
length that is at
+          // least as long, is the padding of the scan to that length.
+          case ReadSidePadding(grandChild, m) if m <= n => Some((grandChild, 
n))
+          case _ => Some((child, n))
+        }
+      // The narrowing of a view or a recursive CTE over the padding to a 
longer length: for a value
+      // that fits in the shorter length, which is all a string of that length 
can be equal to, it
+      // is the padding of the value to that length.
+      case s @ StaticInvoke(_, _, CHAR_TYPE_NARROWING,

Review Comment:
   Thanks, you're right, and my reasoning about values that fit was wrong: a 
CHAR(5) child stores 'a    ', which the narrowing trims to 'a  ', while padding 
to 3 keeps it. I've removed that case, so `ReadSidePadding` doesn't match a 
narrowing any more, and V2ExpressionBuilder doesn't push it down. That means a 
filter on a column of a view stored before this change, over a set operation of 
CHAR columns of different lengths, isn't pushed down to a V2 source. Recreating 
the view stores the widest length and doesn't need the narrowing. The case for 
a padding over a padding to a length at least as long stays, as the two are the 
same for every value. The view test still checks that `WHERE c = 'a'` returns 
the t5 row.



-- 
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]

Reply via email to