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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala:
##########
@@ -2213,8 +2213,8 @@ case class Levenshtein(
   }
 
   override def inputTypes: Seq[AbstractDataType] = threshold match {
-    case Some(_) => Seq(StringType, StringType, IntegerType)
-    case _ => Seq(StringType, StringType)
+    case Some(_) => Seq(StringTypeAnyCollation, StringTypeAnyCollation, 
IntegerType)
+    case _ => Seq(StringTypeAnyCollation, StringTypeAnyCollation)

Review Comment:
   Maybe we should special case this in CollationTypeCasts. We do not want to 
have an expression on the place of third parameter with StringType and take it 
into account, as it will explicitly be casted to Integer, and technically it's 
collation should not be counted. Something similar to If expression that is 
special cased.  



##########
sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala:
##########
@@ -89,6 +89,73 @@ class CollationStringExpressionsSuite
     testRepeat("UNICODE_CI", 3, "abc", 2)
   }
 
+  test("Levenshtein expressions with collation") {
+    def prepareLevenshtein(
+        left: String,
+        right: String,
+        collation: String): Levenshtein = {
+      val collationId = CollationFactory.collationNameToId(collation)
+      val leftLit = Literal.create(left, StringType(collationId))
+      val rightLit = Literal.create(right, StringType(collationId))
+      Levenshtein(leftLit, rightLit)
+    }
+
+    Seq(
+      // scalastyle:off nonascii
+      CollationTestCase("", "", "UTF8_BINARY", 0),
+      CollationTestCase("", "something", "UTF8_BINARY", 9),
+      CollationTestCase("a", "a", "UTF8_BINARY", 0),
+      CollationTestCase("a", "A", "UTF8_BINARY", 1),
+      CollationTestCase("a", "a", "UTF8_BINARY_LCASE", 0),
+      CollationTestCase("a", "A", "UTF8_BINARY_LCASE", 0),
+      CollationTestCase("bd", "ABc", "UTF8_BINARY_LCASE", 2),
+      CollationTestCase("Xü", "Ü", "UTF8_BINARY_LCASE", 1),
+      CollationTestCase("Xũ", "Üx", "UTF8_BINARY_LCASE", 2),
+      CollationTestCase("", "something", "UTF8_BINARY_LCASE", 9),
+      CollationTestCase("sOmeThINg", "SOMETHING", "UTF8_BINARY_LCASE", 0),
+      CollationTestCase("sOmeThINg", "SOMETHING", "UNICODE", 5),
+      CollationTestCase("sOmeThINg", "SOMETHING", "UNICODE_CI", 0)
+      // scalastyle:on nonascii
+    ).foreach(c => checkEvaluation(prepareLevenshtein(c.s1, c.s2, 
c.collation), c.expectedResult))
+  }
+

Review Comment:
   @cloud-fan Should we also add a test to CollationSuite Implicit casting to 
check if casting actually works for this expression?



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