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

    https://github.com/apache/spark/pull/6297#discussion_r39227597
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/functions.scala
 ---
    @@ -249,6 +249,155 @@ case class Min(child: Expression) extends 
AlgebraicAggregate {
       override val evaluateExpression = min
     }
     
    +// Compute the sample standard deviation of a column
    +case class Stddev(child: Expression) extends StddevAgg(child) {
    +
    +  override def isSample: Boolean = true
    +  override def prettyName: String = "stddev"
    +}
    +
    +// Compute the population standard deviation of a column
    +case class StddevPop(child: Expression) extends StddevAgg(child) {
    +
    +  override def isSample: Boolean = false
    +  override def prettyName: String = "stddev_pop"
    +}
    +
    +// Compute the sample standard deviation of a column
    +case class StddevSamp(child: Expression) extends StddevAgg(child) {
    +
    +  override def isSample: Boolean = true
    +  override def prettyName: String = "stddev_samp"
    +}
    +
    +// Compute standard deviation based on online algorithm specified here:
    +// http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
    +abstract class StddevAgg(child: Expression) extends AlgebraicAggregate {
    +
    +  override def children: Seq[Expression] = child :: Nil
    +
    +  override def nullable: Boolean = true
    +
    +  def isSample: Boolean
    +
    +  // Return data type.
    +  override def dataType: DataType = resultType
    +
    +  // 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 stddev(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))
    +
    +  private val resultType = child.dataType match {
    +    case DecimalType.Fixed(p, s) =>
    --- End diff --
    
    I think it should always return Double, because Sqrt() only works with 
Double, also other databases just return Double/float.


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