You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "bowenliang123 (via GitHub)" <gi...@apache.org> on 2023/06/01 05:42:36 UTC

[GitHub] [kyuubi] bowenliang123 commented on a diff in pull request #4914: [AUTHZ] Reuse extractor singleton instance with generalized getter for supported extractor types

bowenliang123 commented on code in PR #4914:
URL: https://github.com/apache/kyuubi/pull/4914#discussion_r1212603841


##########
extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/package.scala:
##########
@@ -82,4 +91,33 @@ package object serde {
       .map(s => s.operationType)
       .getOrElse(QUERY)
   }
+
+  def getExtractor[T <: Extractor](implicit ct: ClassTag[T]): T =
+    getExtractor[T](extractorKey = null)(ct)
+
+  /**
+   * get extractor instance by extractor class name
+   * @param extractorKey explicitly load extractor by its simple class name.
+   *                           null by default means get extractor by extractor class.
+   * @param ct class tag of extractor class type
+   * @tparam T extractor class type
+   * @return
+   */
+  def getExtractor[T <: Extractor](extractorKey: String = null)(
+      implicit ct: ClassTag[T]): T = {
+    val extractorClass = ct.runtimeClass
+    val extractors: Map[String, Extractor] = extractorClass match {
+      case c if classOf[CatalogExtractor].isAssignableFrom(c) => catalogExtractors
+      case c if classOf[DatabaseExtractor].isAssignableFrom(c) => dbExtractors
+      case c if classOf[TableExtractor].isAssignableFrom(c) => tableExtractors
+      case c if classOf[TableTypeExtractor].isAssignableFrom(c) => tableTypeExtractors
+      case c if classOf[ColumnExtractor].isAssignableFrom(c) => columnExtractors
+      case c if classOf[QueryExtractor].isAssignableFrom(c) => queryExtractors
+      case c if classOf[FunctionExtractor].isAssignableFrom(c) => functionExtractors
+      case c if classOf[FunctionTypeExtractor].isAssignableFrom(c) => functionTypeExtractors
+      case c if classOf[ActionTypeExtractor].isAssignableFrom(c) => actionTypeExtractors

Review Comment:
   Is there any better way in more scala style for matching class type here ?
   Or shall we just load the extractor from all the possible extractor mapss regardless of theextractor type here.
   cc @yaooqinn @pan3793 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org