-
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
Changes from all commits
f6585f9
fe89b8d
54046d6
5fc8177
83b3f70
b33514c
8379143
6b808aa
5198955
d58c6af
edaebe5
ce1214d
4f3ade9
6019541
75d1115
36d6bc8
95ffe86
a1d45e8
0df39fc
0d7309b
bc35206
5fcc249
d937038
303f991
d27ec50
b3d23fa
ddc752a
9b8dc3a
e257137
8bf1236
74b105e
32212bb
9422128
6e3c366
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * 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.reflect.ClassTag | ||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkContext} | ||
| import org.apache.spark.internal.config.CATALOG_IMPLEMENTATION | ||
| 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[SharedState, SparkContext]( | ||
| SparkSession.sharedStateClassName(sparkContext.conf), | ||
| sparkContext)) | ||
| } | ||
|
|
||
| @transient | ||
| protected[sql] lazy val sessionState: SessionState = { | ||
| SparkSession.reflect[SessionState, SQLContext]( | ||
| SparkSession.sessionStateClassName(sparkContext.conf), | ||
| new SQLContext(self, isRootContext = false)) | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| private object SparkSession { | ||
|
|
||
| private def sharedStateClassName(conf: SparkConf): String = { | ||
| conf.get(CATALOG_IMPLEMENTATION) match { | ||
| case "hive" => "org.apache.spark.sql.hive.HiveSharedState" | ||
| case "in-memory" => classOf[SharedState].getCanonicalName | ||
| } | ||
| } | ||
|
|
||
| private def sessionStateClassName(conf: SparkConf): String = { | ||
| conf.get(CATALOG_IMPLEMENTATION) match { | ||
| case "hive" => "org.apache.spark.sql.hive.HiveSessionState" | ||
| case "in-memory" => classOf[SessionState].getCanonicalName | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 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)(implicit ctorArgTag: ClassTag[Arg]): T = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need a class tag. You can call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't work because there are places where we pass subclasses of |
||
| try { | ||
| val clazz = Utils.classForName(className) | ||
| val ctor = clazz.getDeclaredConstructor(ctorArgTag.runtimeClass) | ||
| ctor.newInstance(ctorArg).asInstanceOf[T] | ||
| } catch { | ||
| case NonFatal(e) => | ||
| throw new IllegalArgumentException(s"Error while instantiating '$className':", e) | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.
Should this be a class name?
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.
we use this for both
SharedStateandSessionState. If we want to use a class name then we need two configs.