uros-db commented on code in PR #45643: URL: https://github.com/apache/spark/pull/45643#discussion_r1565492245
########## sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala: ########## @@ -96,6 +95,107 @@ class CollationStringExpressionsSuite assert(collationMismatch.getErrorClass === "COLLATION_MISMATCH.EXPLICIT") } + test("INSTR check result on explicitly collated strings") { + def testInStr(str: String, substr: String, collationId: Integer, expected: Integer): Unit = { + val string = Literal.create(str, StringType(collationId)) + val substring = Literal.create(substr, StringType(collationId)) + + checkEvaluation(StringInstr(string, substring), expected) + } + + var collationId = CollationFactory.collationNameToId("UTF8_BINARY") + testInStr("aaads", "Aa", collationId, 0) + testInStr("aaaDs", "de", collationId, 0) + testInStr("aaads", "ds", collationId, 4) + testInStr("xxxx", "", collationId, 1) + testInStr("", "xxxx", collationId, 0) + // scalastyle:off + testInStr("test大千世界X大千世界", "大千", collationId, 5) + testInStr("test大千世界X大千世界", "界X", collationId, 8) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UTF8_BINARY_LCASE") + testInStr("aaads", "Aa", collationId, 1) + testInStr("aaaDs", "de", collationId, 0) + testInStr("aaaDs", "ds", collationId, 4) + testInStr("xxxx", "", collationId, 1) + testInStr("", "xxxx", collationId, 0) + // scalastyle:off + testInStr("test大千世界X大千世界", "大千", collationId, 5) + testInStr("test大千世界X大千世界", "界x", collationId, 8) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UNICODE") + testInStr("aaads", "Aa", collationId, 0) + testInStr("aaads", "aa", collationId, 1) + testInStr("aaads", "de", collationId, 0) + testInStr("xxxx", "", collationId, 1) + testInStr("", "xxxx", collationId, 0) + // scalastyle:off + testInStr("test大千世界X大千世界", "界x", collationId, 0) + testInStr("test大千世界X大千世界", "界X", collationId, 8) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UNICODE_CI") + testInStr("aaads", "AD", collationId, 3) + testInStr("aaads", "dS", collationId, 4) + // scalastyle:off + testInStr("test大千世界X大千世界", "界x", collationId, 8) + // scalastyle:on Review Comment: unit tests should be moved to CollationSupportSuite.java, following the appropriate format please adjust your tests also, add appropriate sql tests to CollationStringExpressionsSuite.scala ########## sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala: ########## @@ -96,6 +95,107 @@ class CollationStringExpressionsSuite assert(collationMismatch.getErrorClass === "COLLATION_MISMATCH.EXPLICIT") } + test("INSTR check result on explicitly collated strings") { + def testInStr(str: String, substr: String, collationId: Integer, expected: Integer): Unit = { + val string = Literal.create(str, StringType(collationId)) + val substring = Literal.create(substr, StringType(collationId)) + + checkEvaluation(StringInstr(string, substring), expected) + } + + var collationId = CollationFactory.collationNameToId("UTF8_BINARY") + testInStr("aaads", "Aa", collationId, 0) + testInStr("aaaDs", "de", collationId, 0) + testInStr("aaads", "ds", collationId, 4) + testInStr("xxxx", "", collationId, 1) + testInStr("", "xxxx", collationId, 0) + // scalastyle:off + testInStr("test大千世界X大千世界", "大千", collationId, 5) + testInStr("test大千世界X大千世界", "界X", collationId, 8) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UTF8_BINARY_LCASE") + testInStr("aaads", "Aa", collationId, 1) + testInStr("aaaDs", "de", collationId, 0) + testInStr("aaaDs", "ds", collationId, 4) + testInStr("xxxx", "", collationId, 1) + testInStr("", "xxxx", collationId, 0) + // scalastyle:off + testInStr("test大千世界X大千世界", "大千", collationId, 5) + testInStr("test大千世界X大千世界", "界x", collationId, 8) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UNICODE") + testInStr("aaads", "Aa", collationId, 0) + testInStr("aaads", "aa", collationId, 1) + testInStr("aaads", "de", collationId, 0) + testInStr("xxxx", "", collationId, 1) + testInStr("", "xxxx", collationId, 0) + // scalastyle:off + testInStr("test大千世界X大千世界", "界x", collationId, 0) + testInStr("test大千世界X大千世界", "界X", collationId, 8) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UNICODE_CI") + testInStr("aaads", "AD", collationId, 3) + testInStr("aaads", "dS", collationId, 4) + // scalastyle:off + testInStr("test大千世界X大千世界", "界x", collationId, 8) + // scalastyle:on + } + + test("FIND_IN_SET check result on explicitly collated strings") { + def testFindInSet(word: String, set: String, collationId: Integer, expected: Integer): Unit = { + val w = Literal.create(word, StringType(collationId)) + val s = Literal.create(set, StringType(collationId)) + + checkEvaluation(FindInSet(w, s), expected) + } + + var collationId = CollationFactory.collationNameToId("UTF8_BINARY") + testFindInSet("AB", "abc,b,ab,c,def", collationId, 0) + testFindInSet("abc", "abc,b,ab,c,def", collationId, 1) + testFindInSet("def", "abc,b,ab,c,def", collationId, 5) + testFindInSet("d,ef", "abc,b,ab,c,def", collationId, 0) + testFindInSet("", "abc,b,ab,c,def", collationId, 0) + + collationId = CollationFactory.collationNameToId("UTF8_BINARY_LCASE") + testFindInSet("a", "abc,b,ab,c,def", collationId, 0) + testFindInSet("c", "abc,b,ab,c,def", collationId, 4) + testFindInSet("AB", "abc,b,ab,c,def", collationId, 3) + testFindInSet("AbC", "abc,b,ab,c,def", collationId, 1) + testFindInSet("abcd", "abc,b,ab,c,def", collationId, 0) + testFindInSet("d,ef", "abc,b,ab,c,def", collationId, 0) + testFindInSet("XX", "xx", collationId, 1) + testFindInSet("", "abc,b,ab,c,def", collationId, 0) + // scalastyle:off + testFindInSet("界x", "test,大千,世,界X,大,千,世界", collationId, 4) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UNICODE") + testFindInSet("a", "abc,b,ab,c,def", collationId, 0) + testFindInSet("ab", "abc,b,ab,c,def", collationId, 3) + testFindInSet("Ab", "abc,b,ab,c,def", collationId, 0) + testFindInSet("d,ef", "abc,b,ab,c,def", collationId, 0) + testFindInSet("xx", "xx", collationId, 1) + // scalastyle:off + testFindInSet("界x", "test,大千,世,界X,大,千,世界", collationId, 0) + testFindInSet("大", "test,大千,世,界X,大,千,世界", collationId, 5) + // scalastyle:on + + collationId = CollationFactory.collationNameToId("UNICODE_CI") + testFindInSet("a", "abc,b,ab,c,def", collationId, 0) + testFindInSet("C", "abc,b,ab,c,def", collationId, 4) + testFindInSet("DeF", "abc,b,ab,c,dEf", collationId, 5) + testFindInSet("DEFG", "abc,b,ab,c,def", collationId, 0) + testFindInSet("XX", "xx", collationId, 1) + // scalastyle:off + testFindInSet("界x", "test,大千,世,界X,大,千,世界", collationId, 4) + testFindInSet("界x", "test,大千,界Xx,世,界X,大,千,世界", collationId, 5) + testFindInSet("大", "test,大千,世,界X,大,千,世界", collationId, 5) + // scalastyle:on Review Comment: unit tests should be moved to CollationSupportSuite.java, following the appropriate format please adjust your tests also, add appropriate sql tests to CollationStringExpressionsSuite.scala -- 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