Skip to content

Commit 6368702

Browse files
committed
Let rowidx as global variable instead of early evaluation of column output.
1 parent d051f9e commit 6368702

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/ColumnarBatchScan.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,10 @@ private[sql] trait ColumnarBatchScan extends CodegenSupport {
109109

110110
ctx.currentVars = null
111111
val rowidx = ctx.freshName("rowIdx")
112+
ctx.addMutableState(ctx.JAVA_INT, rowidx)
112113
val columnsBatchInput = (output zip colVars).map { case (attr, colVar) =>
113114
genCodeColumnVector(ctx, colVar, rowidx, attr.dataType, attr.nullable)
114115
}
115-
// `rowIdx` is a special variable which can't be referred if the parent nodes split expressions.
116-
// So we evaluate column outputs right away.
117-
val evalColumnsBatchInput = evaluateVariables(columnsBatchInput)
118116
val localIdx = ctx.freshName("localIdx")
119117
val localEnd = ctx.freshName("localEnd")
120118
val numRows = ctx.freshName("numRows")
@@ -131,8 +129,7 @@ private[sql] trait ColumnarBatchScan extends CodegenSupport {
131129
| int $numRows = $batch.numRows();
132130
| int $localEnd = $numRows - $idx;
133131
| for (int $localIdx = 0; $localIdx < $localEnd; $localIdx++) {
134-
| int $rowidx = $idx + $localIdx;
135-
| $evalColumnsBatchInput
132+
| $rowidx = $idx + $localIdx;
136133
| ${consume(ctx, columnsBatchInput).trim}
137134
| $shouldStop
138135
| }

0 commit comments

Comments
 (0)