Skip to content

Commit 7ce8e39

Browse files
committed
Avoid hard-coded config: spark.sql.globalTempDatabase
1 parent 7cbe01e commit 7ce8e39

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import org.apache.spark.sql.catalyst.parser.{CatalystSqlParser, ParserInterface}
3939
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, SubqueryAlias, View}
4040
import org.apache.spark.sql.catalyst.util.StringUtils
4141
import org.apache.spark.sql.internal.SQLConf
42+
import org.apache.spark.sql.internal.StaticSQLConf.GLOBAL_TEMP_DATABASE
4243
import org.apache.spark.sql.types.StructType
4344
import org.apache.spark.util.Utils
4445

@@ -71,7 +72,7 @@ class SessionCatalog(
7172
conf: SQLConf) {
7273
this(
7374
() => externalCatalog,
74-
() => new GlobalTempViewManager("global_temp"),
75+
() => new GlobalTempViewManager(conf.getConf(GLOBAL_TEMP_DATABASE)),
7576
functionRegistry,
7677
conf,
7778
new Configuration(),

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/StaticSQLConf.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.spark.sql.internal
1919

20+
import java.util.Locale
21+
2022
import org.apache.spark.util.Utils
2123

2224

@@ -42,6 +44,7 @@ object StaticSQLConf {
4244
val GLOBAL_TEMP_DATABASE = buildStaticConf("spark.sql.globalTempDatabase")
4345
.internal()
4446
.stringConf
47+
.transform(_.toLowerCase(Locale.ROOT))
4548
.createWithDefault("global_temp")
4649

4750
// This is used to control when we will split a schema's JSON string to multiple pieces

sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private[sql] class SharedState(
158158
// System preserved database should not exists in metastore. However it's hard to guarantee it
159159
// for every session, because case-sensitivity differs. Here we always lowercase it to make our
160160
// life easier.
161-
val globalTempDB = conf.get(GLOBAL_TEMP_DATABASE).toLowerCase(Locale.ROOT)
161+
val globalTempDB = conf.get(GLOBAL_TEMP_DATABASE)
162162
if (externalCatalog.databaseExists(globalTempDB)) {
163163
throw new SparkException(
164164
s"$globalTempDB is a system preserved database, please rename your existing database " +

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import org.apache.spark.sql.functions._
3939
import org.apache.spark.sql.hive.{HiveExternalCatalog, HiveUtils}
4040
import org.apache.spark.sql.hive.test.{HiveTestUtils, TestHiveSingleton}
4141
import org.apache.spark.sql.internal.SQLConf
42+
import org.apache.spark.sql.internal.StaticSQLConf.GLOBAL_TEMP_DATABASE
4243
import org.apache.spark.sql.test.SQLTestUtils
4344
import org.apache.spark.sql.types._
4445
import org.apache.spark.unsafe.types.CalendarInterval
@@ -73,13 +74,13 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
7374
test("query global temp view") {
7475
val df = Seq(1).toDF("i1")
7576
df.createGlobalTempView("tbl1")
76-
val global_temp_db = spark.conf.get("spark.sql.globalTempDatabase")
77+
val global_temp_db = spark.conf.get(GLOBAL_TEMP_DATABASE)
7778
checkAnswer(spark.sql(s"select * from ${global_temp_db}.tbl1"), Row(1))
7879
spark.sql(s"drop view ${global_temp_db}.tbl1")
7980
}
8081

8182
test("non-existent global temp view") {
82-
val global_temp_db = spark.conf.get("spark.sql.globalTempDatabase")
83+
val global_temp_db = spark.conf.get(GLOBAL_TEMP_DATABASE)
8384
val message = intercept[AnalysisException] {
8485
spark.sql(s"select * from ${global_temp_db}.nonexistentview")
8586
}.getMessage

0 commit comments

Comments
 (0)