ericm-db commented on code in PR #54236:
URL: https://github.com/apache/spark/pull/54236#discussion_r2814498526
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -1028,13 +1034,15 @@ object PushProjectionThroughUnion extends
Rule[LogicalPlan] {
}
def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
- _.containsAllPatterns(UNION, PROJECT)) {
+ t => t.containsPattern(PROJECT) &&
+ t.containsAnyPattern(UNION, SEQUENTIAL_STREAMING_UNION)) {
- // Push down deterministic projection through UNION ALL
- case project @ Project(projectList, u: Union)
+ // Push down deterministic projection through Union or
SequentialStreamingUnion.
+ // This is safe because it preserves child ordering.
+ case project @ Project(projectList, SequentialOrSimpleUnion(u))
if projectList.forall(_.deterministic) && u.children.nonEmpty &&
canPushProjectionThroughUnion(project) =>
- u.copy(children = pushProjectionThroughUnion(projectList, u))
+ SequentialOrSimpleUnion.withNewChildren(u,
pushProjectionThroughUnion(projectList, u))
Review Comment:
the reason we can't do this in combine unions is because withNewChildren
asserts that oldChildren.length == newChildren.length
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -273,7 +273,11 @@ abstract class Optimizer(catalogManager: CatalogManager)
RemoveNoopOperators),
// This batch must be executed after the `RewriteSubquery` batch, which
creates joins.
Batch("NormalizeFloatingNumbers", Once, NormalizeFloatingNumbers),
- Batch("ReplaceUpdateFieldsExpression", Once,
ReplaceUpdateFieldsExpression)))
+ Batch("ReplaceUpdateFieldsExpression", Once,
ReplaceUpdateFieldsExpression),
+ // Validate that nested SequentialStreamingUnions have been properly
flattened.
+ // Must run after CombineUnions in the "Union" batch.
+ Batch("Validate SequentialStreamingUnion", Once,
+ ValidateSequentialStreamingUnionNesting)))
Review Comment:
Ah okay, let me remove this and rely on the tests.
--
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]