Skip to content
Closed
Changes from 3 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 @@ -199,8 +199,7 @@ case class Stack(children: Seq[Expression]) extends Generator {

override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
// Rows - we write these into an array.
val rowData = ctx.addMutableState("InternalRow[]", "rows",
v => s"$v = new InternalRow[$numRows];")
val rowData = ctx.freshName("rowsStack")
val values = children.tail
val dataTypes = values.take(numFields).map(_.dataType)
val code = ctx.splitExpressionsWithCurrentInputs(Seq.tabulate(numRows) { row =>
Expand All @@ -214,11 +213,12 @@ case class Stack(children: Seq[Expression]) extends Generator {

// Create the collection.
val wrapperClass = classOf[mutable.WrappedArray[_]].getName
ctx.addMutableState(
s"$wrapperClass<InternalRow>",
ev.value,
v => s"$v = $wrapperClass$$.MODULE$$.make($rowData);", useFreshName = false)
ev.copy(code = code, isNull = "false")
ev.copy(code =
s"""
|InternalRow[] $rowData = new InternalRow[$numRows];
Copy link
Contributor

Choose a reason for hiding this comment

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

this creates a large array every time, and I don't think we have data copy issues for generator expressions...

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. I did not imagine that numRows is large.
I will revert the code for rowData.

|$code
|$wrapperClass<InternalRow> ${ev.value} = $wrapperClass$$.MODULE$$.make($rowData);
""".stripMargin, isNull = "false")
Copy link
Member Author

@kiszk kiszk Dec 20, 2017

Choose a reason for hiding this comment

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

This change does not use inline = true at ctx.addMutableState for correct code generation.

}
}

Expand Down