Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,14 @@ object CodeGenerator extends Logging {

def boxedType(dt: DataType): String = boxedType(javaType(dt))

def typeName(clazz: Class[_]): String = {
if (clazz.isArray) {
typeName(clazz.getComponentType) + "[]"
} else {
clazz.getName
}
}

/**
* Returns the representation of default value for a given Java Type.
* @param jt the string name of the Java type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ case class HashAggregateExec(
if (inputVars.forall(_.isDefined)) {
val splitCodes = inputVars.flatten.zipWithIndex.map { case (args, i) =>
val doAggFunc = ctx.freshName(s"doAggregate_${aggNames(i)}")
val argList = args.map(v => s"${v.javaType.getName} ${v.variableName}").mkString(", ")
val argList = args.map { v =>
s"${CodeGenerator.typeName(v.javaType)} ${v.variableName}"
}.mkString(", ")
val doAggFuncName = ctx.addNewFunction(doAggFunc,
s"""
|private void $doAggFunc($argList) throws java.io.IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,13 +1021,28 @@ abstract class AggregationQuerySuite extends QueryTest with SQLTestUtils with Te

test("SPARK-29122: hash-based aggregates for unfixed-length decimals in the interpreter mode") {
withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false",
SQLConf.CODEGEN_FACTORY_MODE.key -> CodegenObjectFactoryMode.NO_CODEGEN.toString) {
SQLConf.CODEGEN_FACTORY_MODE.key -> CodegenObjectFactoryMode.NO_CODEGEN.toString) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think previous is correct...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah IDE automatically indented while fixing conflicts. Will roll back.

withTempView("t") {
spark.range(3).selectExpr("CAST(id AS decimal(38, 0)) a").createOrReplaceTempView("t")
checkAnswer(sql("SELECT SUM(a) FROM t"), Row(java.math.BigDecimal.valueOf(3)))
}
}
}

test("SPARK-29140: HashAggregateExec aggregating binary type doesn't break codegen compilation") {
val schema = new StructType().add("id", IntegerType, nullable = false)
.add("c1", BinaryType, nullable = true)

withSQLConf(
SQLConf.CODEGEN_SPLIT_AGGREGATE_FUNC.key -> "true",
SQLConf.CODEGEN_METHOD_SPLIT_THRESHOLD.key -> "1") {
val emptyRows = spark.sparkContext.parallelize(Seq.empty[Row], 1)
val aggDf = spark.createDataFrame(emptyRows, schema)
.groupBy($"id" % 10 as "group")
.agg(countDistinct($"c1"))
checkAnswer(aggDf, Seq.empty[Row])
}
}
}


Expand Down