Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-4812

SparkPlan.codegenEnabled may be initialized to a wrong value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.3.0
    • SQL
    • None

    Description

      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> :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
      
      scala> 
      

      We should make `sqlContext` `final` to prevent subclasses from overriding it incorrectly.

      Attachments

        Activity

          People

            zsxwing Shixiong Zhu
            zsxwing Shixiong Zhu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: