Skip to content

Commit

Permalink
[KYUUBI apache#4522] use:catalog should execute before than `use:da…
Browse files Browse the repository at this point in the history
…tabase`

### _Why are the changes needed?_

close apache#4522

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request

Closes apache#4648 from lsm1/fix/kyuubi_4522.

Closes apache#4522

e060468 [senmiaoliu] use foreach
bd83d66 [senmiaoliu] spilt narmalizedConf
4d8445a [senmiaoliu] avoid sort
eda34d4 [senmiaoliu] use catalog first

Authored-by: senmiaoliu <senmiaoliu@trip.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
  • Loading branch information
lsm1 authored and pan3793 committed Apr 4, 2023
1 parent d7c1c94 commit f0796ec
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,34 @@ class FlinkSessionImpl(

override def open(): Unit = {
executor.openSession(handle.identifier.toString)
normalizedConf.foreach {
case ("use:catalog", catalog) =>
val tableEnv = sessionContext.getExecutionContext.getTableEnvironment
try {
tableEnv.useCatalog(catalog)
} catch {
case NonFatal(e) =>

val (useCatalogAndDatabaseConf, otherConf) = normalizedConf.partition { case (k, _) =>
Array("use:catalog", "use:database").contains(k)
}

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").foreach { database =>
val tableEnv = sessionContext.getExecutionContext.getTableEnvironment
try {
tableEnv.useDatabase(database)
} catch {
case NonFatal(e) =>
if (database != "default") {
throw e
}
case ("use:database", database) =>
val tableEnv = sessionContext.getExecutionContext.getTableEnvironment
try {
tableEnv.useDatabase(database)
} catch {
case NonFatal(e) =>
if (database != "default") {
throw e
}
}
}
}
}

otherConf.foreach {
case (key, value) => setModifiableConfig(key, value)
}
super.open()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ class SparkSessionImpl(
private val sessionEvent = SessionEvent(this)

override def open(): Unit = {
normalizedConf.foreach {
case ("use:catalog", catalog) =>
try {
SparkCatalogShim().setCurrentCatalog(spark, catalog)
} catch {
case e if e.getMessage.contains("Cannot find catalog plugin class for catalog") =>
warn(e.getMessage())
}
case ("use:database", database) =>
try {
SparkCatalogShim().setCurrentDatabase(spark, database)
} catch {
case e
if database == "default" && e.getMessage != null &&
e.getMessage.contains("not found") =>
}

val (useCatalogAndDatabaseConf, otherConf) = normalizedConf.partition { case (k, _) =>
Array("use:catalog", "use:database").contains(k)
}

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").foreach { database =>
try {
SparkCatalogShim().setCurrentDatabase(spark, database)
} catch {
case e
if database == "default" && e.getMessage != null &&
e.getMessage.contains("not found") =>
}
}

otherConf.foreach {
case (key, value) => setModifiableConfig(key, value)
}
KDFRegistry.registerAll(spark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f0796ec

Please sign in to comment.