You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2015/07/30 06:24:49 UTC
spark git commit: [SPARK-9462][SQL] Initialize nondeterministic
expressions in code gen fallback mode.
Repository: spark
Updated Branches:
refs/heads/master 07fd7d364 -> 27850af52
[SPARK-9462][SQL] Initialize nondeterministic expressions in code gen fallback mode.
Author: Reynold Xin <rx...@databricks.com>
Closes #7767 from rxin/SPARK-9462 and squashes the following commits:
ef3e2d9 [Reynold Xin] Removed println
713ac3a [Reynold Xin] More unit tests.
bb5c334 [Reynold Xin] [SPARK-9462][SQL] Initialize nondeterministic expressions in code gen fallback mode.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/27850af5
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/27850af5
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/27850af5
Branch: refs/heads/master
Commit: 27850af5255352cebd933ed3cc3d82c9ff6e9b62
Parents: 07fd7d3
Author: Reynold Xin <rx...@databricks.com>
Authored: Wed Jul 29 21:24:47 2015 -0700
Committer: Reynold Xin <rx...@databricks.com>
Committed: Wed Jul 29 21:24:47 2015 -0700
----------------------------------------------------------------------
.../expressions/codegen/CodegenFallback.scala | 7 ++-
.../codegen/CodegenExpressionCachingSuite.scala | 46 +++++++++++++++++---
2 files changed, 47 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/27850af5/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala
index 6b187f0..3492d2c 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala
@@ -17,7 +17,7 @@
package org.apache.spark.sql.catalyst.expressions.codegen
-import org.apache.spark.sql.catalyst.expressions.Expression
+import org.apache.spark.sql.catalyst.expressions.{Nondeterministic, Expression}
/**
* A trait that can be used to provide a fallback mode for expression code generation.
@@ -25,6 +25,11 @@ import org.apache.spark.sql.catalyst.expressions.Expression
trait CodegenFallback extends Expression {
protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
+ foreach {
+ case n: Nondeterministic => n.setInitialValues()
+ case _ =>
+ }
+
ctx.references += this
val objectTerm = ctx.freshName("obj")
s"""
http://git-wip-us.apache.org/repos/asf/spark/blob/27850af5/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenExpressionCachingSuite.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenExpressionCachingSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenExpressionCachingSuite.scala
index 866bf90..2d3f98d 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenExpressionCachingSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenExpressionCachingSuite.scala
@@ -19,7 +19,7 @@ package org.apache.spark.sql.catalyst.expressions.codegen
import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.InternalRow
-import org.apache.spark.sql.catalyst.expressions.{UnsafeProjection, LeafExpression}
+import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.types.{BooleanType, DataType}
/**
@@ -27,7 +27,32 @@ import org.apache.spark.sql.types.{BooleanType, DataType}
*/
class CodegenExpressionCachingSuite extends SparkFunSuite {
- test("GenerateUnsafeProjection") {
+ test("GenerateUnsafeProjection should initialize expressions") {
+ // Use an Add to wrap two of them together in case we only initialize the top level expressions.
+ val expr = And(NondeterministicExpression(), NondeterministicExpression())
+ val instance = UnsafeProjection.create(Seq(expr))
+ assert(instance.apply(null).getBoolean(0) === false)
+ }
+
+ test("GenerateProjection should initialize expressions") {
+ val expr = And(NondeterministicExpression(), NondeterministicExpression())
+ val instance = GenerateProjection.generate(Seq(expr))
+ assert(instance.apply(null).getBoolean(0) === false)
+ }
+
+ test("GenerateMutableProjection should initialize expressions") {
+ val expr = And(NondeterministicExpression(), NondeterministicExpression())
+ val instance = GenerateMutableProjection.generate(Seq(expr))()
+ assert(instance.apply(null).getBoolean(0) === false)
+ }
+
+ test("GeneratePredicate should initialize expressions") {
+ val expr = And(NondeterministicExpression(), NondeterministicExpression())
+ val instance = GeneratePredicate.generate(expr)
+ assert(instance.apply(null) === false)
+ }
+
+ test("GenerateUnsafeProjection should not share expression instances") {
val expr1 = MutableExpression()
val instance1 = UnsafeProjection.create(Seq(expr1))
assert(instance1.apply(null).getBoolean(0) === false)
@@ -39,7 +64,7 @@ class CodegenExpressionCachingSuite extends SparkFunSuite {
assert(instance2.apply(null).getBoolean(0) === true)
}
- test("GenerateProjection") {
+ test("GenerateProjection should not share expression instances") {
val expr1 = MutableExpression()
val instance1 = GenerateProjection.generate(Seq(expr1))
assert(instance1.apply(null).getBoolean(0) === false)
@@ -51,7 +76,7 @@ class CodegenExpressionCachingSuite extends SparkFunSuite {
assert(instance2.apply(null).getBoolean(0) === true)
}
- test("GenerateMutableProjection") {
+ test("GenerateMutableProjection should not share expression instances") {
val expr1 = MutableExpression()
val instance1 = GenerateMutableProjection.generate(Seq(expr1))()
assert(instance1.apply(null).getBoolean(0) === false)
@@ -63,7 +88,7 @@ class CodegenExpressionCachingSuite extends SparkFunSuite {
assert(instance2.apply(null).getBoolean(0) === true)
}
- test("GeneratePredicate") {
+ test("GeneratePredicate should not share expression instances") {
val expr1 = MutableExpression()
val instance1 = GeneratePredicate.generate(expr1)
assert(instance1.apply(null) === false)
@@ -77,6 +102,17 @@ class CodegenExpressionCachingSuite extends SparkFunSuite {
}
+/**
+ * An expression that's non-deterministic and doesn't support codegen.
+ */
+case class NondeterministicExpression()
+ extends LeafExpression with Nondeterministic with CodegenFallback {
+ override protected def initInternal(): Unit = { }
+ override protected def evalInternal(input: InternalRow): Any = false
+ override def nullable: Boolean = false
+ override def dataType: DataType = BooleanType
+}
+
/**
* An expression with mutable state so we can change it freely in our test suite.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org