diff options
author | Cheng Hao <hao.cheng@intel.com> | 2014-12-16 21:18:39 -0800 |
---|---|---|
committer | Michael Armbrust <michael@databricks.com> | 2014-12-16 21:18:39 -0800 |
commit | 0aa834adeaf4e31d63198e4197dc592790d3d0cc (patch) | |
tree | 9ee56bf4f1d5762ff3c46dc17b41ffea0bb4f013 | |
parent | 3b395e10510782474789c9098084503f98ca4830 (diff) | |
download | spark-0aa834adeaf4e31d63198e4197dc592790d3d0cc.tar.gz spark-0aa834adeaf4e31d63198e4197dc592790d3d0cc.tar.bz2 spark-0aa834adeaf4e31d63198e4197dc592790d3d0cc.zip |
[SPARK-4744] [SQL] Short circuit evaluation for AND & OR in CodeGen
Author: Cheng Hao <hao.cheng@intel.com>
Closes #3606 from chenghao-intel/codegen_short_circuit and squashes the following commits:
f466303 [Cheng Hao] short circuit for AND & OR
-rw-r--r-- | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala index ab71e15e1f..48727d5e90 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala @@ -314,20 +314,20 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin val eval1 = expressionEvaluator(e1) val eval2 = expressionEvaluator(e2) - eval1.code ++ eval2.code ++ q""" + ..${eval1.code} var $nullTerm = false var $primitiveTerm: ${termForType(BooleanType)} = false - if ((!${eval1.nullTerm} && !${eval1.primitiveTerm}) || - (!${eval2.nullTerm} && !${eval2.primitiveTerm})) { - $nullTerm = false - $primitiveTerm = false - } else if (${eval1.nullTerm} || ${eval2.nullTerm} ) { - $nullTerm = true + if (!${eval1.nullTerm} && ${eval1.primitiveTerm} == false) { } else { - $nullTerm = false - $primitiveTerm = true + ..${eval2.code} + if (!${eval2.nullTerm} && ${eval2.primitiveTerm} == false) { + } else if (!${eval1.nullTerm} && !${eval2.nullTerm}) { + $primitiveTerm = true + } else { + $nullTerm = true + } } """.children @@ -335,20 +335,22 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin val eval1 = expressionEvaluator(e1) val eval2 = expressionEvaluator(e2) - eval1.code ++ eval2.code ++ q""" + ..${eval1.code} var $nullTerm = false var $primitiveTerm: ${termForType(BooleanType)} = false - if ((!${eval1.nullTerm} && ${eval1.primitiveTerm}) || - (!${eval2.nullTerm} && ${eval2.primitiveTerm})) { - $nullTerm = false + if (!${eval1.nullTerm} && ${eval1.primitiveTerm}) { $primitiveTerm = true - } else if (${eval1.nullTerm} || ${eval2.nullTerm} ) { - $nullTerm = true } else { - $nullTerm = false - $primitiveTerm = false + ..${eval2.code} + if (!${eval2.nullTerm} && ${eval2.primitiveTerm}) { + $primitiveTerm = true + } else if (!${eval1.nullTerm} && !${eval2.nullTerm}) { + $primitiveTerm = false + } else { + $nullTerm = true + } } """.children @@ -373,7 +375,6 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin } else if (${eval2.primitiveTerm} == 0) $nullTerm = true else { - $nullTerm = false $primitiveTerm = ${eval1.primitiveTerm} / ${eval2.primitiveTerm} } """.children @@ -494,7 +495,6 @@ abstract class CodeGenerator[InType <: AnyRef, OutType <: AnyRef] extends Loggin $nullTerm = ${eval1.nullTerm} $primitiveTerm = ${eval1.primitiveTerm} } else { - $nullTerm = false if (${eval1.primitiveTerm} > ${eval2.primitiveTerm}) { $primitiveTerm = ${eval1.primitiveTerm} } else { |