Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
999ec13
[SPARK-22570][SQL] Avoid to create a lot of global variables by using…
kiszk Nov 30, 2017
6ac57fd
[SPARK-21417][SQL] Infer join conditions using propagated constraints
Nov 30, 2017
bcceab6
[SPARK-22489][SQL] Shouldn't change broadcast join buildSide if user …
wangyum Nov 30, 2017
f5f8e84
[SPARK-22614] Dataset API: repartitionByRange(...)
adrian-ionescu Nov 30, 2017
7e5f669
[SPARK-22428][DOC] Add spark application garbage collector configurat…
gaborgsomogyi Dec 1, 2017
7da1f57
[SPARK-22373] Bump Janino dependency version to fix thread safety issue…
Victsm Dec 1, 2017
dc36542
[SPARK-22653] executorAddress registered in CoarseGrainedSchedulerBac…
tgravescs Dec 1, 2017
16adaf6
[SPARK-22601][SQL] Data load is getting displayed successful on provi…
sujith71955 Dec 1, 2017
9d06a9e
[SPARK-22393][SPARK-SHELL] spark-shell can't find imported types in c…
mpetruska Dec 1, 2017
ee10ca7
[SPARK-22638][SS] Use a separate queue for StreamingQueryListenerBus
zsxwing Dec 1, 2017
aa4cf2b
[SPARK-22651][PYTHON][ML] Prevent initiating multiple Hive clients fo…
HyukjinKwon Dec 2, 2017
d2cf95a
[SPARK-22634][BUILD] Update Bouncy Castle to 1.58
srowen Dec 2, 2017
f23dddf
[SPARK-20682][SPARK-15474][SPARK-21791] Add new ORCFileFormat based o…
dongjoon-hyun Dec 3, 2017
2c16267
[SPARK-22669][SQL] Avoid unnecessary function calls in code generation
mgaido91 Dec 3, 2017
dff440f
[SPARK-22626][SQL] deals with wrong Hive's statistics (zero rowCount)
wangyum Dec 3, 2017
4131ad0
[SPARK-22489][DOC][FOLLOWUP] Update broadcast behavior changes in mig…
wangyum Dec 4, 2017
3927bb9
[SPARK-22473][FOLLOWUP][TEST] Remove deprecated Date functions
mgaido91 Dec 4, 2017
f81401e
[SPARK-22162] Executors and the driver should use consistent JobIDs i…
Dec 4, 2017
e1dd03e
[SPARK-22372][CORE, YARN] Make cluster submission use SparkApplication.
Dec 4, 2017
dcaac45
Spark on Kubernetes - basic submission client
liyinan926 Nov 10, 2017
27c67ff
Addressed first round of review comments
liyinan926 Nov 27, 2017
6d597d0
Made Client implement the SparkApplication trait
liyinan926 Nov 28, 2017
5b9fa39
Addressed the second round of comments
liyinan926 Nov 28, 2017
5ccadb5
Added missing step for supporting local:// dependencies and addressed…
liyinan926 Nov 30, 2017
12f2797
Fixed Scala style check errors
liyinan926 Nov 30, 2017
c35fe48
Addressed another round of comments
liyinan926 Dec 4, 2017
faa2849
Rebased on master and added a constant val for the Client class
liyinan926 Dec 4, 2017
347ed69
Addressed another major round of comments
liyinan926 Dec 5, 2017
0e8ca01
Addressed one more round of comments
liyinan926 Dec 5, 2017
3a0b8e3
Removed mentioning of kubernetes-namespace
liyinan926 Dec 6, 2017
83d0b9c
Fixed a couple of bugs found during manual tests
liyinan926 Dec 7, 2017
44c40b1
Guard against client mode in SparkContext
liyinan926 Dec 8, 2017
67bc847
Added libc6-compat into the base docker image
liyinan926 Dec 8, 2017
7d2b303
Addressed latest comments
liyinan926 Dec 8, 2017
caf2206
Addressed docs comments
liyinan926 Dec 9, 2017
2e7810b
Fixed a comment
liyinan926 Dec 11, 2017
cbcd30e
Addressed latest comments
liyinan926 Dec 11, 2017
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-22669][SQL] Avoid unnecessary function calls in code generation
## What changes were proposed in this pull request?

