-
Notifications
You must be signed in to change notification settings - Fork 28k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-14647][SQL] Group SQLContext/HiveContext state into SharedState
## What changes were proposed in this pull request? This patch adds a SharedState that groups state shared across multiple SQLContexts. This is analogous to the SessionState added in SPARK-13526 that groups session-specific state. This cleanup makes the constructors of the contexts simpler and ultimately allows us to remove HiveContext in the near future. ## How was this patch tested? Existing tests. Author: Yin Huai <yhuai@databricks.com> Closes #12463 from yhuai/sharedState.
- Loading branch information
Showing
8 changed files
with
175 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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 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
47 changes: 47 additions & 0 deletions
47
sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala
This file contains 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,47 @@ | ||
/* | ||
* 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.internal | ||
|
||
import org.apache.spark.SparkContext | ||
import org.apache.spark.sql.SQLContext | ||
import org.apache.spark.sql.catalyst.catalog.{ExternalCatalog, InMemoryCatalog} | ||
import org.apache.spark.sql.execution.CacheManager | ||
import org.apache.spark.sql.execution.ui.SQLListener | ||
|
||
|
||
/** | ||
* A class that holds all state shared across sessions in a given [[SQLContext]]. | ||
*/ | ||
private[sql] class SharedState(val sparkContext: SparkContext) { | ||
|
||
/** | ||
* Class for caching query results reused in future executions. | ||
*/ | ||
val cacheManager: CacheManager = new CacheManager | ||
|
||
/** | ||
* A listener for SQL-specific [[org.apache.spark.scheduler.SparkListenerEvent]]s. | ||
*/ | ||
val listener: SQLListener = SQLContext.createListenerAndUI(sparkContext) | ||
|
||
/** | ||
* A catalog that interacts with external systems. | ||
*/ | ||
lazy val externalCatalog: ExternalCatalog = new InMemoryCatalog | ||
|
||
} |
This file contains 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 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
53 changes: 53 additions & 0 deletions
53
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveSharedState.scala
This file contains 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,53 @@ | ||
/* | ||
* 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.hive | ||
|
||
import org.apache.spark.SparkContext | ||
import org.apache.spark.sql.hive.client.{HiveClient, HiveClientImpl} | ||
import org.apache.spark.sql.internal.SharedState | ||
|
||
|
||
/** | ||
* A class that holds all state shared across sessions in a given [[HiveContext]]. | ||
*/ | ||
private[hive] class HiveSharedState(override val sparkContext: SparkContext) | ||
extends SharedState(sparkContext) { | ||
|
||
// TODO: just share the IsolatedClientLoader instead of the client instances themselves | ||
|
||
/** | ||
* A Hive client used for execution. | ||
*/ | ||
val executionHive: HiveClientImpl = { | ||
HiveContext.newClientForExecution(sparkContext.conf, sparkContext.hadoopConfiguration) | ||
} | ||
|
||
/** | ||
* A Hive client used to interact with the metastore. | ||
*/ | ||
// This needs to be a lazy val at here because TestHiveSharedState is overriding it. | ||
lazy val metadataHive: HiveClient = { | ||
HiveContext.newClientForMetadata(sparkContext.conf, sparkContext.hadoopConfiguration) | ||
} | ||
|
||
/** | ||
* A catalog that interacts with the Hive metastore. | ||
*/ | ||
override lazy val externalCatalog = new HiveExternalCatalog(metadataHive) | ||
|
||
} |
Oops, something went wrong.