Skip to content

Commit

Permalink
[SPARK-49775][SQL][TESTS] Make tests of `INVALID_PARAMETER_VALUE.CHAR…
Browse files Browse the repository at this point in the history
…SET` deterministic

### What changes were proposed in this pull request?
Make tests of `INVALID_PARAMETER_VALUE.CHARSET` deterministic

### Why are the changes needed?
`VALID_CHARSETS` is a Set, so `VALID_CHARSETS.mkString(", ")` is non-deterministic, and cause failures in different testing environments, e.g.
```
        org.scalatest.exceptions.TestFailedException: ansi/string-functions.sql
Expected "...sets" : "UTF-16LE, U[TF-8, UTF-32, UTF-16BE, UTF-16, US-ASCII, ISO-8859-1]",
    "functionName...", but got "...sets" : "UTF-16LE, U[S-ASCII, ISO-8859-1, UTF-8, UTF-32, UTF-16BE, UTF-16]",
    "functionName..." Result did not match for query apache#93
select encode('hello', 'WINDOWS-1252')
      at org.scalatest.Assertions.newAssertionFailedException(Assertions.scala:472)
      at org.scalatest.Assertions.newAssertionFailedException$(Assertions.scala:471)
      at org.scalatest.funsuite.AnyFunSuite.newAssertionFailedException(AnyFunSuite.scala:1564)
      at org.scalatest.Assertions.assertResult(Assertions.scala:847)
      at org.scalatest.Assertions.assertResult$(Assertions.scala:842)
      at org.scalatest.funsuite.AnyFunSuite.assertResult(AnyFunSuite.scala:1564)

```

### Does this PR introduce _any_ user-facing change?
No, test only

### How was this patch tested?
updated tests

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

Closes apache#48235 from zhengruifeng/sql_test_sort_charset.

Authored-by: Ruifeng Zheng <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
  • Loading branch information
zhengruifeng authored and attilapiros committed Oct 4, 2024
1 parent a47aeb8 commit 8dcb6bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
private[sql] object CharsetProvider {

final lazy val VALID_CHARSETS =
Set("us-ascii", "iso-8859-1", "utf-8", "utf-16be", "utf-16le", "utf-16", "utf-32")
Array("us-ascii", "iso-8859-1", "utf-8", "utf-16be", "utf-16le", "utf-16", "utf-32").sorted

def forName(
charset: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand All @@ -860,7 +860,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand All @@ -878,7 +878,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand All @@ -896,7 +896,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand Down Expand Up @@ -1140,7 +1140,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand All @@ -1158,7 +1158,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand Down Expand Up @@ -1208,7 +1208,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand All @@ -1226,7 +1226,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand All @@ -796,7 +796,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand All @@ -814,7 +814,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand All @@ -832,7 +832,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`encode`",
"parameter" : "`charset`"
}
Expand Down Expand Up @@ -1076,7 +1076,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand All @@ -1094,7 +1094,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "Windows-xxx",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand All @@ -1162,7 +1162,7 @@ org.apache.spark.SparkIllegalArgumentException
"sqlState" : "22023",
"messageParameters" : {
"charset" : "WINDOWS-1252",
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
"functionName" : "`decode`",
"parameter" : "`charset`"
}
Expand Down

0 comments on commit 8dcb6bf

Please sign in to comment.