Skip to content
Closed
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 @@ -647,15 +647,15 @@ case class First(child: Expression) extends UnaryExpression with PartialAggregat
case class FirstFunction(expr: Expression, base: AggregateExpression1) extends AggregateFunction1 {
def this() = this(null, null) // Required for serialization.

var result: Any = null
var result: MutableLiteral = MutableLiteral(null, expr.dataType)

override def update(input: InternalRow): Unit = {
if (result == null) {
result = expr.eval(input)
if (result.value == null) {
result.value = expr.eval(input)
}
}

override def eval(input: InternalRow): Any = result
override def eval(input: InternalRow): Any = result.value
}

case class Last(child: Expression) extends UnaryExpression with PartialAggregate1 {
Expand All @@ -676,13 +676,11 @@ case class Last(child: Expression) extends UnaryExpression with PartialAggregate
case class LastFunction(expr: Expression, base: AggregateExpression1) extends AggregateFunction1 {
def this() = this(null, null) // Required for serialization.

var result: Any = null
var result: MutableLiteral = MutableLiteral(null, expr.dataType)

override def update(input: InternalRow): Unit = {
result = input
result.value = expr.eval(input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggupta81 I see the problem. I think we only need to change this line to fix it. Basically, the input row can be a mutable row. So, we need to eagerly evaluate the expression instead of just pointing result to the input.

}

override def eval(input: InternalRow): Any = {
if (result != null) expr.eval(result.asInstanceOf[InternalRow]) else null
}
override def eval(input: InternalRow): Any = result.value
}