Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class LogicalWindowToPhysicalWindow extends OneImplementationRuleFactory
public Rule build() {

return RuleType.LOGICAL_WINDOW_TO_PHYSICAL_WINDOW_RULE.build(
logicalWindow().when(LogicalWindow::isChecked).then(this::implement)
logicalWindow().then(this::implement)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public Plan visitLogicalAggregate(LogicalAggregate<? extends Plan> aggregate, De
List<NamedExpression> outputExpressions = aggregate.getOutputExpressions().stream()
.map(o -> (NamedExpression) ExpressionDeepCopier.INSTANCE.deepCopy(o, context))
.collect(ImmutableList.toImmutableList());
return new LogicalAggregate<>(groupByExpressions, outputExpressions, child);
return aggregate.withChildGroupByAndOutput(groupByExpressions, outputExpressions, child);
}

@Override
Expand Down Expand Up @@ -194,7 +194,10 @@ public Plan visitLogicalProject(LogicalProject<? extends Plan> project, DeepCopi
List<NamedExpression> newProjects = project.getProjects().stream()
.map(p -> (NamedExpression) ExpressionDeepCopier.INSTANCE.deepCopy(p, context))
.collect(ImmutableList.toImmutableList());
return new LogicalProject<>(newProjects, child);
List<NamedExpression> newExcepts = project.getExcepts().stream()
.map(p -> (NamedExpression) ExpressionDeepCopier.INSTANCE.deepCopy(p, context))
.collect(ImmutableList.toImmutableList());
return new LogicalProject<>(newProjects, newExcepts, project.isDistinct(), child);
}

@Override
Expand Down Expand Up @@ -353,7 +356,7 @@ public Plan visitLogicalGenerate(LogicalGenerate<? extends Plan> generate, DeepC
List<Slot> generatorOutput = generate.getGeneratorOutput().stream()
.map(o -> (Slot) ExpressionDeepCopier.INSTANCE.deepCopy(o, context))
.collect(ImmutableList.toImmutableList());
return new LogicalGenerate<>(generators, generatorOutput, child);
return new LogicalGenerate<>(generators, generatorOutput, generate.getExpandColumnAlias(), child);
}

@Override
Expand All @@ -362,7 +365,7 @@ public Plan visitLogicalWindow(LogicalWindow<? extends Plan> window, DeepCopierC
List<NamedExpression> windowExpressions = window.getWindowExpressions().stream()
.map(w -> (NamedExpression) ExpressionDeepCopier.INSTANCE.deepCopy(w, context))
.collect(ImmutableList.toImmutableList());
return new LogicalWindow<>(windowExpressions, child);
return new LogicalWindow<>(windowExpressions, window.isChecked(), child);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ public LogicalAggregate<Plan> withGroupByAndOutput(List<Expression> groupByExprL
hasPushed, sourceRepeat, Optional.empty(), Optional.empty(), child());
}

public LogicalAggregate<Plan> withChildGroupByAndOutput(List<Expression> groupByExpressions,
List<NamedExpression> outputExpressions, Plan child) {
return new LogicalAggregate<>(groupByExpressions, outputExpressions, normalized, ordinalIsResolved, generated,
hasPushed, sourceRepeat, Optional.empty(), Optional.empty(), child);
}

public LogicalAggregate<Plan> withChildAndOutput(CHILD_TYPE child,
List<NamedExpression> outputExpressionList) {
return new LogicalAggregate<>(groupByExpressions, outputExpressionList, normalized, ordinalIsResolved,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public List<NamedExpression> getProjects() {
return projects;
}

public LogicalEmptyRelation withProjects(List<? extends NamedExpression> projects) {
return new LogicalEmptyRelation(relationId, projects);
}

@Override
public Plan withGroupExpression(Optional<GroupExpression> groupExpression) {
return new LogicalEmptyRelation(relationId, projects,
Expand All @@ -86,6 +82,14 @@ public LogicalEmptyRelation withRelationId(RelationId relationId) {
throw new RuntimeException("should not call LogicalEmptyRelation's withRelationId method");
}

public LogicalEmptyRelation withProjects(List<NamedExpression> projects) {
return new LogicalEmptyRelation(relationId, projects);
}

public LogicalEmptyRelation withRelationIdAndProjects(RelationId relationId, List<NamedExpression> projects) {
return new LogicalEmptyRelation(relationId, projects);
}

@Override
public List<Slot> computeOutput() {
return projects.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public LogicalOneRowRelation withRelationId(RelationId relationId) {
throw new RuntimeException("should not call LogicalOneRowRelation's withRelationId method");
}

public LogicalOneRowRelation withRelationIdAndProjects(RelationId relationId, List<NamedExpression> projects) {
return new LogicalOneRowRelation(relationId, projects);
}

@Override
public List<Slot> computeOutput() {
return projects.stream()
Expand Down
54 changes: 54 additions & 0 deletions regression-test/suites/nereids_p0/union/or_expansion.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,58 @@ suite("or_expansion") {
on (oe1.k0 = oe2.k0 or oe1.k1 + 1 = oe2.k1 * 2) or oe1.k2 = 1
order by oe2.k0, oe1.k0
"""

// test all plan node to be deep copied, include
// - LogicalOneRowRelation
// - LogicalEmptyRelation
// - LogicalFilter
// - LogicalProject
// - LogicalJoin
// - LogicalRepeat
// - LogicalAggregate
// - LogicalGenerate
// - LogicalWindow
// - LogicalPartitionTopN
// - LogicalTopN
// - LogicalLimit
explain {
sql """
WITH cte1 AS (
SELECT 1 AS c1, max(1) OVER() AS c3
)
, cte2 AS (
SELECT c1, sum(c3) AS c3 FROM cte1 GROUP BY GROUPING SETS((c1), ())
)
, cte3 AS (
SELECT c1, [1, 2, 3] AS c2, c3 FROM cte2
)
, cte4 AS (
SELECT c1, c2, c3, c4 FROM cte3 LATERAL VIEW EXPLODE (c2) lv AS c4 LIMIT 10
)
, cte5 AS (
SELECT * FROM cte4 WHERE c4 > 2
)
, cte6 AS (
SELECT 1 AS c5 FROM (SELECT 1) t WHERE 1 < 0
)
, cte7 AS (
SELECT * FROM cte5 LEFT OUTER JOIN cte6 ON cte5.c1 = cte6.c5 ORDER BY c4 LIMIT 10
)
, cte8 AS (
SELECT 1 AS c1, max(1) OVER() AS c3
)
, cte9 AS (
SELECT * FROM (SELECT 1 AS c6, ROW_NUMBER() OVER(PARTITION BY c3 ORDER BY c1) AS c7 FROM cte8) t WHERE c7 < 3
)
, cte10 AS (
SELECT * FROM cte7 LEFT OUTER JOIN cte9 ON cte7.c1 = cte9.c6
)
SELECT *
FROM
cte10 a
LEFT JOIN (SELECT 1 AS c1, 2 AS c2) b ON a.c1 = b.c1 OR a.c1 = b.c2 ORDER BY c1
"""

contains "ANTI JOIN"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ suite("transform_outer_join_to_anti") {
contains "ANTI JOIN"
}
}

Loading