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 @@ -36,7 +36,7 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], () => Mu

protected def create(expressions: Seq[Expression]): (() => MutableProjection) = {
val ctx = newCodeGenContext()
val projectionCode = expressions.zipWithIndex.map { case (e, i) =>
val projectionCodes = expressions.zipWithIndex.map { case (e, i) =>
val evaluationCode = e.gen(ctx)
evaluationCode.code +
s"""
Expand All @@ -45,10 +45,31 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], () => Mu
else
${ctx.setColumn("mutableRow", e.dataType, i, evaluationCode.primitive)};
"""
}.mkString("\n")
}

val projectionCodeSegments = projectionCodes.grouped(50).toSeq.map(_.mkString("\n"))
Copy link
Member

Choose a reason for hiding this comment

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

How did you decide this number '50' for the JVM code size limitation?


val (projectionCode, projectionFuncs) = if (projectionCodeSegments.length == 1) {
(projectionCodeSegments(0), "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right! Here. Thanks for explanation.

} else {
val pCode = (0 until projectionCodeSegments.length).map { i =>
s"projectSeg$i(i);"
}.mkString("\n")

val pFuncs = (0 until projectionCodeSegments.length).map { i =>
s"""
private final void projectSeg$i(InternalRow i) {
${projectionCodeSegments(i)}
}
"""
}.mkString("\n")
(pCode, pFuncs)
}

val mutableStates = ctx.mutableStates.map { case (javaType, variableName, initialValue) =>
s"private $javaType $variableName = $initialValue;"
}.mkString("\n ")

val code = s"""
public Object generate($exprType[] expr) {
return new SpecificProjection(expr);
Expand All @@ -75,6 +96,8 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], () => Mu
return (InternalRow) mutableRow;
}

$projectionFuncs

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