Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/12067#discussion_r57990083
--- 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 --
yes, it's the same problem.
turning an object to a struct in one shot doesn't solve the problem, as we
need to flatten it to `Seq[Expression]` here, which will be a list of
`GetStructField` and the "one shot" expression still appears many times.
Actually I think we don't need to do anything here. Although the `reduced`
expression appears many times, they are same references and subexpression
elimination should always work. Or we can introduce the Holder and Reference to
make it more clear.
---
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]