In many parts of the codebase for code generation, we are splitting the code to avoid exceptions due to the 64KB method size limit. This is generating a lot of methods which are called every time, even though sometime this is not needed. As pointed out here: apache#19752 (comment), this is a not negligible overhead which can be avoided.

The PR applies the same approach used in apache#19752 also to the other places where this was feasible.

## How was this patch tested?

existing UTs.

Author: Marco Gaido <[email protected]>

Closes apache#19860 from mgaido91/SPARK-22669.
  • Loading branch information
mgaido91 authored and cloud-fan committed Dec 3, 2017
commit 2c16267f7ca392d717942a7654e90db60ba60770
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,51 @@ case class Coalesce(children: Seq[Expression]) extends Expression {
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull)
ctx.addMutableState(ctx.javaType(dataType), ev.value)

// all the evals are meant to be in a do { ... } while (false); loop
val evals = children.map { e =>
val eval = e.genCode(ctx)
s"""
if (${ev.isNull}) {
${eval.code}
if (!${eval.isNull}) {
${ev.isNull} = false;
${ev.value} = ${eval.value};
}
}
"""
|${eval.code}
|if (!${eval.isNull}) {
| ${ev.isNull} = false;
| ${ev.value} = ${eval.value};
| continue;
|}
""".stripMargin
}
val code = if (ctx.INPUT_ROW == null || ctx.currentVars != null) {
evals.mkString("\n")
} else {
ctx.splitExpressions(evals, "coalesce",
("InternalRow", ctx.INPUT_ROW) :: Nil,
makeSplitFunction = {
func =>
s"""
|do {
| $func
|} while (false);
""".stripMargin
},
foldFunctions = { funcCalls =>
funcCalls.map { funcCall =>
s"""
|$funcCall;
|if (!${ev.isNull}) {
| continue;
|}
""".stripMargin
}.mkString
})
}

ev.copy(code = s"""
${ev.isNull} = true;
${ev.value} = ${ctx.defaultValue(dataType)};
${ctx.splitExpressions(evals)}""")
ev.copy(code =
s"""
|${ev.isNull} = true;
|${ev.value} = ${ctx.defaultValue(dataType)};
|do {
| $code
|} while (false);
""".stripMargin)
}
}

Expand Down Expand Up @@ -358,53 +386,70 @@ case class AtLeastNNonNulls(n: Int, children: Seq[Expression]) extends Predicate

override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val nonnull = ctx.freshName("nonnull")
// all evals are meant to be inside a do { ... } while (false); loop
val evals = children.map { e =>
val eval = e.genCode(ctx)
e.dataType match {
case DoubleType | FloatType =>
s"""
if ($nonnull < $n) {
${eval.code}
if (!${eval.isNull} && !Double.isNaN(${eval.value})) {
$nonnull += 1;
}
}
"""
|if ($nonnull < $n) {
| ${eval.code}
| if (!${eval.isNull} && !Double.isNaN(${eval.value})) {
| $nonnull += 1;
| }
|} else {
| continue;
|}
""".stripMargin
case _ =>
s"""
if ($nonnull < $n) {
${eval.code}
if (!${eval.isNull}) {
$nonnull += 1;
}
}
"""
|if ($nonnull < $n) {
| ${eval.code}
| if (!${eval.isNull}) {
| $nonnull += 1;
| }
|} else {
| continue;
|}
""".stripMargin
}
}

val code = if (ctx.INPUT_ROW == null || ctx.currentVars != null) {
evals.mkString("\n")
} else {
ctx.splitExpressions(
expressions = evals,
funcName = "atLeastNNonNulls",
arguments = ("InternalRow", ctx.INPUT_ROW) :: ("int", nonnull) :: Nil,
returnType = "int",
makeSplitFunction = { body =>
s"""
$body
return $nonnull;
"""
},
foldFunctions = { funcCalls =>
funcCalls.map(funcCall => s"$nonnull = $funcCall;").mkString("\n")
}
)
}
evals.mkString("\n")
} else {
ctx.splitExpressions(
expressions = evals,
funcName = "atLeastNNonNulls",
arguments = ("InternalRow", ctx.INPUT_ROW) :: (ctx.JAVA_INT, nonnull) :: Nil,
returnType = ctx.JAVA_INT,
makeSplitFunction = { body =>
s"""
|do {
| $body
|} while (false);
|return $nonnull;
""".stripMargin
},
foldFunctions = { funcCalls =>
funcCalls.map(funcCall =>
s"""
|$nonnull = $funcCall;
|if ($nonnull >= $n) {
| continue;
|}
""".stripMargin).mkString("\n")
}
)
}

ev.copy(code = s"""
int $nonnull = 0;
$code
boolean ${ev.value} = $nonnull >= $n;""", isNull = "false")
ev.copy(code =
s"""
|${ctx.JAVA_INT} $nonnull = 0;
|do {
| $code
|} while (false);
|${ctx.JAVA_BOOLEAN} ${ev.value} = $nonnull >= $n;
""".stripMargin, isNull = "false")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,36 +234,62 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate {
}

override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val javaDataType = ctx.javaType(value.dataType)
val valueGen = value.genCode(ctx)
val listGen = list.map(_.genCode(ctx))
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.value)
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull)
val valueArg = ctx.freshName("valueArg")
// All the blocks are meant to be inside a do { ... } while (false); loop.
// The evaluation of variables can be stopped when we find a matching value.
val listCode = listGen.map(x =>
s"""
if (!${ev.value}) {
${x.code}
if (${x.isNull}) {
${ev.isNull} = true;
} else if (${ctx.genEqual(value.dataType, valueArg, x.value)}) {
${ev.isNull} = false;
${ev.value} = true;
|${x.code}
|if (${x.isNull}) {
| ${ev.isNull} = true;
|} else if (${ctx.genEqual(value.dataType, valueArg, x.value)}) {
| ${ev.isNull} = false;
| ${ev.value} = true;
| continue;
|}
""".stripMargin)
val code = if (ctx.INPUT_ROW == null || ctx.currentVars != null) {
listCode.mkString("\n")
} else {
ctx.splitExpressions(
expressions = listCode,
funcName = "valueIn",
arguments = ("InternalRow", ctx.INPUT_ROW) :: (javaDataType, valueArg) :: Nil,
makeSplitFunction = { body =>
s"""
|do {
| $body
|} while (false);
""".stripMargin
},
foldFunctions = { funcCalls =>
funcCalls.map(funcCall =>
s"""
|$funcCall;
|if (${ev.value}) {
| continue;
|}
""".stripMargin).mkString("\n")
}
}
""")
val listCodes = ctx.splitExpressions(
expressions = listCode,
funcName = "valueIn",
extraArguments = (ctx.javaType(value.dataType), valueArg) :: Nil)
ev.copy(code = s"""
${valueGen.code}
${ev.value} = false;
${ev.isNull} = ${valueGen.isNull};
if (!${ev.isNull}) {
${ctx.javaType(value.dataType)} $valueArg = ${valueGen.value};
$listCodes
)
}
""")
ev.copy(code =
s"""
|${valueGen.code}
|${ev.value} = false;
|${ev.isNull} = ${valueGen.isNull};
|if (!${ev.isNull}) {
| $javaDataType $valueArg = ${valueGen.value};
| do {
| $code
| } while (false);
|}
""".stripMargin)
}

override def sql: String = {
Expand Down