You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/07/12 15:03:26 UTC

[GitHub] [spark] brkyvz commented on a change in pull request #25104: [SPARK-28341][SQL] refine the v2 session catalog config

brkyvz commented on a change in pull request #25104: [SPARK-28341][SQL] refine the v2 session catalog config
URL: https://github.com/apache/spark/pull/25104#discussion_r303023250
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalog/v2/CatalogManager.scala
 ##########
 @@ -0,0 +1,88 @@
+/*
+ * 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.catalog.v2
+
+import scala.collection.mutable
+import scala.util.control.NonFatal
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.catalyst.catalog.SessionCatalog
+import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf}
+import org.apache.spark.util.Utils
+
+/**
+ * A thread-safe manager for [[CatalogPlugin]]s. It tracks all the registered catalogs, and allow
+ * the caller to look up a catalog by name.
+ */
+class CatalogManager(conf: SQLConf, val sessionCatalog: SessionCatalog) extends Logging {
+
+  /**
+   * Tracks all the registered catalogs.
+   */
+  private val catalogs = mutable.HashMap.empty[String, CatalogPlugin]
+
+  /**
+   * Looks up a catalog by name.
+   */
+  def catalog(name: String): CatalogPlugin = synchronized {
+    catalogs.getOrElseUpdate(name, Catalogs.load(name, conf))
+  }
+
+  /**
+   * Returns the default catalog specified by config.
+   */
+  // TODO(cloud-fan): This needs to be a def instead of val, because the default catalog config is
+  // a session config which can change at runtime. Shall we make it a static config instead?
+  def defaultCatalog(): Option[CatalogPlugin] = {
+    conf.defaultV2Catalog.flatMap { catalogName =>
+      try {
+        Some(catalog(catalogName))
+      } catch {
+        case NonFatal(e) =>
+          logError(s"Cannot load default v2 catalog: $catalogName", e)
+          None
+      }
+    }
+  }
+
+  /**
+   * Returns the v2 session catalog specified by config.
+   */
+  lazy val v2SessionCatalog: TableCatalog = {
+    val implClsName = conf.getConf(StaticSQLConf.V2_SESSION_CATALOG_IMPL)
 
 Review comment:
   Why does this need to be a StaticConf? Wouldn't this make it impossible to plug in your own session catalog when using the Spark Shell for example?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org