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

    https://github.com/apache/spark/pull/20756#discussion_r172731452
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
 ---
    @@ -1254,8 +1254,24 @@ case class InitializeJavaBean(beanInstance: 
Expression, setters: Map[String, Exp
       override def children: Seq[Expression] = beanInstance +: 
setters.values.toSeq
       override def dataType: DataType = beanInstance.dataType
     
    -  override def eval(input: InternalRow): Any =
    -    throw new UnsupportedOperationException("Only code-generated 
evaluation is supported.")
    +  override def eval(input: InternalRow): Any = {
    +    val instance = beanInstance.eval(input).asInstanceOf[Object]
    +    if (instance != null) {
    +      setters.foreach { case (setterMethod, fieldExpr) =>
    +        val fieldValue = fieldExpr.eval(input).asInstanceOf[Object]
    +
    +        val foundMethods = instance.getClass.getMethods.filter { method =>
    +          method.getName == setterMethod && 
Modifier.isPublic(method.getModifiers) &&
    +            method.getParameterTypes.length == 1
    +        }
    +        assert(foundMethods.length == 1,
    +          throw new RuntimeException("The Java Bean instance should have 
only one " +
    --- End diff --
    
    codegen evaluation does not check method existence. But for non-codegen 
evaluation here, it is a bit weird to directly invoke first found method (we 
may not find it). cc @hvanhovell 


---

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

Reply via email to