-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BugFix] Fix CTE distinct grouping sets rewrite generate invalid plan (…
…#48765) Signed-off-by: stdpain <[email protected]> (cherry picked from commit 6076570) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/sql/optimizer/Optimizer.java # fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/RuleType.java
- Loading branch information
1 parent
9f92fa6
commit b428def
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ain/java/com/starrocks/sql/optimizer/rule/transformation/CTEProduceAddProjectionRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.starrocks.sql.optimizer.rule.transformation; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Lists; | ||
import com.starrocks.sql.optimizer.OptExpression; | ||
import com.starrocks.sql.optimizer.OptimizerContext; | ||
import com.starrocks.sql.optimizer.RowOutputInfo; | ||
import com.starrocks.sql.optimizer.operator.ColumnOutputInfo; | ||
import com.starrocks.sql.optimizer.operator.OperatorType; | ||
import com.starrocks.sql.optimizer.operator.Projection; | ||
import com.starrocks.sql.optimizer.operator.logical.LogicalRepeatOperator; | ||
import com.starrocks.sql.optimizer.operator.pattern.Pattern; | ||
import com.starrocks.sql.optimizer.operator.scalar.ColumnRefOperator; | ||
import com.starrocks.sql.optimizer.operator.scalar.ScalarOperator; | ||
import com.starrocks.sql.optimizer.rule.RuleType; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class CTEProduceAddProjectionRule extends TransformationRule { | ||
|
||
public CTEProduceAddProjectionRule() { | ||
super(RuleType.TF_CTE_ADD_PROJECTION, | ||
Pattern.create(OperatorType.LOGICAL_CTE_PRODUCE, OperatorType.LOGICAL_REPEAT)); | ||
} | ||
|
||
@Override | ||
public List<OptExpression> transform(OptExpression input, OptimizerContext context) { | ||
final OptExpression repeatOpt = input.getInputs().get(0); | ||
final LogicalRepeatOperator repeat = (LogicalRepeatOperator) repeatOpt.getOp(); | ||
if (repeat.getProjection() == null) { | ||
final RowOutputInfo rowOutputInfo = repeatOpt.getInputs().get(0).getRowOutputInfo(); | ||
final ImmutableMap.Builder<ColumnRefOperator, ScalarOperator> builder = ImmutableMap.builder(); | ||
|
||
for (ColumnOutputInfo columnOutputInfo : rowOutputInfo.getColumnOutputInfo()) { | ||
final ColumnRefOperator columnRef = columnOutputInfo.getColumnRef(); | ||
builder.put(columnRef, columnRef); | ||
} | ||
|
||
// add grouping id to projection | ||
for (ColumnRefOperator columnRefOperator : repeat.getOutputGrouping()) { | ||
builder.put(columnRefOperator, columnRefOperator); | ||
} | ||
repeat.setProjection(new Projection(builder.build())); | ||
return Lists.newArrayList(input); | ||
} else { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters