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

    https://github.com/apache/spark/pull/9270#discussion_r44117245
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ScalaUDF.scala
 ---
    @@ -965,6 +969,80 @@ case class ScalaUDF(
       }
     
       // scalastyle:on
    +
    +  // Generate codes used to convert the arguments to Scala type for 
user-defined funtions
    +  private[this] def genCodeForConverter(ctx: CodeGenContext, index: Int): 
String = {
    +    val converterClassName = classOf[Any => Any].getName
    +    val typeConvertersClassName = CatalystTypeConverters.getClass.getName 
+ ".MODULE$"
    +    val expressionClassName = classOf[Expression].getName
    +    val scalaUDFClassName = classOf[ScalaUDF].getName
    +
    +    val converterTerm = ctx.freshName("converter")
    +    ctx.addMutableState(converterClassName, converterTerm,
    +      s"this.$converterTerm = 
($converterClassName)$typeConvertersClassName" +
    +        
s".createToScalaConverter(((${expressionClassName})((($scalaUDFClassName)" +
    +          s"expressions[${ctx.references.size - 
1}]).getChildren().apply($index))).dataType());")
    +    converterTerm
    +  }
    +
    +  override def genCode(
    +      ctx: CodeGenContext,
    +      ev: GeneratedExpressionCode): String = {
    +
    +    ctx.references += this
    +
    +    val scalaUDFClassName = classOf[ScalaUDF].getName
    +    val converterClassName = classOf[Any => Any].getName
    +    val typeConvertersClassName = CatalystTypeConverters.getClass.getName 
+ ".MODULE$"
    +    val expressionClassName = classOf[Expression].getName
    +
    +    // Generate codes used to convert the returned value of user-defined 
functions to Catalyst type
    +    val catalystConverterTerm = ctx.freshName("catalystConverter")
    +    ctx.addMutableState(converterClassName, catalystConverterTerm,
    +      s"this.$catalystConverterTerm = 
($converterClassName)$typeConvertersClassName" +
    +        s".createToCatalystConverter((($scalaUDFClassName)expressions" +
    +          s"[${ctx.references.size - 1}]).dataType());")
    +
    +    val resultTerm = ctx.freshName("result")
    +
    +    // This must be called before children expressions' codegen
    +    // because ctx.references is used in genCodeForConverter
    --- End diff --
    
    I've added that. Thanks.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to