Skip to content

Commit

Permalink
[SPARK-48923][SQL][TESTS] Fix the incorrect logic of `CollationFactor…
Browse files Browse the repository at this point in the history
…ySuite`

### What changes were proposed in this pull request?
The pr aims to fix the incorrect logic of `CollationFactorySuite`.

### Why are the changes needed?
Only fix `CollationFactorySuite`.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Update existed UT.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#47382 from panbingkun/fix_CollationFactorySuite.

Authored-by: panbingkun <panbingkun@baidu.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
  • Loading branch information
panbingkun authored and cloud-fan committed Jul 17, 2024
1 parent 41a2beb commit 74ca836
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ class CollationFactorySuite extends AnyFunSuite with Matchers { // scalastyle:ig
("UNICODE_INDETERMINATE", "UNICODE"),
("UNICODE_CI_INDETERMINATE", "UNICODE")
).foreach{case (collationName, proposals) =>
val error = intercept[SparkException] { fetchCollation(collationName) }
assert(error.getErrorClass === "COLLATION_INVALID_NAME")
assert(error.getMessageParameters.asScala === Map(
"collationName" -> collationName, "proposals" -> proposals))
checkCollationNameError(collationName, proposals)
}
}

Expand Down Expand Up @@ -154,8 +151,8 @@ class CollationFactorySuite extends AnyFunSuite with Matchers { // scalastyle:ig
testCase.expectedResult)

val hash1 = collation.hashFunction.applyAsLong(toUTF8(testCase.s1))
val hash2 = collation.hashFunction.applyAsLong(toUTF8(testCase.s1))
assert(hash1 == hash2)
val hash2 = collation.hashFunction.applyAsLong(toUTF8(testCase.s2))
assert((hash1 == hash2) == testCase.expectedResult)
})
}

Expand Down Expand Up @@ -316,13 +313,9 @@ class CollationFactorySuite extends AnyFunSuite with Matchers { // scalastyle:ig
// no locale specified
("_CI_AI", "af_CI_AI, am_CI_AI, ar_CI_AI"),
("", "af, am, ar")
).foreach { case (collationName, proposals) => {
val error = intercept[SparkException] { fetchCollation(collationName) }
assert(error.getErrorClass === "COLLATION_INVALID_NAME")

assert(error.getMessageParameters.asScala === Map(
"collationName" -> collationName, "proposals" -> proposals))
}}
).foreach { case (collationName, proposals) =>
checkCollationNameError(collationName, proposals)
}
}

test("collations name normalization for ICU non-root localization") {
Expand Down Expand Up @@ -427,13 +420,7 @@ class CollationFactorySuite extends AnyFunSuite with Matchers { // scalastyle:ig
("UNICODECSAS", "UNICODE"),
("_CS_AS_UNICODE", "UNICODE")
).foreach { case (collationName, proposals) =>
val error = intercept[SparkException] {
fetchCollation(collationName)
}

assert(error.getErrorClass === "COLLATION_INVALID_NAME")
assert(error.getMessageParameters.asScala === Map(
"collationName" -> collationName, "proposals" -> proposals))
checkCollationNameError(collationName, proposals)
}
}

Expand Down Expand Up @@ -465,4 +452,13 @@ class CollationFactorySuite extends AnyFunSuite with Matchers { // scalastyle:ig
assert(Integer.signum(result) == testCase.expectedResult)
})
}

private def checkCollationNameError(collationName: String, proposals: String): Unit = {
val e = intercept[SparkException] {
fetchCollation(collationName)
}
assert(e.getErrorClass === "COLLATION_INVALID_NAME")
assert(e.getMessageParameters.asScala === Map(
"collationName" -> collationName, "proposals" -> proposals))
}
}

0 comments on commit 74ca836

Please sign in to comment.