Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-26680][SQL] Eagerly create inputVars while conditions are appropriate #23617

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -143,14 +143,11 @@ trait CodegenSupport extends SparkPlan {
* Note that `outputVars` and `row` can't both be null.
*/
final def consume(ctx: CodegenContext, outputVars: Seq[ExprCode], row: String = null): String = {
val inputVars =
val inputVars = {
if (outputVars != null) {
assert(outputVars.length == output.length)
// outputVars will be used to generate the code for UnsafeRow, so we should copy them
outputVars.map(_.copy()) match {
case stream: Stream[ExprCode] => stream.force
case other => other
}
outputVars.map(_.copy())
} else {
assert(row != null, "outputVars and row cannot both be null.")
ctx.currentVars = null
Expand All @@ -159,6 +156,10 @@ trait CodegenSupport extends SparkPlan {
BoundReference(i, attr.dataType, attr.nullable).genCode(ctx)
}
}
} match {
Copy link
Member

Choose a reason for hiding this comment

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

I think this construction is confusing. Can this be split into two statements rather than chain a block and match?

case stream: Stream[ExprCode] => stream.force
case other => other
}

val rowVar = prepareRowVar(ctx, row, outputVars)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,13 @@ class WholeStageCodegenSuite extends QueryTest with SharedSQLContext {

checkAnswer(abc, Row(1, "a"))
}

test("SPARK-26680: Stream in groupBy does not cause StackOverflowError") {
val groupByCols = Stream(col("key"))
val df = Seq((1, 2), (2, 3), (1, 3)).toDF("key", "value")
.groupBy(groupByCols: _*)
.max("value")

checkAnswer(df, Seq(Row(1, 3), Row(2, 3)))
}
}