Skip to content

Commit 8dcb6bf

Browse files
zhengruifengattilapiros
authored andcommitted
[SPARK-49775][SQL][TESTS] Make tests of INVALID_PARAMETER_VALUE.CHARSET 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]>
1 parent a47aeb8 commit 8dcb6bf

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharsetProvider.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
private[sql] object CharsetProvider {
2525

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

2929
def forName(
3030
charset: String,

sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ org.apache.spark.SparkIllegalArgumentException
842842
"sqlState" : "22023",
843843
"messageParameters" : {
844844
"charset" : "WINDOWS-1252",
845-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
845+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
846846
"functionName" : "`encode`",
847847
"parameter" : "`charset`"
848848
}
@@ -860,7 +860,7 @@ org.apache.spark.SparkIllegalArgumentException
860860
"sqlState" : "22023",
861861
"messageParameters" : {
862862
"charset" : "WINDOWS-1252",
863-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
863+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
864864
"functionName" : "`encode`",
865865
"parameter" : "`charset`"
866866
}
@@ -878,7 +878,7 @@ org.apache.spark.SparkIllegalArgumentException
878878
"sqlState" : "22023",
879879
"messageParameters" : {
880880
"charset" : "Windows-xxx",
881-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
881+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
882882
"functionName" : "`encode`",
883883
"parameter" : "`charset`"
884884
}
@@ -896,7 +896,7 @@ org.apache.spark.SparkIllegalArgumentException
896896
"sqlState" : "22023",
897897
"messageParameters" : {
898898
"charset" : "Windows-xxx",
899-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
899+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
900900
"functionName" : "`encode`",
901901
"parameter" : "`charset`"
902902
}
@@ -1140,7 +1140,7 @@ org.apache.spark.SparkIllegalArgumentException
11401140
"sqlState" : "22023",
11411141
"messageParameters" : {
11421142
"charset" : "Windows-xxx",
1143-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1143+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
11441144
"functionName" : "`decode`",
11451145
"parameter" : "`charset`"
11461146
}
@@ -1158,7 +1158,7 @@ org.apache.spark.SparkIllegalArgumentException
11581158
"sqlState" : "22023",
11591159
"messageParameters" : {
11601160
"charset" : "Windows-xxx",
1161-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1161+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
11621162
"functionName" : "`decode`",
11631163
"parameter" : "`charset`"
11641164
}
@@ -1208,7 +1208,7 @@ org.apache.spark.SparkIllegalArgumentException
12081208
"sqlState" : "22023",
12091209
"messageParameters" : {
12101210
"charset" : "WINDOWS-1252",
1211-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1211+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
12121212
"functionName" : "`decode`",
12131213
"parameter" : "`charset`"
12141214
}
@@ -1226,7 +1226,7 @@ org.apache.spark.SparkIllegalArgumentException
12261226
"sqlState" : "22023",
12271227
"messageParameters" : {
12281228
"charset" : "WINDOWS-1252",
1229-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1229+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
12301230
"functionName" : "`decode`",
12311231
"parameter" : "`charset`"
12321232
}

sql/core/src/test/resources/sql-tests/results/string-functions.sql.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ org.apache.spark.SparkIllegalArgumentException
778778
"sqlState" : "22023",
779779
"messageParameters" : {
780780
"charset" : "WINDOWS-1252",
781-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
781+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
782782
"functionName" : "`encode`",
783783
"parameter" : "`charset`"
784784
}
@@ -796,7 +796,7 @@ org.apache.spark.SparkIllegalArgumentException
796796
"sqlState" : "22023",
797797
"messageParameters" : {
798798
"charset" : "WINDOWS-1252",
799-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
799+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
800800
"functionName" : "`encode`",
801801
"parameter" : "`charset`"
802802
}
@@ -814,7 +814,7 @@ org.apache.spark.SparkIllegalArgumentException
814814
"sqlState" : "22023",
815815
"messageParameters" : {
816816
"charset" : "Windows-xxx",
817-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
817+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
818818
"functionName" : "`encode`",
819819
"parameter" : "`charset`"
820820
}
@@ -832,7 +832,7 @@ org.apache.spark.SparkIllegalArgumentException
832832
"sqlState" : "22023",
833833
"messageParameters" : {
834834
"charset" : "Windows-xxx",
835-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
835+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
836836
"functionName" : "`encode`",
837837
"parameter" : "`charset`"
838838
}
@@ -1076,7 +1076,7 @@ org.apache.spark.SparkIllegalArgumentException
10761076
"sqlState" : "22023",
10771077
"messageParameters" : {
10781078
"charset" : "Windows-xxx",
1079-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1079+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
10801080
"functionName" : "`decode`",
10811081
"parameter" : "`charset`"
10821082
}
@@ -1094,7 +1094,7 @@ org.apache.spark.SparkIllegalArgumentException
10941094
"sqlState" : "22023",
10951095
"messageParameters" : {
10961096
"charset" : "Windows-xxx",
1097-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1097+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
10981098
"functionName" : "`decode`",
10991099
"parameter" : "`charset`"
11001100
}
@@ -1144,7 +1144,7 @@ org.apache.spark.SparkIllegalArgumentException
11441144
"sqlState" : "22023",
11451145
"messageParameters" : {
11461146
"charset" : "WINDOWS-1252",
1147-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1147+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
11481148
"functionName" : "`decode`",
11491149
"parameter" : "`charset`"
11501150
}
@@ -1162,7 +1162,7 @@ org.apache.spark.SparkIllegalArgumentException
11621162
"sqlState" : "22023",
11631163
"messageParameters" : {
11641164
"charset" : "WINDOWS-1252",
1165-
"charsets" : "utf-8, utf-16be, iso-8859-1, utf-16le, utf-16, utf-32, us-ascii",
1165+
"charsets" : "iso-8859-1, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-8",
11661166
"functionName" : "`decode`",
11671167
"parameter" : "`charset`"
11681168
}

0 commit comments

Comments
 (0)