Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ import org.apache.spark.sql.types._
* a single partition, and we use a single reducer to do the aggregation.).
*/
@ExpressionDescription(
usage = """_FUNC_(expr) - Returns the first value of `child` for a group of rows.
_FUNC_(expr,isIgnoreNull=false) - Returns the first value of `child` for a group of rows.
usage =
"""
_FUNC_(expr) - Returns the first value of `child` for a group of rows.

_FUNC_(expr, isIgnoreNull=false) - Returns the first value of `child` for a group of rows.
If isIgnoreNull is true, returns only non-null values.

Note that in most cases the result is nondeterministic.
""")
case class First(child: Expression, ignoreNullsExpr: Expression) extends DeclarativeAggregate {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,23 @@ import org.apache.spark.sql.types._
* a single partition, and we use a single reducer to do the aggregation.).
*/
@ExpressionDescription(
usage = "_FUNC_(expr,isIgnoreNull) - Returns the last value of `child` for a group of rows.")
usage =
"""
_FUNC_(expr) - Returns the last value of `child` for a group of rows.

_FUNC_(expr, isIgnoreNull) - Returns the last value of `child` for a group of rows.
If isIgnoreNull is true, returns only non-null values.

Note that in most cases the result is nondeterministic.
""")
case class Last(child: Expression, ignoreNullsExpr: Expression) extends DeclarativeAggregate {

def this(child: Expression) = this(child, Literal.create(false, BooleanType))

private val ignoreNulls: Boolean = ignoreNullsExpr match {
case Literal(b: Boolean, BooleanType) => b
case _ =>
throw new AnalysisException("The second argument of First should be a boolean literal.")
throw new AnalysisException("The second argument of Last should be a boolean literal.")
}

override def children: Seq[Expression] = child :: ignoreNullsExpr :: Nil
Expand Down