Skip to content

Commit

Permalink
fix get related table column from null generate side
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Dec 22, 2023
1 parent 4ee6612 commit 475b0bf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private static final class IncrementCheckerContext {
private boolean pctPossible = true;
private TableIf relatedTable;
private Column relatedTableColumn;
private boolean joinNullGenerateSide;

public IncrementCheckerContext(SlotReference mvPartitionColumn) {
this.mvPartitionColumn = mvPartitionColumn;
Expand Down Expand Up @@ -304,6 +305,14 @@ public Column getRelatedTableColumn() {
public void setRelatedTableColumn(Column relatedTableColumn) {
this.relatedTableColumn = relatedTableColumn;
}

public boolean isJoinNullGenerateSide() {
return joinNullGenerateSide;
}

public void setJoinNullGenerateSide(boolean joinNullGenerateSide) {
this.joinNullGenerateSide = joinNullGenerateSide;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void getRelatedTableInfoUseRightTest() {
+ " (select * from "
+ " lineitem "
+ " where L_SHIPDATE in ('2017-01-30')) t1 "
+ "left join "
+ "right join "
+ " (select * from "
+ " orders "
+ " where O_ORDERDATE in ('2017-01-30')) t2 "
Expand All @@ -207,6 +207,33 @@ public void getRelatedTableInfoUseRightTest() {
});
}

@Test
public void getRelatedTableInfoUseNullGenerateSideTest() {
PlanChecker.from(connectContext)
.checkExplain("SELECT t1.L_SHIPDATE, t2.O_ORDERDATE, t1.L_QUANTITY, t2.O_ORDERSTATUS, "
+ "count(distinct case when t1.L_SUPPKEY > 0 then t2.O_ORDERSTATUS else null end) as cnt_1 "
+ "from "
+ " (select * from "
+ " lineitem "
+ " where L_SHIPDATE in ('2017-01-30')) t1 "
+ "left join "
+ " (select * from "
+ " orders "
+ " where O_ORDERDATE in ('2017-01-30')) t2 "
+ "on t1.L_ORDERKEY = t2.O_ORDERKEY "
+ "group by "
+ "t1.L_SHIPDATE, "
+ "t2.O_ORDERDATE, "
+ "t1.L_QUANTITY, "
+ "t2.O_ORDERSTATUS;",
nereidsPlanner -> {
Plan rewrittenPlan = nereidsPlanner.getRewrittenPlan();
Optional<RelatedTableInfo> relatedTableInfo =
MaterializedViewUtils.getRelatedTableInfo("o_orderdate", rewrittenPlan);
Assertions.assertFalse(relatedTableInfo.isPresent());
});
}

@Test
public void getRelatedTableInfoTestWithoutPartitionTest() {
PlanChecker.from(connectContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ suite("inner_join") {
sql """ DROP MATERIALIZED VIEW IF EXISTS mv6_0"""


// filter inside + inner + right
// filter inside + left + right
def mv7_0 = "select l_shipdate, o_orderdate, l_partkey, l_suppkey " +
"from lineitem " +
"inner join (select * from orders where o_orderdate = '2023-12-08') t2 " +
Expand Down

0 comments on commit 475b0bf

Please sign in to comment.