Skip to content

Commit

Permalink
Refactor isValidParamLength a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Jan 25, 2018
1 parent c859d53 commit 11946e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1247,21 +1247,28 @@ class CodegenContext {
}

/**
* In Java, a method descriptor is valid only if it represents method parameters with a total
* length of 255 or less. `this` contributes one unit and a parameter of type long or double
* contributes two units. Besides, for nullable parameters, we also need to pass a boolean
* for the null status.
* Returns the length of parameters for a Java method descriptor. `this` contributes one unit
* and a parameter of type long or double contributes two units. Besides, for nullable parameter,
* we also need to pass a boolean parameter for the null status.
*/
def isValidParamLength(params: Seq[Expression]): Boolean = {
def calculateParamLength(input: Expression): Int = {
def calculateParamLength(params: Seq[Expression]): Int = {
def paramLengthForExpr(input: Expression): Int = {
// For a nullable expression, we need to pass in an extra boolean parameter.
(if (input.nullable) 1 else 0) + javaType(input.dataType) match {
case JAVA_LONG | JAVA_DOUBLE => 2
case _ => 1
}
}
// Initial value is 1 for `this`.
1 + params.map(calculateParamLength(_)).sum <= CodeGenerator.MAX_JVM_METHOD_PARAMS_LENGTH
1 + params.map(paramLengthForExpr(_)).sum
}

/**
* In Java, a method descriptor is valid only if it represents method parameters with a total
* length less than a pre-defined constant.
*/
def isValidParamLength(paramLength: Int): Boolean = {
paramLength <= CodeGenerator.MAX_JVM_METHOD_PARAMS_LENGTH
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ trait CodegenSupport extends SparkPlan {
// all variables in output (see `requireAllOutput`).
// 3. The number of output variables must less than maximum number of parameters in Java method
// declaration.
val confEnabled = SQLConf.get.wholeStageSplitConsumeFuncByOperator
val requireAllOutput = output.forall(parent.usedInputs.contains(_))
val consumeFunc =
if (SQLConf.get.wholeStageSplitConsumeFuncByOperator && requireAllOutput &&
ctx.isValidParamLength(output)) {
constructDoConsumeFunction(ctx, inputVars, row)
} else {
parent.doConsume(ctx, inputVars, rowVar)
}
val paramLength = ctx.calculateParamLength(output) + (if (row != null) 1 else 0)
val consumeFunc = if (confEnabled && requireAllOutput && ctx.isValidParamLength(paramLength)) {
constructDoConsumeFunction(ctx, inputVars, row)
} else {
parent.doConsume(ctx, inputVars, rowVar)
}
s"""
|${ctx.registerComment(s"CONSUME: ${parent.simpleString}")}
|$evaluated
Expand Down

0 comments on commit 11946e7

Please sign in to comment.