This is an automated email from the ASF dual-hosted git repository.

bowenliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 34e79b419 [KYUUBI #4917][Bug][AUTHZ] Table owner undefied in Iceberg 
1.3.0 on Spark 3.4
34e79b419 is described below

commit 34e79b419592a4dd2c2fa96983b352c348e3bcce
Author: zhouyifan279 <[email protected]>
AuthorDate: Fri Jun 9 15:37:32 2023 +0800

    [KYUUBI #4917][Bug][AUTHZ] Table owner undefied in Iceberg 1.3.0 on Spark 
3.4
    
    ### _Why are the changes needed?_
    Fix #4917
    - support extracting table owner from `ResolvedIdentifier`
    
    ### _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
    <img width="1266" alt="image" 
src="https://github.com/apache/kyuubi/assets/88070094/e3066d0e-7a14-41da-96f6-032a5c53780f";>
    
    Closes #4941 from zhouyifan279/drop-table.
    
    Closes #4917
    
    b2207ed17 [zhouyifan279] [KYUUBI #4917][Bug][AUTHZ] Table owner undefied in 
Iceberg 1.3.0 on Spark 3.4
    bc4661a13 [zhouyifan279] [KYUUBI #4917][Bug][AUTHZ] Table owner undefied in 
Iceberg 1.3.0 on Spark 3.4
    
    Authored-by: zhouyifan279 <[email protected]>
    Signed-off-by: liangbowen <[email protected]>
---
 .../plugin/spark/authz/serde/tableExtractors.scala     | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

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 a8a08ed93..9a4435d5a 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
@@ -51,6 +51,21 @@ object TableExtractor {
     val properties = invokeAs[JMap[String, String]](table, 
"properties").asScala
     properties.get("owner")
   }
+
+  def getOwner(spark: SparkSession, catalogName: String, tableIdent: AnyRef): 
Option[String] = {
+    try {
+      val catalogManager = invokeAs[AnyRef](spark.sessionState, 
"catalogManager")
+      val catalog = invokeAs[AnyRef](catalogManager, "catalog", 
(classOf[String], catalogName))
+      val table = invokeAs[AnyRef](
+        catalog,
+        "loadTable",
+        (Class.forName("org.apache.spark.sql.connector.catalog.Identifier"), 
tableIdent))
+      getOwner(table)
+    } catch {
+      // Exception may occur due to invalid reflection or table not found
+      case _: Exception => None
+    }
+  }
 }
 
 /**
@@ -177,7 +192,8 @@ class ResolvedIdentifierTableExtractor extends 
TableExtractor {
         val catalog = 
lookupExtractor[CatalogPluginCatalogExtractor].apply(catalogVal)
         val identifier = invokeAs[AnyRef](v1, "identifier")
         val maybeTable = 
lookupExtractor[IdentifierTableExtractor].apply(spark, identifier)
-        maybeTable.map(_.copy(catalog = catalog))
+        val owner = catalog.flatMap(name => TableExtractor.getOwner(spark, 
name, identifier))
+        maybeTable.map(_.copy(catalog = catalog, owner = owner))
       case _ => None
     }
   }

Reply via email to