Return-Path: X-Original-To: apmail-spark-reviews-archive@minotaur.apache.org Delivered-To: apmail-spark-reviews-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A53C8187F6 for ; Mon, 9 Nov 2015 23:58:33 +0000 (UTC) Received: (qmail 84801 invoked by uid 500); 9 Nov 2015 23:58:33 -0000 Delivered-To: apmail-spark-reviews-archive@spark.apache.org Received: (qmail 84774 invoked by uid 500); 9 Nov 2015 23:58:33 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 84759 invoked by uid 99); 9 Nov 2015 23:58:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Nov 2015 23:58:33 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 33C7CE0974; Mon, 9 Nov 2015 23:58:33 +0000 (UTC) From: marmbrus To: reviews@spark.apache.org Reply-To: reviews@spark.apache.org References: In-Reply-To: Subject: [GitHub] spark pull request: [SPARK-9830] [SQL] Remove AggregateExpression1... Content-Type: text/plain Message-Id: <20151109235833.33C7CE0974@git1-us-west.apache.org> Date: Mon, 9 Nov 2015 23:58:33 +0000 (UTC) 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