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

    https://github.com/apache/spark/pull/9003#discussion_r42584406
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/functions.scala
 ---
    @@ -842,3 +699,302 @@ object HyperLogLogPlusPlus {
       )
       // scalastyle:on
     }
    +
    +abstract class CentralMomentAgg(child: Expression) extends 
ImperativeAggregate with Serializable {
    +
    +  /**
    +   * The maximum central moment order to be computed
    +   */
    +  protected def maxMoment: Int
    +
    +  override def children: Seq[Expression] = Seq(child)
    +
    +  override def nullable: Boolean = false
    +
    +  override def dataType: DataType = DoubleType
    +
    +  // Expected input data type.
    +  // TODO: Right now, we replace old aggregate functions (based on 
AggregateExpression1) to the
    +  // new version at planning time (after analysis phase). For now, 
NullType is added at here
    +  // to make it resolved when we have cases like `select avg(null)`.
    +  // We can use our analyzer to cast NullType to the default data type of 
the NumericType once
    +  // we remove the old aggregate functions. Then, we will not need 
NullType at here.
    +  override def inputTypes: Seq[AbstractDataType] = 
Seq(TypeCollection(NumericType, NullType))
    +
    +  override def aggBufferSchema: StructType = 
StructType.fromAttributes(aggBufferAttributes)
    +
    +  /**
    +   * The number of central moments to store in the buffer
    +   */
    +  private[this] val numMoments = 5
    +
    +  override val aggBufferAttributes: Seq[AttributeReference] = 
Seq.tabulate(numMoments) { i =>
    +    AttributeReference(s"M$i", DoubleType)()
    +  }
    +
    +  /**
    +   * Initialize all moments to zero
    +   */
    +  override def initialize(buffer: MutableRow): Unit = {
    +    var aggIndex = 0
    +    while (aggIndex < numMoments) {
    +      buffer.setDouble(mutableAggBufferOffset + aggIndex, 0.0)
    +      aggIndex += 1
    +    }
    +  }
    +
    +  /**
    +   * Update the central moments buffer.
    +   */
    +  override def update(buffer: MutableRow, input: InternalRow): Unit = {
    +    val v = Cast(child, DoubleType).eval(input)
    +    if (v != null) {
    +      val updateValue = v match {
    +        case d: Double => d
    +        case _ => 0.0
    +      }
    +      val currentM0 = buffer.getDouble(mutableAggBufferOffset)
    --- End diff --
    
    Done.


---
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