Skip to content

Conversation

@zsxwing
Copy link
Member

@zsxwing zsxwing commented Dec 10, 2014

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

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

@zsxwing zsxwing changed the title Fix the initialization issue of 'codegenEnabled' [SPARK-4812][SQL] Fix the initialization issue of 'codegenEnabled' Dec 10, 2014
@SparkQA
Copy link

SparkQA commented Dec 10, 2014

Test build #24296 has started for PR 3660 at commit fab8658.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Dec 10, 2014

Test build #24296 has finished for PR 3660 at commit fab8658.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/24296/
Test FAILed.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 10, 2014

we should mark codegenEnabled as lazy.

lazy doesn't work because codegenEnabled has not been used before serialization. Fixed it in InMemoryColumnarTableScan and updated the description of this PR.

@SparkQA
Copy link

SparkQA commented Dec 10, 2014

Test build #24307 has started for PR 3660 at commit a3eea56.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Dec 10, 2014

Test build #24307 has finished for PR 3660 at commit a3eea56.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/24307/
Test PASSed.

@marmbrus
Copy link
Contributor

This is a good catch, but perhaps the real bug here is that we are overriding the sqlContext in InMemoryTableScan. Instead, what do you think about just removing that?

@zsxwing
Copy link
Member Author

zsxwing commented Dec 15, 2014

I heard from @liancheng about some plan of using two SchemaRDDs from different sqlContext together. Is the override sqlContext designed to support it? @liancheng since you added it in liancheng@3784105

@liancheng
Copy link
Contributor

@zsxwing I guess what you mentioned is the plan to support multiple data sources via the newly introduced external data source API? ��The commit you mentioned is irrelevant. In that commit I just want to ensure the SQLContext we used in InMemoryColumnarTableScan is the same one used by its child .

@zsxwing
Copy link
Member Author

zsxwing commented Dec 15, 2014

I guess what you mentioned is the plan to support multiple data sources via the newly introduced external data source API?

Yes.

In that commit I just want to ensure the SQLContext we used in InMemoryColumnarTableScan is the same one used by its child .

In which case, it won't be protected[spark] val sqlContext = SparkPlan.currentContext.get()? If they are always same, we can remove the override sqlContext.

@liancheng
Copy link
Contributor

Ah I see you point, so here we referenced a field overriden by subclass in the constructor of the parent class. Then I think it's generally not safe to allow sqlContext to be overriden. How about marking SparkPlan.sqlContext as final to prevent this?

@liancheng
Copy link
Contributor

Yes, we should remove it.

@SparkQA
Copy link

SparkQA commented Dec 15, 2014

Test build #24451 has started for PR 3660 at commit 1cbb623.

  • This patch merges cleanly.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 15, 2014

Done. Also updated the description of this PR and JIRA.

@SparkQA
Copy link

SparkQA commented Dec 15, 2014

Test build #24451 has finished for PR 3660 at commit 1cbb623.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/24451/
Test PASSed.

@asfgit asfgit closed this in 6530243 Dec 16, 2014
@marmbrus
Copy link
Contributor

Thanks! Merged to master.

@zsxwing zsxwing deleted the SPARK-4812 branch December 17, 2014 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants