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/15 15:19:22 UTC

[GitHub] [kyuubi] bowenliang123 opened a new pull request, #4970: [WIP] Unified invokeAs

bowenliang123 opened a new pull request, #4970:
URL: https://github.com/apache/kyuubi/pull/4970

   <!--
   Thanks for sending a pull request!
   
   Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/CONTRIBUTING.html
     2. If the PR is related to an issue in https://github.com/apache/kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
   -->
   
   ### _Why are the changes needed?_
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you add a feature, you can talk about the use case of it.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   - comment https://github.com/apache/kyuubi/pull/4963#discussion_r1230490326
   - simplify reflection reflection method calling with unified `invokeAs` method for either declared, inherited, or static methods
   
   
   ### _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
   


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


[GitHub] [kyuubi] bowenliang123 commented on a diff in pull request #4970: Unified reflection methods invokeAs and getField

Posted by "bowenliang123 (via GitHub)" <gi...@apache.org>.
bowenliang123 commented on code in PR #4970:
URL: https://github.com/apache/kyuubi/pull/4970#discussion_r1231757156


##########
kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala:
##########
@@ -70,20 +78,26 @@ object ReflectUtils {
    * @return
    */
   def invokeAs[T](target: AnyRef, methodName: String, args: (Class[_], AnyRef)*): T = {
-    val targetClass = target.getClass
+    val (clz, obj) = getTargetClass(target)
     val argClasses = args.map(_._1)
     try {
-      DynMethods.builder(methodName)
-        .hiddenImpl(targetClass, argClasses: _*)
-        .buildChecked(target)
-        .invoke[T](args.map(_._2): _*)
+      val method = DynMethods.builder(methodName)
+        .hiddenImpl(clz, argClasses: _*)
+        .impl(clz, argClasses: _*)
+        .buildChecked
+      if (method.isStatic) {
+        method.asStatic.invoke[T](args.map(_._2): _*)

Review Comment:
   how about the static fields. Separate a method for them as well?



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


[GitHub] [kyuubi] bowenliang123 commented on a diff in pull request #4970: Unified reflection methods invokeAs and getField

Posted by "bowenliang123 (via GitHub)" <gi...@apache.org>.
bowenliang123 commented on code in PR #4970:
URL: https://github.com/apache/kyuubi/pull/4970#discussion_r1231757156


##########
kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala:
##########
@@ -70,20 +78,26 @@ object ReflectUtils {
    * @return
    */
   def invokeAs[T](target: AnyRef, methodName: String, args: (Class[_], AnyRef)*): T = {
-    val targetClass = target.getClass
+    val (clz, obj) = getTargetClass(target)
     val argClasses = args.map(_._1)
     try {
-      DynMethods.builder(methodName)
-        .hiddenImpl(targetClass, argClasses: _*)
-        .buildChecked(target)
-        .invoke[T](args.map(_._2): _*)
+      val method = DynMethods.builder(methodName)
+        .hiddenImpl(clz, argClasses: _*)
+        .impl(clz, argClasses: _*)
+        .buildChecked
+      if (method.isStatic) {
+        method.asStatic.invoke[T](args.map(_._2): _*)

Review Comment:
   how about the static fields. Separate a method for them as well?



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


[GitHub] [kyuubi] codecov-commenter commented on pull request #4970: [WIP] Unified invokeAs and getField

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #4970:
URL: https://github.com/apache/kyuubi/pull/4970#issuecomment-1593602054

   ## [Codecov](https://app.codecov.io/gh/apache/kyuubi/pull/4970?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#4970](https://app.codecov.io/gh/apache/kyuubi/pull/4970?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (696d979) into [master](https://app.codecov.io/gh/apache/kyuubi/commit/5ee96b5d063ec2b3545578c42b19620862461613?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (5ee96b5) will **not change** coverage.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@          Coverage Diff           @@
   ##           master   #4970   +/-   ##
   ======================================
     Coverage    0.00%   0.00%           
   ======================================
     Files         561     561           
     Lines       30950   30942    -8     
     Branches     4058    4058           
   ======================================
   + Misses      30950   30942    -8     
   ```
   
   
   | [Impacted Files](https://app.codecov.io/gh/apache/kyuubi/pull/4970?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...plugin/spark/authz/util/RangerConfigProvider.scala](https://app.codecov.io/gh/apache/kyuubi/pull/4970?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXh0ZW5zaW9ucy9zcGFyay9reXV1Ymktc3BhcmstYXV0aHovc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9reXV1YmkvcGx1Z2luL3NwYXJrL2F1dGh6L3V0aWwvUmFuZ2VyQ29uZmlnUHJvdmlkZXIuc2NhbGE=) | `0.00% <0.00%> (ø)` | |
   | [...e/kyuubi/engine/spark/util/SparkCatalogUtils.scala](https://app.codecov.io/gh/apache/kyuubi/pull/4970?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXh0ZXJuYWxzL2t5dXViaS1zcGFyay1zcWwtZW5naW5lL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL2VuZ2luZS9zcGFyay91dGlsL1NwYXJrQ2F0YWxvZ1V0aWxzLnNjYWxh) | `0.00% <0.00%> (ø)` | |
   | [...g/apache/spark/sql/kyuubi/SparkDatasetHelper.scala](https://app.codecov.io/gh/apache/kyuubi/pull/4970?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXh0ZXJuYWxzL2t5dXViaS1zcGFyay1zcWwtZW5naW5lL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvc3Bhcmsvc3FsL2t5dXViaS9TcGFya0RhdGFzZXRIZWxwZXIuc2NhbGE=) | `0.00% <0.00%> (ø)` | |
   | [...he/kyuubi/operation/log/Log4j2DivertAppender.scala](https://app.codecov.io/gh/apache/kyuubi/pull/4970?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-a3l1dWJpLWNvbW1vbi9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9vcGVyYXRpb24vbG9nL0xvZzRqMkRpdmVydEFwcGVuZGVyLnNjYWxh) | `0.00% <0.00%> (ø)` | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


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


[GitHub] [kyuubi] pan3793 commented on a diff in pull request #4970: Unified reflection methods invokeAs and getField

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #4970:
URL: https://github.com/apache/kyuubi/pull/4970#discussion_r1231756165


##########
kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala:
##########
@@ -70,20 +78,26 @@ object ReflectUtils {
    * @return
    */
   def invokeAs[T](target: AnyRef, methodName: String, args: (Class[_], AnyRef)*): T = {
-    val targetClass = target.getClass
+    val (clz, obj) = getTargetClass(target)
     val argClasses = args.map(_._1)
     try {
-      DynMethods.builder(methodName)
-        .hiddenImpl(targetClass, argClasses: _*)
-        .buildChecked(target)
-        .invoke[T](args.map(_._2): _*)
+      val method = DynMethods.builder(methodName)
+        .hiddenImpl(clz, argClasses: _*)
+        .impl(clz, argClasses: _*)
+        .buildChecked
+      if (method.isStatic) {
+        method.asStatic.invoke[T](args.map(_._2): _*)

Review Comment:
   I lean to separate the static case to dedicated method



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


[GitHub] [kyuubi] bowenliang123 closed pull request #4970: Unified reflection methods invokeAs and getField

Posted by "bowenliang123 (via GitHub)" <gi...@apache.org>.
bowenliang123 closed pull request #4970: Unified reflection methods invokeAs and getField
URL: https://github.com/apache/kyuubi/pull/4970


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


[GitHub] [kyuubi] pan3793 commented on a diff in pull request #4970: Unified reflection methods invokeAs and getField

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #4970:
URL: https://github.com/apache/kyuubi/pull/4970#discussion_r1231755994


##########
kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala:
##########
@@ -70,20 +78,26 @@ object ReflectUtils {
    * @return
    */
   def invokeAs[T](target: AnyRef, methodName: String, args: (Class[_], AnyRef)*): T = {
-    val targetClass = target.getClass
+    val (clz, obj) = getTargetClass(target)
     val argClasses = args.map(_._1)
     try {
-      DynMethods.builder(methodName)
-        .hiddenImpl(targetClass, argClasses: _*)
-        .buildChecked(target)
-        .invoke[T](args.map(_._2): _*)
+      val method = DynMethods.builder(methodName)
+        .hiddenImpl(clz, argClasses: _*)
+        .impl(clz, argClasses: _*)
+        .buildChecked
+      if (method.isStatic) {
+        method.asStatic.invoke[T](args.map(_._2): _*)

Review Comment:
   not sure if it's a good idea to include static case



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


[GitHub] [kyuubi] bowenliang123 commented on a diff in pull request #4970: Unified reflection methods invokeAs and getField

Posted by "bowenliang123 (via GitHub)" <gi...@apache.org>.
bowenliang123 commented on code in PR #4970:
URL: https://github.com/apache/kyuubi/pull/4970#discussion_r1231810829


##########
kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/reflect/ReflectUtils.scala:
##########
@@ -70,20 +78,26 @@ object ReflectUtils {
    * @return
    */
   def invokeAs[T](target: AnyRef, methodName: String, args: (Class[_], AnyRef)*): T = {
-    val targetClass = target.getClass
+    val (clz, obj) = getTargetClass(target)
     val argClasses = args.map(_._1)
     try {
-      DynMethods.builder(methodName)
-        .hiddenImpl(targetClass, argClasses: _*)
-        .buildChecked(target)
-        .invoke[T](args.map(_._2): _*)
+      val method = DynMethods.builder(methodName)
+        .hiddenImpl(clz, argClasses: _*)
+        .impl(clz, argClasses: _*)
+        .buildChecked
+      if (method.isStatic) {
+        method.asStatic.invoke[T](args.map(_._2): _*)

Review Comment:
   After my second thought, a dedicated method for static class may cause confusion for usage, eg. a method of Sacla object class is not static. The usages for both object/static class and common classes are shown in test cases which clear enough to understand and use. I would keep it as it is with auto detecting for whether it's a static one.



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