[KYUUBI #4915] Adapt database not exist error message change for Spark 3.4

### _Why are the changes needed?_

Spark is migrating to the error class framework, in SPARK-40360(fixed in 3.4.0) SCHEMA_NOT_FOUND was introduced, which changes the output of the error message on switching a not existing database.

### _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

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

Closes #4915 from pan3793/schema-not-found.

Closes #4915

c0e03feaf [Cheng Pan] nit
0ee0deada [Cheng Pan] SCHEMA_NOT_FOUND

Authored-by: Cheng Pan <chengpan@apache.org>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Cheng Pan 2023-06-01 13:47:37 +08:00
parent c194e82573
commit 00b32a0381
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D

View File

@ -17,6 +17,7 @@
package org.apache.kyuubi.engine.spark.session
import org.apache.commons.lang3.StringUtils
import org.apache.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue, TProtocolVersion}
import org.apache.spark.sql.{AnalysisException, SparkSession}
@ -28,7 +29,7 @@ import org.apache.kyuubi.engine.spark.shim.SparkCatalogShim
import org.apache.kyuubi.engine.spark.udf.KDFRegistry
import org.apache.kyuubi.events.EventBus
import org.apache.kyuubi.operation.{Operation, OperationHandle}
import org.apache.kyuubi.session.{AbstractSession, SessionHandle, SessionManager, USE_CATALOG, USE_DATABASE}
import org.apache.kyuubi.session._
class SparkSessionImpl(
protocol: TProtocolVersion,
@ -73,8 +74,8 @@ class SparkSessionImpl(
SparkCatalogShim().setCurrentDatabase(spark, database)
} catch {
case e
if database == "default" && e.getMessage != null &&
e.getMessage.contains("not found") =>
if database == "default" &&
StringUtils.containsAny(e.getMessage, "not found", "SCHEMA_NOT_FOUND") =>
}
}