You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/01/14 10:28:07 UTC

[GitHub] [spark] yaooqinn opened a new pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

yaooqinn opened a new pull request #31181:
URL: https://github.com/apache/spark/pull/31181


   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   On the read-side, we should respect the original data instead of trimming it first.
   
   It brings extra overhead on the code-gen code side, trimming and padding for the same field, and it's also unnecessary and a bug
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   bugfix and perf regression
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   no
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   new tests


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557550574



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala
##########
@@ -666,6 +682,19 @@ class FileSourceCharVarcharTestSuite extends CharVarcharTestSuite with SharedSpa
       assert(rest.contains("CHAR(5)"))
     }
   }
+
+  test("SPARK-34114: should not trim right for read-side length check and char padding") {
+    Seq("char", "varchar").foreach { typ =>

Review comment:
       `type` is a scala keyword and can't be used as a variable name.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA removed a comment on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760116371


   **[Test build #134052 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134052/testReport)** for PR 31181 at commit [`81e5a13`](https://github.com/apache/spark/commit/81e5a13f60a460d7d8451d8fd39e651071014466).


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557551108



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -208,53 +209,60 @@ object CharVarcharUtils extends Logging {
     RaiseError(Literal(errMsg, StringType), StringType)
   }
 
-  private def stringLengthCheck(expr: Expression, dt: DataType): Expression = dt match {
-    case CharType(length) =>
-      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)
-
-    case VarcharType(length) =>
-      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,
+  private def stringLengthCheck(expr: Expression, dt: DataType, needTrim: Boolean): Expression = {
+    dt match {
+      case CharType(length) =>
+        val trimmed = if (needTrim) StringTrimRight(expr) else 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("varchar", length),
-          StringRPad(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.

Review comment:
       Do we have a JIRA for this TODO? Shall we make this as `IDed` TODO like `TODO(SPARK-XXX)`?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760170398


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/38638/
   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760637927


   thanks, merging to master/3.1!


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557855366



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -208,53 +209,60 @@ object CharVarcharUtils extends Logging {
     RaiseError(Literal(errMsg, StringType), StringType)
   }
 
-  private def stringLengthCheck(expr: Expression, dt: DataType): Expression = dt match {
-    case CharType(length) =>
-      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)
-
-    case VarcharType(length) =>
-      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,
+  private def stringLengthCheck(expr: Expression, dt: DataType, needTrim: Boolean): Expression = {
+    dt match {
+      case CharType(length) =>
+        val trimmed = if (needTrim) StringTrimRight(expr) else 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("varchar", length),
-          StringRPad(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.

Review comment:
       let's keep it as it's not added by this PR: https://github.com/apache/spark/pull/31181/files#diff-16753285e80505e04c445ea8ccee1dde7ae601ed7bae224e212d90d395f57928L225




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557549432



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala
##########
@@ -666,6 +682,19 @@ class FileSourceCharVarcharTestSuite extends CharVarcharTestSuite with SharedSpa
       assert(rest.contains("CHAR(5)"))
     }
   }
+
+  test("SPARK-34114: should not trim right for read-side length check and char padding") {
+    Seq("char", "varchar").foreach { typ =>

Review comment:
       `typ` -> `type`?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760316056


   cc @HyukjinKwon since this affects 3.1.1.


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760265864


   **[Test build #134052 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134052/testReport)** for PR 31181 at commit [`81e5a13`](https://github.com/apache/spark/commit/81e5a13f60a460d7d8451d8fd39e651071014466).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760276616


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/134052/
   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760170398






----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760116371


   **[Test build #134052 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134052/testReport)** for PR 31181 at commit [`81e5a13`](https://github.com/apache/spark/commit/81e5a13f60a460d7d8451d8fd39e651071014466).


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557857395



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -208,53 +209,60 @@ object CharVarcharUtils extends Logging {
     RaiseError(Literal(errMsg, StringType), StringType)
   }
 
-  private def stringLengthCheck(expr: Expression, dt: DataType): Expression = dt match {
-    case CharType(length) =>
-      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)
-
-    case VarcharType(length) =>
-      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,
+  private def stringLengthCheck(expr: Expression, dt: DataType, needTrim: Boolean): Expression = {
+    dt match {
+      case CharType(length) =>
+        val trimmed = if (needTrim) StringTrimRight(expr) else 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("varchar", length),
-          StringRPad(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.

Review comment:
       k that's fine. but let's add an ID-ed todo in general. That's the standard approach to make sure they are on track.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760137517


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/38638/
   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557381230



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -208,53 +209,56 @@ object CharVarcharUtils extends Logging {
     RaiseError(Literal(errMsg, StringType), StringType)
   }
 
-  private def stringLengthCheck(expr: Expression, dt: DataType): Expression = dt match {
-    case CharType(length) =>
-      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)
-
-    case VarcharType(length) =>
-      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,
+  private def stringLengthCheck(expr: Expression, dt: DataType, needTrim: Boolean): Expression = {
+    dt match {
+      case CharType(length) =>
+        val trimmed = if (needTrim) StringTrimRight(expr) else 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("varchar", length),
-          StringRPad(trimmed, Literal(length))))
-
-    case StructType(fields) =>
-      val struct = CreateNamedStruct(fields.zipWithIndex.flatMap { case (f, i) =>
-        Seq(Literal(f.name), stringLengthCheck(GetStructField(expr, i, Some(f.name)), f.dataType))
-      })
-      if (expr.nullable) {
-        If(IsNull(expr), Literal(null, struct.dataType), struct)
-      } else {
-        struct
-      }
+          raiseError("char", length),
+          trimmed)
+
+      case VarcharType(length) =>
+        val trimmed = if (needTrim) StringTrimRight(expr) else 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(

Review comment:
       we don't need 2 `If` if we don't need to trim.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760282039


   **[Test build #134056 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/134056/testReport)** for PR 31181 at commit [`8773e66`](https://github.com/apache/spark/commit/8773e669ddaf08f918ebf9dc36226495366a71c5).


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760351538






----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yaooqinn commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
yaooqinn commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557485379



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -21,7 +21,7 @@ import scala.collection.mutable
 
 import org.apache.spark.internal.Logging
 import org.apache.spark.sql.AnalysisException
-import org.apache.spark.sql.catalyst.expressions._
+import org.apache.spark.sql.catalyst.expressions.{StringTrimRight, _}

Review comment:
       Not me, the IDE did 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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yaooqinn commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
yaooqinn commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557852898



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -208,53 +209,60 @@ object CharVarcharUtils extends Logging {
     RaiseError(Literal(errMsg, StringType), StringType)
   }
 
-  private def stringLengthCheck(expr: Expression, dt: DataType): Expression = dt match {
-    case CharType(length) =>
-      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)
-
-    case VarcharType(length) =>
-      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,
+  private def stringLengthCheck(expr: Expression, dt: DataType, needTrim: Boolean): Expression = {
+    dt match {
+      case CharType(length) =>
+        val trimmed = if (needTrim) StringTrimRight(expr) else 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("varchar", length),
-          StringRPad(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.

Review comment:
       In general, yes.
   
   We may keep improving here. @cloud-fan and I have considered more than 3 ways to simplify the logic here for performance improvement.
   
   This TODO may be invalid in this case, How about just rm it? WDYT? @cloud-fan @dongjoon-hyun 




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760151110


   Kubernetes integration test status success
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/38638/
   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760351534






----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan closed pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #31181:
URL: https://github.com/apache/spark/pull/31181


   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yaooqinn commented on pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
yaooqinn commented on pull request #31181:
URL: https://github.com/apache/spark/pull/31181#issuecomment-760168874


   cc @cloud-fan @maropu @HyukjinKwon @dongjoon-hyun, thanks for review


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557473916



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -21,7 +21,7 @@ import scala.collection.mutable
 
 import org.apache.spark.internal.Logging
 import org.apache.spark.sql.AnalysisException
-import org.apache.spark.sql.catalyst.expressions._
+import org.apache.spark.sql.catalyst.expressions.{StringTrimRight, _}

Review comment:
       why change the import?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yaooqinn commented on a change in pull request #31181: [SPARK-34114][SQL] should not trim right for read-side char length check and padding

Posted by GitBox <gi...@apache.org>.
yaooqinn commented on a change in pull request #31181:
URL: https://github.com/apache/spark/pull/31181#discussion_r557852898



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -208,53 +209,60 @@ object CharVarcharUtils extends Logging {
     RaiseError(Literal(errMsg, StringType), StringType)
   }
 
-  private def stringLengthCheck(expr: Expression, dt: DataType): Expression = dt match {
-    case CharType(length) =>
-      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)
-
-    case VarcharType(length) =>
-      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,
+  private def stringLengthCheck(expr: Expression, dt: DataType, needTrim: Boolean): Expression = {
+    dt match {
+      case CharType(length) =>
+        val trimmed = if (needTrim) StringTrimRight(expr) else 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("varchar", length),
-          StringRPad(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.

Review comment:
       In general, yes.
   
   We may keep improving here. @cloud-fan and I have considered more than 3 ways to simplify the logic here for performance improvement.
   
   This TODO may be invalid now, How about just rm it? WDYT? @cloud-fan @dongjoon-hyun 




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org