Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20778#discussion_r180975252
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
 ---
    @@ -392,8 +392,44 @@ case class NewInstance(
         childrenResolved && !needOuterPointer
       }
     
    -  override def eval(input: InternalRow): Any =
    -    throw new UnsupportedOperationException("Only code-generated 
evaluation is supported.")
    +  private lazy val constructor: (Seq[AnyRef]) => Any = {
    +    val paramTypes = arguments.map { expr =>
    +      CallMethodViaReflection.typeMapping.getOrElse(expr.dataType,
    +        Seq(expr.dataType.asInstanceOf[ObjectType].cls))
    +    }
    +    val findConstructor = (types: Seq[Seq[Class[_]]]) => {
    +      val constructorOption = cls.getConstructors.find { c =>
    --- End diff --
    
    I checked the resolution rule in `Class.getConstructor` and I found it only 
supported the exact matching for parameter types (so, we couldn't handle class 
inheritances correctly). Then, in the latest fix, I tried to use 
[getMatchingAccessibleConstructor](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/reflect/ConstructorUtils.html#getMatchingAccessibleConstructor-java.lang.Class-java.lang.Class...-)
 in `commons.lang3`. It seems useful to find an acceptable constructor in a 
class. How about this? @hvanhovell @viirya 


---

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

Reply via email to