yaooqinn commented on a change in pull request #31199:
URL: https://github.com/apache/spark/pull/31199#discussion_r559286164



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -200,69 +212,60 @@ object CharVarcharUtils extends Logging {
    */
   def stringLengthCheck(expr: Expression, targetAttr: Attribute): Expression = 
{
     getRawType(targetAttr.metadata).map { rawType =>
-      stringLengthCheck(expr, rawType, needTrim = true)
+      stringLengthCheck(expr, rawType)
     }.getOrElse(expr)
   }
 
   private def raiseError(typeName: String, length: Int): Expression = {
     val errMsg = UTF8String.fromString(s"Exceeds $typeName type length 
limitation: $length")
-    RaiseError(Literal(errMsg, StringType), StringType)
+      RaiseError(Literal(errMsg, StringType), StringType)
   }
 
-  private def stringLengthCheck(expr: Expression, dt: DataType, needTrim: 
Boolean): Expression = {
+  private def stringLengthCheck(expr: Expression, dt: DataType): Expression = {
     dt match {
       case CharType(length) =>
-        val trimmed = if (needTrim) StringTrimRight(expr) else expr
+        val trimmed = StringTrimRight(expr)
         // Trailing spaces do not count in the length check. We don't need to 
retain the trailing
         // spaces, as we will pad char type columns/fields at read time.
-        If(
-          GreaterThan(Length(trimmed), Literal(length)),
-          raiseError("char", length),
-          trimmed)
+        If(GreaterThan(Length(trimmed), Literal(length)), raiseError("char", 
length), trimmed)
 
       case VarcharType(length) =>
-        if (needTrim) {
-          val trimmed = StringTrimRight(expr)
-          // Trailing spaces do not count in the length check. We need to 
retain the trailing spaces
-          // (truncate to length N), as there is no read-time padding for 
varchar type.
-          // TODO: create a special TrimRight function that can trim to a 
certain length.
-          If(
-            LessThanOrEqual(Length(expr), Literal(length)),
-            expr,
-            If(
-              GreaterThan(Length(trimmed), Literal(length)),
-              raiseError("varchar", length),
-              StringRPad(trimmed, Literal(length))))
-        } else {
-          If(GreaterThan(Length(expr), Literal(length)), raiseError("varchar", 
length), expr)
-        }
+        val trimmed = StringTrimRight(expr)

Review comment:
       >  I wasn't clear why that would mean read-side doesn't trim anymore.
   
   Looks like we have a misunderstanding here, we are not removing trim logic 
from the read-side in this PR, just the flag itself. The trim logic was removed 
in the previous PR https://github.com/apache/spark/pull/31181 as a bugfix.




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

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