spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marmbrus <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-9830] [SQL] Remove AggregateExpression1...
Date Mon, 09 Nov 2015 23:58:33 GMT
Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9556#discussion_r44352445
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/GroupedData.scala ---
    @@ -88,30 +89,33 @@ class GroupedData protected[sql](
             namedExpr
           }
         }
    -    toDF(columnExprs.map(f))
    +    toDF(columnExprs.map(expr => f(expr).toAggregateExpression()))
       }
     
       private[this] def strToExpr(expr: String): (Expression => Expression) = {
    -    expr.toLowerCase match {
    -      case "avg" | "average" | "mean" => Average
    -      case "max" => Max
    -      case "min" => Min
    -      case "stddev" | "std" => StddevSamp
    -      case "stddev_pop" => StddevPop
    -      case "stddev_samp" => StddevSamp
    -      case "variance" => VarianceSamp
    -      case "var_pop" => VariancePop
    -      case "var_samp" => VarianceSamp
    -      case "sum" => Sum
    -      case "skewness" => Skewness
    -      case "kurtosis" => Kurtosis
    -      case "count" | "size" =>
    -        // Turn count(*) into count(1)
    -        (inputExpr: Expression) => inputExpr match {
    -          case s: Star => Count(Literal(1))
    -          case _ => Count(inputExpr)
    -        }
    +    val exprToFunc: (Expression => AggregateFunction) = {
    +      (inputExpr: Expression) => expr.toLowerCase match {
    +        case "avg" | "average" | "mean" => Average(inputExpr)
    +        case "max" => Max(inputExpr)
    +        case "min" => Min(inputExpr)
    +        case "stddev" | "std" => StddevSamp(inputExpr)
    +        case "stddev_pop" => StddevPop(inputExpr)
    +        case "stddev_samp" => StddevSamp(inputExpr)
    +        case "variance" => VarianceSamp(inputExpr, 0, 0)
    +        case "var_pop" => VariancePop(inputExpr, 0, 0)
    +        case "var_samp" => VarianceSamp(inputExpr, 0, 0)
    +        case "sum" => Sum(inputExpr)
    +        case "skewness" => Skewness(inputExpr, 0, 0)
    +        case "kurtosis" => Kurtosis(inputExpr, 0, 0)
    --- End diff --
    
    This is kinda of a nit, but I think it might be better to rely on the defaults provided
by the extra constructor instead of hard coding these here and elsewhere.
    
    Also, is it possible for a user to corrupt query results by specifying their own offsets
due to the way we resolve functions?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message