uros-db commented on code in PR #47620:
URL: https://github.com/apache/spark/pull/47620#discussion_r1713251635
##########
sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala:
##########
@@ -17,135 +17,130 @@
package org.apache.spark.sql
-import org.apache.spark.{SparkConf, SparkIllegalArgumentException}
-import org.apache.spark.sql.catalyst.expressions.{ExpressionEvalHelper,
Literal, StringTrim, StringTrimLeft, StringTrimRight}
-import org.apache.spark.sql.catalyst.util.CollationFactory
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession
-import org.apache.spark.sql.types.{ArrayType, BinaryType, BooleanType,
DataType, IntegerType, StringType}
+import org.apache.spark.sql.types._
// scalastyle:off nonascii
class CollationStringExpressionsSuite
extends QueryTest
with SharedSparkSession
with ExpressionEvalHelper {
- test("Support ConcatWs string expression with collation") {
- // Supported collations
- case class ConcatWsTestCase[R](s: String, a: Array[String], c: String,
result: R)
+ test("Support `ConcatWs` string expression with collation") {
+ case class ConcatWsTestCase[R](
+ sep: String,
+ arrayStr: Array[String],
+ collation: String,
+ result: R)
val testCases = Seq(
ConcatWsTestCase(" ", Array("Spark", "SQL"), "UTF8_BINARY", "Spark SQL"),
ConcatWsTestCase(" ", Array("Spark", "SQL"), "UTF8_LCASE", "Spark SQL"),
ConcatWsTestCase(" ", Array("Spark", "SQL"), "UNICODE", "Spark SQL"),
ConcatWsTestCase(" ", Array("Spark", "SQL"), "UNICODE_CI", "Spark SQL")
)
testCases.foreach(t => {
- val arrCollated = t.a.map(s => s"collate('$s', '${t.c}')").mkString(", ")
- var query = s"SELECT concat_ws(collate('${t.s}', '${t.c}'),
$arrCollated)"
- // Result & data type
- checkAnswer(sql(query), Row(t.result))
- assert(sql(query).schema.fields.head.dataType.sameType(StringType(t.c)))
- // Implicit casting
- val arr = t.a.map(s => s"'$s'").mkString(", ")
- query = s"SELECT concat_ws(collate('${t.s}', '${t.c}'), $arr)"
- checkAnswer(sql(query), Row(t.result))
- assert(sql(query).schema.fields.head.dataType.sameType(StringType(t.c)))
- query = s"SELECT concat_ws('${t.s}', $arrCollated)"
- checkAnswer(sql(query), Row(t.result))
- assert(sql(query).schema.fields.head.dataType.sameType(StringType(t.c)))
+ // Unit test.
+ val inputExprs = t.arrayStr.map {
+ case null => Literal.create(null, StringType(t.collation))
+ case s: String => Literal.create(s, StringType(t.collation))
+ }
+ val sepExpr = Literal.create(t.sep, StringType(t.collation))
+ checkEvaluation(ConcatWs(sepExpr +: inputExprs.toIndexedSeq), t.result)
+ // E2E SQL test.
+ withSQLConf(SQLConf.DEFAULT_COLLATION.key -> t.collation) {
+ val array = t.arrayStr.map(s => s"'$s'").mkString(", ")
+ val query = s"select concat_ws('${t.sep}', $array)"
+ checkAnswer(sql(query), Row(t.result))
+
assert(sql(query).schema.fields.head.dataType.sameType(StringType(t.collation)))
Review Comment:
It was already done like this in the current, and many other test suites, so
I'm not inclined to change it
These lines are rather simple, so I think repeating 1 line instead of 2
lines across the suite is not going to help a lot, also - having to jump to a
single private helper method in all tests may negatively impact debugging
--
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]