Skip to content

Commit cbf96df

Browse files
committed
more tests
1 parent 935aec6 commit cbf96df

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

spark/src/test/scala/org/apache/comet/CometCodegenDispatchSmokeSuite.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,19 @@ class CometCodegenDispatchSmokeSuite extends CometTestBase with AdaptiveSparkPla
575575
}
576576
}
577577

578+
test("ScalaUDF on BinaryType (VarBinaryVector, getBinary)") {
579+
// Binary input getter path: VarBinaryVector with byte[] reads via Spark's `getBinary` getter.
580+
spark.udf.register("blen", (b: Array[Byte]) => if (b == null) -1 else b.length)
581+
withTable("t") {
582+
sql("CREATE TABLE t (b BINARY) USING parquet")
583+
sql("INSERT INTO t VALUES (CAST('abc' AS BINARY)), (CAST('hello' AS BINARY)), (NULL)")
584+
assertCodegenDidWork {
585+
checkSparkAnswerAndOperator(sql("SELECT blen(b) FROM t"))
586+
}
587+
assertKernelSignaturePresent(Seq(classOf[VarBinaryVector]), IntegerType)
588+
}
589+
}
590+
578591
test("ScalaUDF returning ArrayType(StringType) (ListVector output writer)") {
579592
// First use of the ArrayType output path end-to-end. The UDF returns a `Seq[String]`,
580593
// which Spark encodes as `ArrayType(StringType, containsNull = true)`. The dispatcher's
@@ -937,6 +950,23 @@ class CometCodegenDispatchSmokeSuite extends CometTestBase with AdaptiveSparkPla
937950
}
938951
}
939952

953+
test("ScalaUDF round-trips Map<Int, Int> (primitive key and value)") {
954+
// Map with non-string keys: exercises the primitive-key element getter on the input side
955+
// and the corresponding writer on the output side. Spark's encoder for `Map[Int, Int]` calls
956+
// `getInt(0)` / `getInt(1)` on the entries struct, hitting the kernel's typed scalar getter
957+
// for each side rather than the UTF8 path.
958+
spark.udf.register(
959+
"incValues",
960+
(m: Map[Int, Int]) => if (m == null) null else m.map { case (k, v) => k -> (v + 1) })
961+
withTable("t") {
962+
sql("CREATE TABLE t (m MAP<INT, INT>) USING parquet")
963+
sql("INSERT INTO t VALUES (map(1, 10, 2, 20)), (map()), (null)")
964+
assertCodegenDidWork {
965+
checkSparkAnswerAndOperator(sql("SELECT incValues(m) FROM t"))
966+
}
967+
}
968+
}
969+
940970
test("ScalaUDF returning Map<String, Int>") {
941971
spark.udf.register(
942972
"singletonMap",

0 commit comments

Comments
 (0)