diff options
author | zsxwing <zsxwing@gmail.com> | 2014-12-16 14:13:40 -0800 |
---|---|---|
committer | Michael Armbrust <michael@databricks.com> | 2014-12-16 14:13:40 -0800 |
commit | 6530243a52b05007e566d458cd8f075e851e91f1 (patch) | |
tree | 41556cccdbbfb39020e721065f1b8c578ba8f19c /sql/core/src | |
parent | dc8280dcca7b54793a3db644f74fd33460960d4a (diff) | |
download | spark-6530243a52b05007e566d458cd8f075e851e91f1.tar.gz spark-6530243a52b05007e566d458cd8f075e851e91f1.tar.bz2 spark-6530243a52b05007e566d458cd8f075e851e91f1.zip |
[SPARK-4812][SQL] Fix the initialization issue of 'codegenEnabled'
The problem is `codegenEnabled` is `val`, but it uses a `val` `sqlContext`, which can be override by subclasses. Here is a simple example to show this issue.
```Scala
scala> :paste
// Entering paste mode (ctrl-D to finish)
abstract class Foo {
protected val sqlContext = "Foo"
val codegenEnabled: Boolean = {
println(sqlContext) // it will call subclass's `sqlContext` which has not yet been initialized.
if (sqlContext != null) {
true
} else {
false
}
}
}
class Bar extends Foo {
override val sqlContext = "Bar"
}
println(new Bar().codegenEnabled)
// Exiting paste mode, now interpreting.
null
false
defined class Foo
defined class Bar
```
We should make `sqlContext` `final` to prevent subclasses from overriding it incorrectly.
Author: zsxwing <zsxwing@gmail.com>
Closes #3660 from zsxwing/SPARK-4812 and squashes the following commits:
1cbb623 [zsxwing] Make `sqlContext` final to prevent subclasses from overriding it incorrectly
Diffstat (limited to 'sql/core/src')
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/columnar/InMemoryColumnarTableScan.scala | 2 | ||||
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala | 2 |
2 files changed, 1 insertions, 3 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/columnar/InMemoryColumnarTableScan.scala b/sql/core/src/main/scala/org/apache/spark/sql/columnar/InMemoryColumnarTableScan.scala index 0cebe823b2..1e432485c4 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/columnar/InMemoryColumnarTableScan.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/columnar/InMemoryColumnarTableScan.scala @@ -175,8 +175,6 @@ private[sql] case class InMemoryColumnarTableScan( relation: InMemoryRelation) extends LeafNode { - @transient override val sqlContext = relation.child.sqlContext - override def output: Seq[Attribute] = attributes private def statsFor(a: Attribute) = relation.partitionStatistics.forAttribute(a) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala index 4cd8e7d657..017c78d2c6 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala @@ -44,7 +44,7 @@ abstract class SparkPlan extends QueryPlan[SparkPlan] with Logging with Serializ * populated by the query planning infrastructure. */ @transient - protected[spark] val sqlContext = SparkPlan.currentContext.get() + protected[spark] final val sqlContext = SparkPlan.currentContext.get() protected def sparkContext = sqlContext.sparkContext |