dtenedor commented on code in PR #60697:
URL: https://github.com/apache/spark/pull/60697#discussion_r4635894211
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/pipeOperators.scala:
##########
@@ -62,28 +63,52 @@ object EliminatePipeOperators extends Rule[LogicalPlan] {
}
/**
- * Validates and strips PipeExpression nodes from a logical plan once the
child expressions are
- * resolved.
+ * Validates and strips PipeExpression nodes from a logical plan once their
children are ready:
+ * either resolved, or a generator item whose arguments are resolved (see
`isReadyGeneratorItem`).
*/
case object ValidateAndStripPipeExpressions extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan =
plan.resolveOperatorsUpWithPruning(
_.containsPattern(PIPE_EXPRESSION), ruleId) {
case node: LogicalPlan =>
node.resolveExpressions {
- case p: PipeExpression if p.child.resolved =>
+ case p: PipeExpression if p.child.resolved ||
isReadyGeneratorItem(p.child) =>
validateAndStripPipeExpression(p, p.child)
}
}
/**
- * Validates aggregate function constraints for a [[PipeExpression]] and
returns the resolved
- * child expression (stripping the [[PipeExpression]] wrapper).
+ * Returns true for a generator item that ExtractGenerator plans, once the
generator's arguments
+ * are resolved: a generator, optionally wrapped in GeneratorOuter (for the
*_outer functions)
+ * and then in MultiAlias (for a parenthesized alias list). ExtractGenerator
replaces both
+ * wrappers when it plans Generate; ResolveAliases only removes the
UnresolvedAlias above a
+ * MultiAlias. Neither wrapper ever reports itself resolved, and the
generator itself may only
+ * become resolved after this rule runs, when type coercion fixes its
arguments (for example,
+ * stack(2, id, null)). So the PipeExpression is stripped as soon as the
arguments are resolved,
+ * keeping both wrappers in place; otherwise ExtractGenerator sees the
PipeExpression above the
+ * generator and rejects it as nested inside another expression.
+ */
+ private def isReadyGeneratorItem(e: Expression): Boolean = e match {
+ case MultiAlias(g: Generator, _) => isReadyGenerator(g)
Review Comment:
I will keep this decision alone because we already thought about it several
times.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]