MaxGekk commented on code in PR #48608:
URL: https://github.com/apache/spark/pull/48608#discussion_r1817716453
##########
sql/core/src/test/scala/org/apache/spark/sql/CollationSQLExpressionsSuite.scala:
##########
@@ -2434,829 +2447,799 @@ class CollationSQLExpressionsSuite
)
}
- test("min_by supports collation") {
- val collation = "UNICODE"
- val query = s"SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c',
20) AS tab(x, y);"
+ // common method for subsequent tests verifying various SQL expressions with
collations
+ private def testCollationSqlExpressionCommon(
+ query: String,
+ collation: String,
+ result: Seq[Row],
+ expectedTypes: Seq[DataType]): Unit = {
withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collation) {
- checkAnswer(
- sql(query),
- Seq(
+ // check result correctness
+ checkAnswer(sql(query), result)
+ // check result row data types
+ for (i <- 0 until expectedTypes.length)
+ assert(sql(query).schema(i).dataType == expectedTypes(i))
+ }
+ }
+
+ test("min_by supports collation") {
+ testAdditionalCollations.foreach { collation =>
+ testCollationSqlExpressionCommon(
+ query = "SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c',
20) AS tab(x, y);",
+ collation,
+ result = Seq(
Row("a")
+ ),
+ expectedTypes = Seq(
+ StringType(collation)
)
)
- // check result row data type
- val dataType = StringType(collation)
- assert(sql(query).schema.head.dataType == dataType)
}
}
Review Comment:
Let's simplify the common use-case, and add an overloaded versions
`testCollationSqlExpressionCommon`:
```scala
private def testCollationSqlExpressionCommon(
query: String,
collation: String,
result: Row,
expectedType: DataType): Unit = {
testCollationSqlExpressionCommon(query, collation, Seq(result),
Seq(expectedType))
}
```
like
```scala
test("min_by supports collation") {
testAdditionalCollations.foreach { collation =>
testCollationSqlExpressionCommon(
query = "SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c',
20) AS tab(x, y);",
collation,
result = Row("a"),
expectedType = StringType(collation)
)
}
}
```
##########
sql/core/src/test/scala/org/apache/spark/sql/CollationSQLExpressionsSuite.scala:
##########
@@ -2434,829 +2447,799 @@ class CollationSQLExpressionsSuite
)
}
- test("min_by supports collation") {
- val collation = "UNICODE"
- val query = s"SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c',
20) AS tab(x, y);"
+ // common method for subsequent tests verifying various SQL expressions with
collations
+ private def testCollationSqlExpressionCommon(
+ query: String,
+ collation: String,
+ result: Seq[Row],
+ expectedTypes: Seq[DataType]): Unit = {
withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collation) {
- checkAnswer(
- sql(query),
- Seq(
+ // check result correctness
+ checkAnswer(sql(query), result)
+ // check result row data types
+ for (i <- 0 until expectedTypes.length)
+ assert(sql(query).schema(i).dataType == expectedTypes(i))
+ }
+ }
+
+ test("min_by supports collation") {
+ testAdditionalCollations.foreach { collation =>
+ testCollationSqlExpressionCommon(
+ query = "SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c',
20) AS tab(x, y);",
+ collation,
+ result = Seq(
Row("a")
+ ),
+ expectedTypes = Seq(
+ StringType(collation)
)
)
- // check result row data type
- val dataType = StringType(collation)
- assert(sql(query).schema.head.dataType == dataType)
}
}
test("max_by supports collation") {
- val collation = "UNICODE"
- val query = s"SELECT max_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c',
20) AS tab(x, y);"
- withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collation) {
- checkAnswer(
- sql(query),
- Seq(
+ testAdditionalCollations.foreach { collation =>
+ testCollationSqlExpressionCommon(
+ query = "SELECT max_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c',
20) AS tab(x, y);",
+ collation,
+ result = Seq(
Row("b")
+ ),
+ expectedTypes = Seq(
+ StringType(collation)
)
)
- // check result row data type
- val dataType = StringType(collation)
- assert(sql(query).schema.head.dataType == dataType)
}
}
test("array supports collation") {
- val collation = "UNICODE"
- val query = s"SELECT array('a', 'b', 'c');"
- withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collation) {
- checkAnswer(
- sql(query),
- Seq(
+ testAdditionalCollations.foreach { collation =>
+ testCollationSqlExpressionCommon(
+ query = "SELECT array('a', 'b', 'c');",
Review Comment:
; at the end is not needed:
```suggestion
query = "SELECT array('a', 'b', 'c')",
```
--
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]