Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/12067#discussion_r57923023
--- 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 --
Here we have a problem, `bufferSerializer` is a list of expressions, and
the `reduced` expression will appear many times. However, it should be only
executed once, and it's may not good to depend on subexpression elimination to
optimize this case.
cc @marmbrus
---
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]