Skip to content

Commit 759262d

Browse files
committed
+constructor Last
1 parent 7ba7802 commit 759262d

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,12 @@ object FunctionRegistry {
304304
expression[ApproximatePercentile]("approx_percentile"),
305305
expressionWithAlias[StddevSamp]("std"),
306306
expressionWithAlias[StddevSamp]("stddev"),
307-
expression[StddevPop]("stddev_pop"),
308307
expressionWithAlias[StddevSamp]("stddev_samp"),
308+
expression[StddevPop]("stddev_pop"),
309309
expression[Sum]("sum"),
310310
expressionWithAlias[VarianceSamp]("variance"),
311-
expression[VariancePop]("var_pop"),
312311
expressionWithAlias[VarianceSamp]("var_samp"),
312+
expression[VariancePop]("var_pop"),
313313
expression[CollectList]("collect_list"),
314314
expression[CollectSet]("collect_set"),
315315
expression[CountMinSketchAgg]("count_min_sketch"),

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/First.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ import org.apache.spark.sql.types._
4747
case class First(funcName: String, child: Expression, ignoreNullsExpr: Expression)
4848
extends DeclarativeAggregate with ExpectsInputTypes {
4949

50-
def this(child: Expression) = this("first", child, Literal.create(false, BooleanType))
50+
def this(child: Expression) = this(child, Literal.create(false, BooleanType))
5151

52-
def this(child: Expression, ignoreNullsExpr: Expression) =
53-
this("first", child, ignoreNullsExpr)
52+
def this(child: Expression, ignoreNullsExpr: Expression) = this("first", child, ignoreNullsExpr)
5453

5554
override def children: Seq[Expression] = child :: ignoreNullsExpr :: Nil
5655

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Last.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ import org.apache.spark.sql.types._
4747
case class Last(funcName: String, child: Expression, ignoreNullsExpr: Expression)
4848
extends DeclarativeAggregate with ExpectsInputTypes {
4949

50-
def this(child: Expression) = this("last", child, Literal.create(false, BooleanType))
50+
def this(child: Expression) = this(child, Literal.create(false, BooleanType))
51+
52+
def this(child: Expression, ignoreNullsExpr: Expression) = this("last", child, ignoreNullsExpr)
5153

5254
override def children: Seq[Expression] = child :: ignoreNullsExpr :: Nil
5355

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("first", expression(ctx.expression), Literal(ignoreNullsExpr)).toAggregateExpression()
1513+
new 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("last", expression(ctx.expression), Literal(ignoreNullsExpr)).toAggregateExpression()
1521+
new 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +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("last", input, Literal(false)), Seq(input))
26+
val evaluator = DeclarativeAggregateEvaluator(new Last(input, Literal(false)), Seq(input))
2727
val evaluatorIgnoreNulls = DeclarativeAggregateEvaluator(
28-
Last("last", input, Literal(true)), Seq(input))
28+
new Last(input, Literal(true)), Seq(input))
2929

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

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ class ExpressionParserSuite extends AnalysisTest {
789789
test("SPARK-19526 Support ignore nulls keywords for first and last") {
790790
assertEqual("first(a ignore nulls)", new First('a, Literal(true)).toAggregateExpression())
791791
assertEqual("first(a)", new 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())
792+
assertEqual("last(a ignore nulls)", new Last('a, Literal(true)).toAggregateExpression())
793+
assertEqual("last(a)", new Last('a, Literal(false)).toAggregateExpression())
794794
}
795795

796796
test("Support respect nulls keywords for first_value and last_value") {
@@ -801,10 +801,11 @@ class ExpressionParserSuite extends AnalysisTest {
801801
assertEqual("first_value(a)",
802802
new First('a, Literal(false)).toAggregateExpression())
803803
assertEqual("last_value(a ignore nulls)",
804-
Last("last", 'a, Literal(true)).toAggregateExpression())
804+
new Last('a, Literal(true)).toAggregateExpression())
805805
assertEqual("last_value(a respect nulls)",
806-
Last("last", 'a, Literal(false)).toAggregateExpression())
807-
assertEqual("last_value(a)", Last("last", 'a, Literal(false)).toAggregateExpression())
806+
new Last('a, Literal(false)).toAggregateExpression())
807+
assertEqual("last_value(a)",
808+
new Last('a, Literal(false)).toAggregateExpression())
808809
}
809810

810811
test("timestamp literals") {

sql/core/src/main/scala/org/apache/spark/sql/functions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ object functions {
556556
* @since 2.0.0
557557
*/
558558
def last(e: Column, ignoreNulls: Boolean): Column = withAggregateFunction {
559-
new Last("last", e.expr, Literal(ignoreNulls))
559+
new Last(e.expr, Literal(ignoreNulls))
560560
}
561561

562562
/**

0 commit comments

Comments
 (0)