dtenedor commented on code in PR #60697:
URL: https://github.com/apache/spark/pull/60697#discussion_r4635114497


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/pipeOperators.scala:
##########
@@ -62,28 +63,46 @@ 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 that ExtractGenerator plans later (see
+ * `isResolvedGeneratorItem`).
  */
 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 || 
isResolvedGeneratorItem(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 the generator items that ExtractGenerator plans but that 
never report
+   * themselves resolved: an outer generator (GeneratorOuter is replaced by 
ExtractGenerator), and
+   * a generator with a parenthesized alias list (MultiAlias is replaced by 
ResolveAliases or
+   * ExtractGenerator). The PipeExpression must be stripped once the generator 
inside is resolved,
+   * keeping GeneratorOuter and MultiAlias in place; otherwise 
ExtractGenerator sees the
+   * PipeExpression above the generator and rejects it as nested inside 
another expression.
+   */
+  private def isResolvedGeneratorItem(e: Expression): Boolean = e match {
+    case GeneratorOuter(g) => g.resolved
+    case MultiAlias(GeneratorOuter(g), _) => g.resolved
+    case MultiAlias(g: Generator, _) => g.resolved

Review Comment:
   Addressed in 74d7c55f. The readiness check (now `isReadyGeneratorItem`) 
waits only until the generator's arguments are resolved, for every shape the 
rule strips: `g`, `GeneratorOuter(g)`, `MultiAlias(g, names)` and 
`MultiAlias(GeneratorOuter(g), names)`. For `GeneratorOuter` it tests the inner 
generator's arguments, and both wrappers stay in place. I added golden cases 
for `stack(2, id, null)` with an alias list in `|> EXTEND` and `|> AGGREGATE`, 
and with a single-name alias and with none in `|> SELECT` and `|> EXTEND`. They 
all return the plain SQL rows. I also added wrongly typed arguments in a `|> 
SELECT` outer generator item and a `|> EXTEND` alias-list item, each next to 
its plain SQL query; both now report `DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE`, 
as plain SQL does. Regenerating the golden files only adds the new cases, and 
the PR description now mentions the error-class change.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/pipeOperators.scala:
##########
@@ -62,28 +63,46 @@ 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 that ExtractGenerator plans later (see
+ * `isResolvedGeneratorItem`).
  */
 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 || 
isResolvedGeneratorItem(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 the generator items that ExtractGenerator plans but that 
never report
+   * themselves resolved: an outer generator (GeneratorOuter is replaced by 
ExtractGenerator), and
+   * a generator with a parenthesized alias list (MultiAlias is replaced by 
ResolveAliases or

Review Comment:
   Addressed in 74d7c55f. The scaladoc now says that ExtractGenerator replaces 
both `GeneratorOuter` and `MultiAlias` when it plans `Generate`, and that 
ResolveAliases only removes the `UnresolvedAlias` above a `MultiAlias`.



-- 
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]

Reply via email to