Skip to content

Commit 1ed010f

Browse files
committed
Add new conf for maxParamNumInJavaMethod
1 parent f866b11 commit 1ed010f

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,17 @@ object SQLConf {
607607
.intConf
608608
.createWithDefault(100)
609609

610+
val MAX_PARAM_NUM_IN_JAVA_METHOD =
611+
buildConf("spark.sql.codegen.maxParamNumInJavaMethod")
612+
.internal()
613+
.doc("The maximum number of parameters in codegened Java functions. When a function " +
614+
"exceeds this threshold, the code generator gives up splitting the function code. " +
615+
"This default value is 127 because the maximum length of parameters in non-static Java " +
616+
"methods is 254 and a parameter of type long or double contributes " +
617+
"two units to the length.")
618+
.intConf
619+
.createWithDefault(127)
620+
610621
val CODEGEN_FALLBACK = buildConf("spark.sql.codegen.fallback")
611622
.internal()
612623
.doc("When true, (whole stage) codegen could be temporary disabled for the part of query that" +
@@ -1156,6 +1167,8 @@ class SQLConf extends Serializable with Logging {
11561167

11571168
def wholeStageMaxNumFields: Int = getConf(WHOLESTAGE_MAX_NUM_FIELDS)
11581169

1170+
def maxParamNumInJavaMethod: Int = getConf(MAX_PARAM_NUM_IN_JAVA_METHOD)
1171+
11591172
def codegenFallback: Boolean = getConf(CODEGEN_FALLBACK)
11601173

11611174
def loggingMaxLinesForCodegen: Int = getConf(CODEGEN_LOGGING_MAX_LINES)

sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,11 @@ case class HashAggregateExec(
309309
subExprs: Map[Expression, SubExprEliminationState],
310310
otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
311311
aggExprs.zipWithIndex.map { case (aggExpr, i) =>
312-
// The maximum length of parameters in non-static Java methods is 254, but a parameter of
313-
// type long or double contributes two units to the length. So, this method gives up
314-
// splitting the code if the parameter length goes over 127.
315312
val args = (getInputVariableReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
316313

317-
// This is for testing/benchmarking only
318-
val maxParamNumInJavaMethod =
319-
sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
320-
case null | "" => 127
321-
case param => param.toInt
322-
}
323-
if (args.size <= maxParamNumInJavaMethod) {
314+
// This method gives up splitting the code if the parameter length goes over
315+
// `maxParamNumInJavaMethod`.
316+
if (args.size <= sqlContext.conf.maxParamNumInJavaMethod) {
324317
val doAggVal = ctx.freshName(s"doAggregateVal_${aggExpr.prettyName}")
325318
val argList = args.map(a => s"${a._1} ${a._2}").mkString(", ")
326319
val doAggValFuncName = ctx.addNewFunction(doAggVal,

sql/core/src/test/scala/org/apache/spark/sql/execution/WholeStageCodegenSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class WholeStageCodegenSuite extends QueryTest with SharedSQLContext {
238238
}
239239

240240
test("SPARK-21870 check the case where the number of parameters goes over the limit") {
241-
withSQLConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod" -> "2") {
241+
withSQLConf("spark.sql.codegen.maxParamNumInJavaMethod" -> "2") {
242242
sql("CREATE OR REPLACE TEMPORARY VIEW t AS SELECT * FROM VALUES (1, 1, 1) AS t(a, b, c)")
243243
val df = sql("SELECT SUM(a + b + c) AS sum FROM t")
244244
assert(df.collect === Seq(Row(3)))

0 commit comments

Comments
 (0)