Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12067#discussion_r57932737
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/TypedAggregateExpression.scala
 ---
    @@ -149,3 +149,73 @@ case class TypedAggregateExpression(
     
       override def nodeName: String = aggregator.getClass.getSimpleName
     }
    +
    +case class TypedAggregateExpression2(
    +    aggregator: Aggregator[Any, Any, Any],
    +    inputDeserializer: Expression,
    +    inputAttributes: Seq[Attribute],
    +    bufferSerializer: Seq[NamedExpression],
    +    bufferDeserializer: Expression,
    +    bufferClass: Class[_],
    +    resultSerializer: Seq[NamedExpression],
    +    dataType: DataType) extends DeclarativeAggregate with NonSQLExpression 
{
    +
    +  override def nullable: Boolean = true
    +
    +  override def children: Seq[Expression] = Nil
    +
    +  override def inputTypes: Seq[AbstractDataType] = Nil
    +
    +  private val aggregatorLiteral = Literal.fromObject(aggregator)
    +
    +  private val bufferType = ObjectType(bufferClass)
    +
    +  override lazy val aggBufferAttributes: Seq[Attribute] = 
bufferSerializer.map(_.toAttribute)
    +
    +  override lazy val initialValues: Seq[Expression] = {
    +    val zero = Literal.create(aggregator.zero, bufferType)
    +    bufferSerializer.map(_ transform {
    +      case b: BoundReference => zero
    +    })
    +  }
    +
    +  override lazy val updateExpressions: Seq[Expression] = {
    +    val reduced = Invoke(
    +      aggregatorLiteral,
    +      "reduce",
    +      bufferType,
    +      bufferDeserializer :: inputDeserializer :: Nil)
    +
    +    bufferSerializer.map(_ transform {
    +      case b: BoundReference => reduced
    --- End diff --
    
    Is this fundamentally the same problem we are hitting when trying to codgen 
`Map` using `Project` or am I not understanding the issue?
    
    I wonder if we could have a special expression that takes an object and 
turns it into a struct in one shot instead of exploding it to multiple columns? 
 Just a random though.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to