Skip to content

Commit

Permalink
testFilterProjectTransposeExpandFalse
Browse files Browse the repository at this point in the history
  • Loading branch information
ViggoC committed Feb 18, 2025
1 parent 2a15b65 commit 9ae781d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 15 deletions.
54 changes: 39 additions & 15 deletions core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2689,21 +2689,6 @@ private void checkProjectCorrelateTransposeRuleSemiOrAntiCorrelate(JoinRelType t
.checkUnchanged();
}

@Test void testFilterProjectTransposePreventedByCorrelationWithExpandFalse() {
final String sql = "SELECT e.deptno\n"
+ "FROM emp as e\n"
+ "WHERE exists (\n"
+ " SELECT *\n"
+ " FROM dept AS d\n"
+ " WHERE e.deptno = d.deptno)";
sql(sql)
.withDecorrelate(false)
.withTrim(true)
.withExpand(false)
.withRule(CoreRules.FILTER_PROJECT_TRANSPOSE)
.checkUnchanged();
}

/** Tests a variant of {@link FilterProjectTransposeRule}
* that pushes a Filter that contains a correlating variable. */
@Test void testFilterProjectTranspose() {
Expand Down Expand Up @@ -2733,6 +2718,45 @@ private void checkProjectCorrelateTransposeRuleSemiOrAntiCorrelate(JoinRelType t
.check();
}

@Test void testFilterProjectTransposePreventedByCorrelationWithExpandFalse() {
final String sql = "SELECT e.deptno\n"
+ "FROM emp as e\n"
+ "WHERE exists (\n"
+ " SELECT *\n"
+ " FROM dept AS d\n"
+ " WHERE e.deptno = d.deptno)";
sql(sql)
.withDecorrelate(false)
.withTrim(true)
.withRule(CoreRules.FILTER_PROJECT_TRANSPOSE)
.checkUnchanged();
}

@Test void testFilterProjectTransposeExpandFalse() {
final String sql = "SELECT e.deptno\n"
+ "FROM emp as e\n"
+ "WHERE exists (\n"
+ " SELECT *\n"
+ " FROM dept AS d\n"
+ " WHERE e.deptno = d.deptno)";
final FilterProjectTransposeRule filterProjectTransposeRule =
CoreRules.FILTER_PROJECT_TRANSPOSE.config
.withOperandSupplier(b0 ->
b0.operand(Filter.class).predicate(filter -> true)
.oneInput(b1 ->
b1.operand(Project.class).predicate(project -> true)
.anyInputs()))
.as(FilterProjectTransposeRule.Config.class)
.withCopyFilter(true)
.withCopyProject(true)
.toRule();
sql(sql)
.withDecorrelate(false)
.withTrim(true)
.withRule(filterProjectTransposeRule)
.check();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6513">[CALCITE-6513]
* FilterProjectTransposeRule may cause OOM when Project expressions are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4707,6 +4707,36 @@ LogicalProject(X1=[$0])
LogicalFilter(condition=[=(||(||(||(||('L1', $0), $0), $0), $0), 'Something')])
LogicalProject(X0=[||(||(||(||('L0', $1), $1), $1), $1)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testFilterProjectTransposeExpandFalse">
<Resource name="sql">
<![CDATA[SELECT e.deptno
FROM emp as e
WHERE exists (
SELECT *
FROM dept AS d
WHERE e.deptno = d.deptno)]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalFilter(condition=[EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})], variablesSet=[[$cor0]])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
})], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
Expand Down

0 comments on commit 9ae781d

Please sign in to comment.