uros-db commented on code in PR #46404:
URL: https://github.com/apache/spark/pull/46404#discussion_r1592826648


##########
sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala:
##########
@@ -800,6 +804,61 @@ class CollationStringExpressionsSuite
     assert(collationMismatch.getErrorClass === "COLLATION_MISMATCH.EXPLICIT")
   }
 
+  test("Support mode for string expression with collation") {
+    val query = "SELECT mode(collate('abc', 'utf8_binary'))"
+    checkAnswer(sql(query), Row("abc"))
+    
assert(sql(query).schema.fields.head.dataType.sameType(StringType("utf8_binary")))
+  }
+
+  test("Support mode for string expression with collation ID on table") {
+    withTable("t") {
+      sql("CREATE TABLE t(i STRING) USING parquet")
+      sql("INSERT INTO t VALUES " +
+        "('a'), ('a'), ('a'), ('a'), ('a'), " +
+        "('b'), ('b'), ('b'), " +
+        "('B'), ('B'), ('B'), ('B')")
+      val query = "SELECT mode(collate(i, 'UTF8_BINARY_LCASE')) FROM t"
+      checkAnswer(sql(query), Row("b"))
+    }
+  }
+
+  test("Support mode for string expression with collation ID") {
+    val query = "SELECT mode(collate('lorem epsum', 'UTF8_BINARY_LCASE'))"
+    checkAnswer(sql(query), Row("lorem epsum"))
+    
assert(sql(query).schema.fields.head.dataType.sameType(StringType("UTF8_BINARY_LCASE")))
+  }
+
+  test("Support Mode.eval(buffer)") {
+    val myMode = Mode(child = Literal("some_column_name"), collationEnabled = 
true)
+    val buffer = new OpenHashMap[AnyRef, Long](5)
+    buffer.update("b", 1L)
+    buffer.update("B", 1L)
+    buffer.update("c", 1L)
+    buffer.update("d", 1L)
+    buffer.update("a", 2L)
+    assert(myMode.eval(buffer).toString == "a")
+    val buffer2 = new OpenHashMap[AnyRef, Long](5)
+    buffer2.update(UTF8String.fromString("b"), 1L)
+    buffer2.update(UTF8String.fromString("B"), 1L)
+    buffer2.update(UTF8String.fromString("c"), 1L)
+    buffer2.update(UTF8String.fromString("d"), 1L)
+    buffer2.update(UTF8String.fromString("a"), 2L)
+    assert(myMode.eval(buffer2).toString == "a")
+  }
+
+  test("Support Mode.eval(buffer) with non-default collation") {
+    val myMode = Mode(
+      child = Literal.create("some_column_name", 
StringType("utf8_binary_lcase")),
+      collationEnabled = true)
+    val buffer = new OpenHashMap[AnyRef, Long](11)
+    buffer.update("b", 2L)
+    buffer.update("B", 2L)
+    buffer.update("c", 2L)
+    buffer.update("d", 2L)
+    buffer.update("a", 3L)
+    assert(myMode.eval(buffer).toString == "B")
+  }

Review Comment:
   these two tests can also be combined using testCases -> foreach...



-- 
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]

Reply via email to