Skip to content
Closed
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
Prev Previous commit
Next Next commit
[SPARK-8443][SQL] inline execution if one block only
  • Loading branch information
saurfang committed Jul 18, 2015
commit 1b5aa7e3c4fd9f0ffd2a55e0b26a1fdbda446005
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], () => Mu
${ctx.setColumn("mutableRow", e.dataType, i, evaluationCode.primitive)};
"""
}
val partitionedProjectionCode = projectionCode.foldLeft(List.empty[String]) {
val projectionBlocks = projectionCode.foldLeft(List.empty[String]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

would be great if you can rewrite the code to make it slightly less functional here. I'd actually prefer a more imperative version here

(acc, code) =>
acc match {
case Nil => List(code)
Expand All @@ -58,19 +58,24 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], () => Mu
code::acc
}
}
}
.zipWithIndex
.map {
case (body, i) =>
s"""
private void apply$i(InternalRow i) {
$body
}
"""
}
val projectionCalls = ((partitionedProjectionCode.length - 1) to 0 by -1)
.map(i => s"apply$i(i);")
.mkString("\n")
val (projectionFuns, projectionCalls) = {
// inline execution if codesize limit was not broken
if (projectionBlocks.length == 1) {
("", projectionBlocks.head)
} else {
(
projectionBlocks.zipWithIndex.map { case (body, i) =>
s"""
|private void apply$i(InternalRow i) {
| $body
|}
""".stripMargin
}.mkString,
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, should this be mkString("\n") or is there implicitly a newline somewhere that I'm overlooking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to above. The lines of s""" and """ seem already added newlines for readability.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM.

((projectionBlocks.length - 1) to 0 by -1).map(i => s"apply$i(i);").mkString("\n")
)
}
}
val mutableStates = ctx.mutableStates.map { case (javaType, variableName, initialValue) =>
s"private $javaType $variableName = $initialValue;"
}.mkString("\n ")
Expand Down Expand Up @@ -100,7 +105,7 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], () => Mu
return (InternalRow) mutableRow;
}

${partitionedProjectionCode.mkString("\n")}
$projectionFuns

public Object apply(Object _i) {
InternalRow i = (InternalRow) _i;
Expand Down