mihailom-db commented on code in PR #46206:
URL: https://github.com/apache/spark/pull/46206#discussion_r1580521078


##########
sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala:
##########
@@ -608,6 +610,181 @@ class CollationStringExpressionsSuite
     assert(sql(query).schema.fields.head.dataType.sameType(StringType(0)))
   }
 
+  test("StringTrim* functions - unit tests for both paths (codegen and eval)") 
{
+    // Without trimString param.
+    checkEvaluation(StringTrim(Literal.create( "  asd  ", StringType(0))), 
"asd")
+    checkEvaluation(StringTrimLeft(Literal.create("  asd  ", StringType(0))), 
"asd  ")
+    checkEvaluation(StringTrimRight(Literal.create("  asd  ", StringType(0))), 
"  asd")
+
+    // With trimString param.
+    checkEvaluation(
+      StringTrim(Literal.create("  asd  ", StringType(0)), Literal.create(" ", 
StringType(0))),
+      "asd")
+    checkEvaluation(
+      StringTrimLeft(Literal.create("  asd  ", StringType(0)), 
Literal.create(" ", StringType(0))),
+      "asd  ")
+    checkEvaluation(
+      StringTrimRight(Literal.create("  asd  ", StringType(0)), 
Literal.create(" ", StringType(0))),
+      "  asd")
+
+    checkEvaluation(
+      StringTrim(Literal.create("xxasdxx", StringType(0)), Literal.create("x", 
StringType(0))),
+      "asd")
+    checkEvaluation(
+      StringTrimLeft(Literal.create("xxasdxx", StringType(0)), 
Literal.create("x", StringType(0))),
+      "asdxx")
+    checkEvaluation(
+      StringTrimRight(Literal.create("xxasdxx", StringType(0)), 
Literal.create("x", StringType(0))),
+      "xxasd")
+  }

Review Comment:
   I am not sure we need this test that much, when we have E2E, but if we 
intend to keep it, please use StringType(collation_name) as it makes it more 
readable for anyone who wants to review the code. Also extracting that name as 
a val collationName = "UTF8_BINARY" could be good.



-- 
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: reviews-unsubscr...@spark.apache.org

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


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

Reply via email to