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

    https://github.com/apache/spark/pull/19480#discussion_r144246243
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
 ---
    @@ -798,10 +830,35 @@ class CodegenContext {
                |  ${makeSplitFunction(body)}
                |}
              """.stripMargin
    -        addNewFunction(name, code)
    +        addNewFunctionInternal(name, code, inlineToOuterClass = false)
           }
     
    -      foldFunctions(functions.map(name => 
s"$name(${arguments.map(_._2).mkString(", ")})"))
    +      val outerClassFunctions = functions
    +        .filter(_.subclassName.isEmpty)
    +        .map(_.functionName)
    +
    +      val innerClassFunctions = functions
    +        .filter(_.subclassName.isDefined)
    +        .foldLeft(Map.empty[(String, String), Seq[String]]) { case (acc, 
f) =>
    +          val key = (f.subclassName.get, f.subclassInstance.get)
    +          acc.updated(key, acc.getOrElse(key, Seq.empty[String]) ++ 
Seq(f.functionName))
    +        }
    +        .map { case ((subclassName, subclassInstance), subclassFunctions) 
=>
    +          // Adding a new function to each subclass which contains
    +          // the invocation of all the ones which have been added to
    +          // that subclass
    +          val code = s"""
    +              |private $returnType $func($argString) {
    +              |  
${makeSplitFunction(foldFunctions(subclassFunctions.map(name =>
    +                    s"$name(${arguments.map(_._2).mkString(", ")})")))}
    +              |}
    +            """.stripMargin
    +          addNewFunctionToClass(func, code, subclassName)
    --- End diff --
    
    we might, but I think this would not be the best option, since in this way 
we are "reusing" some ConstantPool entries (like `Utf8` for the name of the 
function) and it keeps everything about those things in the same class.
    Moreover, foreach instance referenced from other classes, like it would be 
in that case, we are adding new entries to the Constant Pool of that class.
    Thus this is the option which minimizes the number of entries added to the 
Constant Pools.


---

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

Reply via email to