diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java index 8ae323cfb41497..15ceb8c1f8bb35 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/copier/LogicalPlanDeepCopier.java @@ -151,7 +151,13 @@ public Plan visitLogicalAggregate(LogicalAggregate aggregate, De List outputExpressions = aggregate.getOutputExpressions().stream() .map(o -> (NamedExpression) ExpressionDeepCopier.INSTANCE.deepCopy(o, context)) .collect(ImmutableList.toImmutableList()); - return aggregate.withChildGroupByAndOutput(groupByExpressions, outputExpressions, child); + LogicalAggregate copiedAggregate = aggregate.withChildGroupByAndOutput(groupByExpressions, + outputExpressions, child); + Optional> childRepeat = + copiedAggregate.collectFirst(LogicalRepeat.class::isInstance); + return childRepeat.isPresent() ? aggregate.withChildGroupByAndOutputAndSourceRepeat( + groupByExpressions, outputExpressions, child, childRepeat) + : aggregate.withChildGroupByAndOutput(groupByExpressions, outputExpressions, child); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java index e59025442dabf7..fbea327f7a865a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java @@ -282,6 +282,13 @@ public LogicalAggregate withChildGroupByAndOutput(List groupBy hasPushed, sourceRepeat, Optional.empty(), Optional.empty(), newChild); } + public LogicalAggregate withChildGroupByAndOutputAndSourceRepeat(List groupByExprList, + List outputExpressionList, Plan newChild, + Optional> sourceRepeat) { + return new LogicalAggregate<>(groupByExprList, outputExpressionList, normalized, ordinalIsResolved, generated, + hasPushed, sourceRepeat, Optional.empty(), Optional.empty(), newChild); + } + public LogicalAggregate withChildAndOutput(CHILD_TYPE child, List outputExpressionList) { return new LogicalAggregate<>(groupByExpressions, outputExpressionList, normalized, ordinalIsResolved,