uros-db commented on code in PR #47154: URL: https://github.com/apache/spark/pull/47154#discussion_r1700147650
########## sql/core/src/test/scala/org/apache/spark/sql/CollationSQLExpressionsSuite.scala: ########## @@ -1724,6 +1724,72 @@ class CollationSQLExpressionsSuite }) } + test("Support Mode.eval(buffer) with complex types") { + case class UTF8StringModeTestCase[R]( + collationId: String, + bufferValues: Map[InternalRow, Long], + result: R) + + val bufferValuesUTF8String: Map[Any, Long] = Map( + UTF8String.fromString("a") -> 5L, + UTF8String.fromString("b") -> 4L, + UTF8String.fromString("B") -> 3L, + UTF8String.fromString("d") -> 2L, + UTF8String.fromString("e") -> 1L) + + val bufferValuesComplex = bufferValuesUTF8String.map{ + case (k, v) => (InternalRow.fromSeq(Seq(k, k, k)), v) + } + val testCasesUTF8String = Seq( + UTF8StringModeTestCase("utf8_binary", bufferValuesComplex, "[a,a,a]"), + UTF8StringModeTestCase("UTF8_LCASE", bufferValuesComplex, "[b,b,b]"), + UTF8StringModeTestCase("unicode_ci", bufferValuesComplex, "[b,b,b]"), + UTF8StringModeTestCase("unicode", bufferValuesComplex, "[a,a,a]")) + + testCasesUTF8String.foreach(t => { + val buffer = new OpenHashMap[AnyRef, Long](5) + val myMode = Mode(child = Literal.create(null, StructType(Seq( + StructField("f1", StringType(t.collationId), true), + StructField("f2", StringType(t.collationId), true), + StructField("f3", StringType(t.collationId), true) + )))) + t.bufferValues.foreach { case (k, v) => buffer.update(k, v) } + assert(myMode.eval(buffer).toString.toLowerCase() == t.result.toLowerCase()) + }) + } +// +// test("Support Mode.eval(buffer) with complex map types") { +// case class UTF8StringModeTestCase[R]( +// collationId: String, +// bufferValues: Map[InternalRow, Long], +// result: R) +// +// val bufferValuesUTF8String: Map[Any, Long] = Map( +// UTF8String.fromString("a") -> 5L, +// UTF8String.fromString("b") -> 4L, +// UTF8String.fromString("B") -> 3L, +// UTF8String.fromString("d") -> 2L, +// UTF8String.fromString("e") -> 1L) +// +// val bufferValuesComplex = bufferValuesUTF8String.map{ +// case (k, v) => (InternalRow.apply(Map(k -> 1)), v) +// } +// val testCasesUTF8String = Seq( +// UTF8StringModeTestCase("utf8_binary", bufferValuesComplex, "[a,a,a]"), +// UTF8StringModeTestCase("UTF8_LCASE", bufferValuesComplex, "[b,b,b]"), +// UTF8StringModeTestCase("unicode_ci", bufferValuesComplex, "[b,b,b]"), +// UTF8StringModeTestCase("unicode", bufferValuesComplex, "[a,a,a]")) +// +// testCasesUTF8String.foreach(t => { +// val buffer = new OpenHashMap[AnyRef, Long](5) +// val myMode = Mode(child = Literal.create(null, StructType(Seq( +// StructField("f1", MapType(StringType(t.collationId), IntegerType), true) +// )))) +// t.bufferValues.foreach { case (k, v) => buffer.update(k, v) } +// assert(myMode.eval(buffer).toString.toLowerCase() == t.result.toLowerCase()) +// }) +// } Review Comment: do we want to delete or keep these tests? -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org