maropu commented on a change in pull request #25717: [WIP][SPARK-29013][SQL] Structurally equivalent subexpression elimination URL: https://github.com/apache/spark/pull/25717#discussion_r321999396
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala ########## @@ -65,35 +89,102 @@ class EquivalentExpressions { } /** - * Adds the expression to this data structure recursively. Stops if a matching expression - * is found. That is, if `expr` has already been added, its children are not added. + * Adds each expression to structural expression data structure, grouping them with existing + * structurally equivalent expressions. Non-recursive. + */ + def addStructExpr(ctx: CodegenContext, expr: Expression): Unit = { + if (expr.deterministic) { + val refs = expr.collect { + case b: BoundReference => b + } + + // For structural equivalent expressions, we need to pass in int type ordinals into + // split functions. If the number of ordinals is more than JVM function limit, we skip + // this expression. + // We calculate function parameter length by the number of ints plus `INPUT_ROW` plus + // a int type result array index. + val parameterLength = CodeGenerator.calculateParamLength(refs.map(_ => Literal(0))) + 2 + if (CodeGenerator.isValidParamLength(parameterLength)) { Review comment: If the length goes over the limit, the current logic gives up eliminating common exprs? If so, can we fall back into the non-structural mode? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org