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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ApplyCharTypePaddingHelper.scala:
##########
@@ -158,9 +161,49 @@ object ApplyCharTypePaddingHelper {
           i.copy(value = newChildren.head, list = newChildren.tail)
         }
 
+      case i: InSubquery if i.resolved => padInSubquery(i)
+
       case other => other
     }
 
+  /**
+   * For CHAR values compared with CHAR columns of a different length of an IN 
subquery, pads the
+   * shorter of each to the longer length. Like read-side padding, it does not 
truncate longer
+   * values. The columns are padded in a Project over the subquery.
+   */
+  private def padInSubquery(i: InSubquery): InSubquery = {
+    val rawTypes = i.values.zip(i.query.childOutputs).map {
+      case (AttrOrOuterRef(attr), col) => 
CharVarcharUtils.widerCharRawType(Seq(attr, col))
+      case _ => None
+    }
+    if (rawTypes.forall(_.isEmpty)) {
+      i
+    } else {
+      val newValues = i.values.zip(rawTypes).map {
+        case (e @ AttrOrOuterRef(attr), Some(rawType)) =>
+          CharVarcharUtils.padCharToWiderLength(attr, rawType).map {

Review Comment:
   Fixed. `padInSubquery` now pads through the same 
`addPaddingInStringComparison` as a comparison of two columns, with `alwaysPad 
= padCharCol`, so both sides are padded when read-side padding is off. New test 
`SPARK-61972: an IN subquery of char columns without read-side padding` 
(`FileSourceCharVarcharTestSuite`): external CHAR(3) and CHAR(5) tables over 
the same unpadded 'a', with `spark.sql.readSideCharPadding=false`, in both 
directions.



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