nikolamand-db commented on code in PR #45963:
URL: https://github.com/apache/spark/pull/45963#discussion_r1559431415
##########
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
Review Comment:
Wrapped the class with `scalastyle:off nonascii`.
##########
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:
Added the tests to CollationSuite, please check.
##########
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:
Added special case for Levenshtein to `CollationTypeCasts`, please check.
--
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]