Skip to content

Commit 7d5f4be

Browse files
committed
Fixed errors
1 parent 29fdaba commit 7d5f4be

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RewriteDistinctAggregates.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
198198

199199
// Select the result of the first aggregate in the last aggregate.
200200
val result = AggregateExpression(
201-
aggregate.First(evalWithinGroup(regularGroupId, operator.toAttribute), Literal(true)),
201+
aggregate.First("first",
202+
evalWithinGroup(regularGroupId, operator.toAttribute), Literal(true)),
202203
mode = Complete,
203204
isDistinct = false)
204205

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,15 +1510,15 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
15101510
*/
15111511
override def visitFirst(ctx: FirstContext): Expression = withOrigin(ctx) {
15121512
val ignoreNullsExpr = ctx.IGNORE != null
1513-
First(expression(ctx.expression), Literal(ignoreNullsExpr)).toAggregateExpression()
1513+
First("first", expression(ctx.expression), Literal(ignoreNullsExpr)).toAggregateExpression()
15141514
}
15151515

15161516
/**
15171517
* Create a [[Last]] expression.
15181518
*/
15191519
override def visitLast(ctx: LastContext): Expression = withOrigin(ctx) {
15201520
val ignoreNullsExpr = ctx.IGNORE != null
1521-
Last(expression(ctx.expression), Literal(ignoreNullsExpr)).toAggregateExpression()
1521+
Last("last", expression(ctx.expression), Literal(ignoreNullsExpr)).toAggregateExpression()
15221522
}
15231523

15241524
/**

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/aggregate/LastTestSuite.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import org.apache.spark.sql.types.IntegerType
2323

2424
class LastTestSuite extends SparkFunSuite {
2525
val input = AttributeReference("input", IntegerType, nullable = true)()
26-
val evaluator = DeclarativeAggregateEvaluator(Last(input, Literal(false)), Seq(input))
27-
val evaluatorIgnoreNulls = DeclarativeAggregateEvaluator(Last(input, Literal(true)), Seq(input))
26+
val evaluator = DeclarativeAggregateEvaluator(Last("last", input, Literal(false)), Seq(input))
27+
val evaluatorIgnoreNulls = DeclarativeAggregateEvaluator(
28+
Last("last", input, Literal(true)), Seq(input))
2829

2930
test("empty buffer") {
3031
assert(evaluator.initialize() === InternalRow(null, false))

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -787,19 +787,23 @@ class ExpressionParserSuite extends AnalysisTest {
787787
}
788788

789789
test("SPARK-19526 Support ignore nulls keywords for first and last") {
790-
assertEqual("first(a ignore nulls)", First('a, Literal(true)).toAggregateExpression())
791-
assertEqual("first(a)", First('a, Literal(false)).toAggregateExpression())
792-
assertEqual("last(a ignore nulls)", Last('a, Literal(true)).toAggregateExpression())
793-
assertEqual("last(a)", Last('a, Literal(false)).toAggregateExpression())
790+
assertEqual("first(a ignore nulls)", First("first", 'a, Literal(true)).toAggregateExpression())
791+
assertEqual("first(a)", First("first", 'a, Literal(false)).toAggregateExpression())
792+
assertEqual("last(a ignore nulls)", Last("last", 'a, Literal(true)).toAggregateExpression())
793+
assertEqual("last(a)", Last("last", 'a, Literal(false)).toAggregateExpression())
794794
}
795795

796796
test("Support respect nulls keywords for first_value and last_value") {
797-
assertEqual("first_value(a ignore nulls)", First('a, Literal(true)).toAggregateExpression())
798-
assertEqual("first_value(a respect nulls)", First('a, Literal(false)).toAggregateExpression())
799-
assertEqual("first_value(a)", First('a, Literal(false)).toAggregateExpression())
800-
assertEqual("last_value(a ignore nulls)", Last('a, Literal(true)).toAggregateExpression())
801-
assertEqual("last_value(a respect nulls)", Last('a, Literal(false)).toAggregateExpression())
802-
assertEqual("last_value(a)", Last('a, Literal(false)).toAggregateExpression())
797+
assertEqual("first_value(a ignore nulls)",
798+
First("first", 'a, Literal(true)).toAggregateExpression())
799+
assertEqual("first_value(a respect nulls)",
800+
First("first", 'a, Literal(false)).toAggregateExpression())
801+
assertEqual("first_value(a)", First("first", 'a, Literal(false)).toAggregateExpression())
802+
assertEqual("last_value(a ignore nulls)",
803+
Last("last", 'a, Literal(true)).toAggregateExpression())
804+
assertEqual("last_value(a respect nulls)",
805+
Last("last", 'a, Literal(false)).toAggregateExpression())
806+
assertEqual("last_value(a)", Last("last", 'a, Literal(false)).toAggregateExpression())
803807
}
804808

805809
test("timestamp literals") {

sql/core/src/main/scala/org/apache/spark/sql/execution/stat/StatFunctions.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ object StatFunctions extends Logging {
254254
stats.toLowerCase(Locale.ROOT) match {
255255
case "count" => (child: Expression) => Count(child).toAggregateExpression()
256256
case "mean" => (child: Expression) => Average(child).toAggregateExpression()
257-
case "stddev" => (child: Expression) => StddevSamp(child).toAggregateExpression()
257+
case "stddev" => (child: Expression) =>
258+
StddevSamp("stddev_samp", child).toAggregateExpression()
258259
case "min" => (child: Expression) => Min(child).toAggregateExpression()
259260
case "max" => (child: Expression) => Max(child).toAggregateExpression()
260261
case _ => throw new IllegalArgumentException(s"$stats is not a recognised statistic")

0 commit comments

Comments
 (0)