diff --git a/externals/kyuubi-flink-sql-engine/src/main/scala/org/apache/kyuubi/engine/flink/session/FlinkSessionImpl.scala b/externals/kyuubi-flink-sql-engine/src/main/scala/org/apache/kyuubi/engine/flink/session/FlinkSessionImpl.scala index bcfba3b7350..a4b6a8a902b 100644 --- a/externals/kyuubi-flink-sql-engine/src/main/scala/org/apache/kyuubi/engine/flink/session/FlinkSessionImpl.scala +++ b/externals/kyuubi-flink-sql-engine/src/main/scala/org/apache/kyuubi/engine/flink/session/FlinkSessionImpl.scala @@ -62,30 +62,26 @@ class FlinkSessionImpl( Array("use:catalog", "use:database").contains(k) } - useCatalogAndDatabaseConf.get("use:catalog") match { - case Some(catalog) => - val tableEnv = sessionContext.getExecutionContext.getTableEnvironment - try { - tableEnv.useCatalog(catalog) - } catch { - case NonFatal(e) => - throw e - } - case None => + useCatalogAndDatabaseConf.get("use:catalog").foreach { catalog => + val tableEnv = sessionContext.getExecutionContext.getTableEnvironment + try { + tableEnv.useCatalog(catalog) + } catch { + case NonFatal(e) => + throw e + } } - useCatalogAndDatabaseConf.get("use:database") match { - case Some(database) => - val tableEnv = sessionContext.getExecutionContext.getTableEnvironment - try { - tableEnv.useDatabase(database) - } catch { - case NonFatal(e) => - if (database != "default") { - throw e - } - } - case None => + useCatalogAndDatabaseConf.get("use:database").foreach { database => + val tableEnv = sessionContext.getExecutionContext.getTableEnvironment + try { + tableEnv.useDatabase(database) + } catch { + case NonFatal(e) => + if (database != "default") { + throw e + } + } } otherConf.foreach { diff --git a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSessionImpl.scala b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSessionImpl.scala index c84127482ad..96fc43e857d 100644 --- a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSessionImpl.scala +++ b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSessionImpl.scala @@ -59,27 +59,23 @@ class SparkSessionImpl( Array("use:catalog", "use:database").contains(k) } - useCatalogAndDatabaseConf.get("use:catalog") match { - case Some(catalog) => - try { - SparkCatalogShim().setCurrentCatalog(spark, catalog) - } catch { - case e if e.getMessage.contains("Cannot find catalog plugin class for catalog") => - warn(e.getMessage()) - } - case None => + useCatalogAndDatabaseConf.get("use:catalog").foreach { catalog => + try { + SparkCatalogShim().setCurrentCatalog(spark, catalog) + } catch { + case e if e.getMessage.contains("Cannot find catalog plugin class for catalog") => + warn(e.getMessage()) + } } - useCatalogAndDatabaseConf.get("use:database") match { - case Some(database) => - try { - SparkCatalogShim().setCurrentDatabase(spark, database) - } catch { - case e - if database == "default" && e.getMessage != null && - e.getMessage.contains("not found") => - } - case None => + useCatalogAndDatabaseConf.get("use:database").foreach { database => + try { + SparkCatalogShim().setCurrentDatabase(spark, database) + } catch { + case e + if database == "default" && e.getMessage != null && + e.getMessage.contains("not found") => + } } otherConf.foreach { diff --git a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala index 81f973b1b5e..1a96bed73f5 100644 --- a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala +++ b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala @@ -57,10 +57,14 @@ class TrinoSessionImpl( private val sessionEvent = TrinoSessionEvent(this) override def open(): Unit = { - normalizedConf.foreach { + + val (useCatalogAndDatabaseConf, _) = normalizedConf.partition { case (k, _) => + Array("use:catalog", "use:database").contains(k) + } + + useCatalogAndDatabaseConf.foreach { case ("use:catalog", catalog) => catalogName = catalog case ("use:database", database) => databaseName = database - case _ => // do nothing } val httpClient = new OkHttpClient.Builder().build()