Github user ueshin commented on a diff in the pull request:
https://github.com/apache/spark/pull/22187#discussion_r212062744
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/RowBasedHashMapGenerator.scala
---
@@ -44,31 +44,19 @@ class RowBasedHashMapGenerator(
groupingKeySchema, bufferSchema) {
override protected def initializeAggregateHashMap(): String = {
- val generatedKeySchema: String =
- s"new org.apache.spark.sql.types.StructType()" +
- groupingKeySchema.map { key =>
- val keyName = ctx.addReferenceObj("keyName", key.name)
- key.dataType match {
- case d: DecimalType =>
- s""".add($keyName,
org.apache.spark.sql.types.DataTypes.createDecimalType(
- |${d.precision}, ${d.scale}))""".stripMargin
- case _ =>
- s""".add($keyName,
org.apache.spark.sql.types.DataTypes.${key.dataType})"""
- }
- }.mkString("\n").concat(";")
+ val generatedKeyColTypes = groupingKeySchema
+ .zipWithIndex.map { case (t, i) => (s"_col$i", t.dataType) }
+ val generatedKeySchemaTypes = generatedKeyColTypes
+ .foldLeft(new StructType())((schema, colType) =>
schema.add(colType._1, colType._2))
--- End diff --
Btw, do we need to recreate the struct type with dummy names if we use
`ctx.addReferenceObj()`? We might need to do `.asNullable`, though.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]