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 @@ -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,32 @@ 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"""
public void projectSeg$i(Object _i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it private final? And also instead of the make the argument type as Object, can we make it as InternalRow?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the codegen aim to inline the execution, probably we'd better not to increase the overhead for type casting.
Even, we'd better to put every 50(says) expressions into a single codegen function?

InternalRow 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 +97,8 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], () => Mu
return (InternalRow) mutableRow;
}

$projectionFuncs

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