Github user sun-rui commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8458#discussion_r38995711
  
    --- Diff: core/src/main/scala/org/apache/spark/api/r/RBackendHandler.scala 
---
    @@ -171,35 +183,58 @@ private[r] class RBackendHandler(server: RBackend)
         }.toArray
       }
     
    -  // Checks if the arguments passed in args matches the parameter types.
    -  // NOTE: Currently we do exact match. We may add type conversions later.
    +  // Find a matching method in all methods of the same name of a class
    +  // according to the passed arguments. Arguments may be converted in
    +  // order to match a method.
    +  //
    +  // Returns a two-element tuple. The first element is the index of
    +  // the matched method in the list of the methods of the same name.
    +  // The second element is the list of converted arguments.
       def matchMethod(
    -      numArgs: Int,
    -      args: Array[java.lang.Object],
    -      parameterTypes: Array[Class[_]]): Boolean = {
    -    if (parameterTypes.length != numArgs) {
    -      return false
    -    }
    +      parameterTypesOfMethods: Array[Array[Class[_]]],
    +      args: Array[Object]): (Option[Int], Array[Object]) = {
    +    val numArgs = args.length
    +
    +    for (index <- 0 to parameterTypesOfMethods.length - 1) {
    +      val parameterTypes = parameterTypesOfMethods(index)
    +
    +      if (parameterTypes.length == numArgs) {
    +        val convertedArgs = new Array[Object](numArgs)
    --- End diff --
    
    Arg is checked and converted one by one when matching a method. It is 
possible that after some args were converted, an arg fails, then all args have 
to be reverted to the original ones for matching next method.
    
    It could be possible for now that checking all args for one method, and 
only after the checking passes, then do conversion, thus we can modify args in 
place.
    
    I will refine the code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to