Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions spark/src/test/scala/org/apache/comet/CometCodegenFuzzSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,16 @@ class CometCodegenFuzzSuite
}
}

private def probeCardinality(accessor: String, viewName: String): Unit = {
private def probeCardinality(accessor: String, dt: DataType, viewName: String): Unit = {
// `Size` only supports `ArrayType` in Comet, so for `MapType` we route through `map_keys` to
// reach a `Size(ArrayType)`. Spark still calls `getMap` on the column vector to extract the
// keys, which is the accessor path this probe is intended to exercise.
val sizeExpr = dt match {
case _: MapType => s"size(map_keys($accessor))"
case _ => s"cardinality($accessor)"
}
assertCodegenRan {
checkSparkAnswerAndOperator(
s"SELECT $cardinalityProbeUdf(cardinality($accessor)) FROM $viewName")
checkSparkAnswerAndOperator(s"SELECT $cardinalityProbeUdf($sizeExpr) FROM $viewName")
}
}

Expand All @@ -323,13 +329,14 @@ class CometCodegenFuzzSuite
private def probeComplexColumn(field: StructField, viewName: String): Unit = {
field.dataType match {
case _: ArrayType | _: MapType =>
probeCardinality(field.name, viewName)
probeCardinality(field.name, field.dataType, viewName)

case st: StructType =>
for (subField <- st.fields) {
val accessor = s"${field.name}.${subField.name}"
subField.dataType match {
case _: ArrayType | _: MapType => probeCardinality(accessor, viewName)
case _: ArrayType | _: MapType =>
probeCardinality(accessor, subField.dataType, viewName)
case dt if !isComplexType(dt) =>
val udfName = s"id_${field.name}_${subField.name}"
registerIdentityUdfFor(dt, udfName).foreach { _ =>
Expand Down
10 changes: 9 additions & 1 deletion spark/src/test/scala/org/apache/comet/CometCodegenSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,15 @@ class CometCodegenSuite
}

test("ScalaUDF over Decimal(38, 10) routes through the BigDecimal slow path") {
spark.udf.register("decIdLong", (d: java.math.BigDecimal) => d)
// Pin the return type to Decimal(38, 10). TypeTag inference for `BigDecimal` would default to
// Decimal(38, 18), and under Spark 4 ANSI the encoder's CheckOverflow throws on the 28-digit
// boundary value below when rescaling 10 -> 18.
spark.udf.register(
"decIdLong",
new UDF1[java.math.BigDecimal, java.math.BigDecimal] {
override def call(d: java.math.BigDecimal): java.math.BigDecimal = d
},
DecimalType(38, 10))
withDecimalTable(
"DECIMAL(38, 10)",
Seq(
Expand Down
Loading