From c1a09214af25455d0389a3db3dc8a405b67bd043 Mon Sep 17 00:00:00 2001 From: caoyu Date: Thu, 18 Jul 2024 23:59:47 +0800 Subject: [PATCH] Optimising the 'database' capture logic --- .../spark/authz/serde/tableExtractors.scala | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala index 6cc33f30386..03506036d07 100644 --- a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala +++ b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala @@ -196,20 +196,17 @@ class DataSourceV2RelationTableExtractor extends TableExtractor { !isPathIdentifier(v2Relation.identifier.get.name(), spark) => val maybeCatalog = v2Relation.catalog.flatMap(catalogPlugin => lookupExtractor[CatalogPluginCatalogExtractor].apply(catalogPlugin)) - - val identifierDatabase = { - val maybeIdentifier = invokeAs[Option[AnyRef]](v2Relation, "identifier") - maybeIdentifier.flatMap { id => - lookupExtractor[IdentifierTableExtractor].apply(spark, id) - } match { - case Some(value) => value.database - case _ => None - } - } lookupExtractor[TableTableExtractor].apply(spark, v2Relation.table) .map { table => val maybeOwner = TableExtractor.getOwner(v2Relation) - val maybeDatabase = table.database.orElse(identifierDatabase) + val maybeDatabase: Option[String] = table.database match { + case Some(x) => Some(x) + case None => + val maybeIdentifier = invokeAs[Option[AnyRef]](v2Relation, "identifier") + maybeIdentifier.flatMap { id => + lookupExtractor[IdentifierTableExtractor].apply(spark, id) + }.flatMap(table => table.database) + } table.copy(catalog = maybeCatalog, database = maybeDatabase, owner = maybeOwner) } case _ => None