-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14720][SPARK-13643] Remove HiveContext (step 1) #12485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f6585f9
[SPARK-14647][SQL] Group SQLContext/HiveContext state into SharedState
fe89b8d
Make HiveSessionState take in SQLContext, not HiveContext
54046d6
Move QueryExecution out of HiveContext
5fc8177
Merge branch 'master' of github.com:apache/spark into spark-session
83b3f70
Minor cleanup
b33514c
Implement SparkSession and use it to track state
8379143
Merge branch 'master' of github.com:apache/spark into spark-session
6b808aa
Clean up some TODO's and bad signatures
5198955
Move the bulk of HiveContext into SessionCatalog
d58c6af
Remove more things from HiveContext
edaebe5
Fix style
ce1214d
Merge branch 'master' of github.com:apache/spark into spark-session
4f3ade9
Minor fixes
6019541
Use in-memory catalog by default in tests
75d1115
Fix NPE when initializing HiveSessionState
36d6bc8
Fix the conf
95ffe86
Merge branch 'master' of github.com:apache/spark into spark-session
a1d45e8
Fix REPL in in-memory case
0df39fc
Fix tests: set "in-memory" in more places
0d7309b
Fix style
bc35206
Fix SQLExecutionSuite
5fcc249
Fix ParquetHadoopFsRelationSuite
d937038
Fix HiveUDFSuite + refactor TestHive
303f991
Make diff slightly smaller?
d27ec50
Fix test compile
b3d23fa
Merge branch 'master' of github.com:apache/spark into spark-session
ddc752a
Fix HiveResolutionSuite
9b8dc3a
Fix StatisticsSuite
e257137
Minor change
8bf1236
Fix HiveUDFSuite (and many others)
74b105e
Merge branch 'master' of github.com:apache/spark into spark-session
32212bb
Fix tests
yhuai 9422128
Merge branch 'master' of github.com:apache/spark into spark-session
6e3c366
Fix Python tests.
yhuai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql | ||
|
|
||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkContext} | ||
| import org.apache.spark.sql.internal.{SessionState, SharedState} | ||
| import org.apache.spark.util.Utils | ||
|
|
||
|
|
||
| /** | ||
| * The entry point to Spark execution. | ||
| */ | ||
| class SparkSession private( | ||
| sparkContext: SparkContext, | ||
| existingSharedState: Option[SharedState]) { self => | ||
|
|
||
| def this(sc: SparkContext) { | ||
| this(sc, None) | ||
| } | ||
|
|
||
| /** | ||
| * Start a new session where configurations, temp tables, temp functions etc. are isolated. | ||
| */ | ||
| def newSession(): SparkSession = { | ||
| // Note: materialize the shared state here to ensure the parent and child sessions are | ||
| // initialized with the same shared state. | ||
| new SparkSession(sparkContext, Some(sharedState)) | ||
| } | ||
|
|
||
| @transient | ||
| protected[sql] lazy val sharedState: SharedState = { | ||
| existingSharedState.getOrElse( | ||
| SparkSession.reflect(SparkSession.sharedStateClassName(sparkContext.conf), sparkContext)) | ||
| } | ||
|
|
||
| @transient | ||
| protected[sql] lazy val sessionState: SessionState = { | ||
| SparkSession.reflect( | ||
| SparkSession.sessionStateClassName(sparkContext.conf), | ||
| new SQLContext(self, isRootContext = false)) | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| private object SparkSession { | ||
|
|
||
| private val DEFAULT_SHARED_STATE_CLASS_NAME = "org.apache.spark.sql.hive.HiveSharedState" | ||
| private val DEFAULT_SESSION_STATE_CLASS_NAME = "org.apache.spark.sql.hive.HiveSessionState" | ||
|
|
||
| private def sharedStateClassName(conf: SparkConf): String = { | ||
| conf.getOption("spark.sql.catalogImplementation") match { | ||
| case Some("hive") => "org.apache.spark.sql.hive.HiveSharedState" | ||
| case Some("in-memory") => classOf[SharedState].getCanonicalName | ||
| case Some(unknown) => | ||
| throw new IllegalArgumentException( | ||
| s"Unexpected catalog implementation '$unknown'; must be 'hive' or 'in-memory'") | ||
| case None => DEFAULT_SHARED_STATE_CLASS_NAME | ||
| } | ||
| } | ||
|
|
||
| private def sessionStateClassName(conf: SparkConf): String = { | ||
| conf.getOption("spark.sql.catalogImplementation") match { | ||
| case Some("hive") => "org.apache.spark.sql.hive.HiveSessionState" | ||
| case Some("in-memory") => classOf[SessionState].getCanonicalName | ||
| case Some(unknown) => | ||
| throw new IllegalArgumentException( | ||
| s"Unexpected catalog implementation '$unknown'; must be 'hive' or 'in-memory'") | ||
| case None => DEFAULT_SESSION_STATE_CLASS_NAME | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to create an instance of [[T]] using a single-arg constructor that | ||
| * accepts an [[Arg]]. | ||
| */ | ||
| private def reflect[T, Arg <: AnyRef](className: String, ctorArg: Arg): T = { | ||
| try { | ||
| val clazz = Utils.classForName(className) | ||
| val ctor = clazz.getDeclaredConstructor(ctorArg.getClass) | ||
| ctor.newInstance(ctorArg).asInstanceOf[T] | ||
| } catch { | ||
| case NonFatal(e) => | ||
| throw new IllegalArgumentException(s"Error while instantiating '$className':", e) | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we also need to change this?