Skip to content

Commit 4672ab2

Browse files
julianhydeclaude
andcommitted
[CALCITE-7420] Migrate remaining 7 tests from RelOptRulesTest to Quidem .iq format
Adds lateDecorrelate=true and operatorTable=BIG_QUERY config tokens to !sub-plan, enabling migration of tests that require these configurations. - reduce-expressions.iq: testDoubleReduction, testDoubleReduction2 (POWER and division constant folding); testSplit, testSplitNull, testSplitNull1, testSplitNull2 (BigQuery SPLIT function reduction) - project-sub-query-to-correlate.iq: testDecorrelationWithProject (EXISTS in project expanded to left join, then late decorrelation) RelOptRulesTest.java and RelOptRulesTest.xml are now empty of tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1f976b0 commit 4672ab2

File tree

5 files changed

+144
-234
lines changed

5 files changed

+144
-234
lines changed

core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,33 +2753,6 @@ private void checkPushJoinThroughUnionOnRightDoesNotMatchSemiOrAntiJoin(JoinRelT
27532753
.check();
27542754
}
27552755

2756-
/** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-2067">
2757-
* [CALCITE-2067] RexLiteral cannot represent accurately floating point values,
2758-
* including NaN, Infinity</a>. */
2759-
@Test public void testDoubleReduction() {
2760-
// Without the fix for CALCITE-2067 the result returned below is
2761-
// 1008618.49. Ironically, that result is more accurate; however
2762-
// it is not the result returned by the pow() function, which is
2763-
// 1008618.4899999999
2764-
final String sql = "SELECT power(1004.3, 2)";
2765-
sql(sql)
2766-
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
2767-
.check();
2768-
}
2769-
2770-
/** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-2067">
2771-
* [CALCITE-2067] RexLiteral cannot represent accurately floating point values,
2772-
* including NaN, Infinity</a>. */
2773-
@Test public void testDoubleReduction2() {
2774-
// Without the fix for CALCITE-2067 the following expression is not
2775-
// reduced to Infinity, since Infinity cannot be represented
2776-
// as a BigDecimal value.
2777-
final String sql2 = "SELECT 1.0 / 0.0e0";
2778-
sql(sql2)
2779-
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
2780-
.check();
2781-
}
2782-
27832756
/** Tests that {@link UnionMergeRule} does nothing if its arguments have
27842757
* are different set operators, {@link Union} and {@link Intersect}. */
27852758
@Test void testMergeSetOpMixed() {
@@ -5034,63 +5007,6 @@ private HepProgram getTransitiveProgram() {
50345007

50355008
/** Test case for non-equi outer join. */
50365009

5037-
/** Test case for
5038-
* <a href="https://issues.apache.org/jira/browse/CALCITE-5879">
5039-
* AssertionError during constant reduction of SPLIT expression that returns NULL</a>. */
5040-
@Test public void testSplitNull() {
5041-
final String query = "select split('1|2|3', NULL)";
5042-
sql(query)
5043-
.withFactory(
5044-
t -> t.withOperatorTable(opTab ->
5045-
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
5046-
SqlLibrary.BIG_QUERY))) // needed for SPLIT function
5047-
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
5048-
.check();
5049-
}
5050-
5051-
/** Test case for
5052-
* <a href="https://issues.apache.org/jira/browse/CALCITE-5879">
5053-
* AssertionError during constant reduction of SPLIT expression that returns NULL</a>. */
5054-
@Test public void testSplitNull1() {
5055-
final String query = "select split(NULL, '|')";
5056-
sql(query)
5057-
.withFactory(
5058-
t -> t.withOperatorTable(opTab ->
5059-
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
5060-
SqlLibrary.BIG_QUERY))) // needed for SPLIT function
5061-
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
5062-
.check();
5063-
}
5064-
5065-
/** Test case for
5066-
* <a href="https://issues.apache.org/jira/browse/CALCITE-5879">
5067-
* AssertionError during constant reduction of SPLIT expression that returns NULL</a>. */
5068-
@Test public void testSplitNull2() {
5069-
final String query = "select split(NULL, NULL)";
5070-
sql(query)
5071-
.withFactory(
5072-
t -> t.withOperatorTable(opTab ->
5073-
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
5074-
SqlLibrary.BIG_QUERY))) // needed for SPLIT function
5075-
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
5076-
.check();
5077-
}
5078-
5079-
/** Test case for
5080-
* <a href="https://issues.apache.org/jira/browse/CALCITE-5882">
5081-
* [CALCITE-5882] Compile-time evaluation of SPLIT function returns incorrect result</a>. */
5082-
@Test public void testSplit() {
5083-
final String query = "select split('1|2|3', '|')";
5084-
sql(query)
5085-
.withFactory(
5086-
t -> t.withOperatorTable(opTab ->
5087-
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
5088-
SqlLibrary.BIG_QUERY))) // needed for SPLIT function
5089-
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
5090-
.check();
5091-
}
5092-
5093-
50945010
/** Test case for
50955011
* <a href="https://issues.apache.org/jira/browse/CALCITE-2200">[CALCITE-2200]
50965012
* Infinite loop for JoinPushTransitivePredicatesRule</a>. */
@@ -6991,16 +6907,6 @@ public interface Config extends RelRule.Config {
69916907
* <a href="https://issues.apache.org/jira/browse/CALCITE-6176">[CALCITE-6176]
69926908
* JOIN_SUB_QUERY_TO_CORRELATE rule incorrectly handles EXISTS in LEFT JOIN ON clause</a>. */
69936909

6994-
/** Test case for
6995-
* <a href="https://issues.apache.org/jira/browse/CALCITE-2295">[CALCITE-2295]
6996-
* Correlated SubQuery with Project will generate error plan</a>. */
6997-
@Test public void testDecorrelationWithProject() throws Exception {
6998-
final String sql = "select sal,\n"
6999-
+ "exists (select * from emp_b where emp.deptno = emp_b.deptno)\n"
7000-
+ "from sales.emp";
7001-
sql(sql).withSubQueryRules().withLateDecorrelate(true).check();
7002-
}
7003-
70046910
/** Test case for
70056911
* <a href="https://issues.apache.org/jira/browse/CALCITE-3296">[CALCITE-3296]
70066912
* Decorrelator gives empty result after decorrelating sort rel with

core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,44 +2383,6 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
23832383
LogicalAggregate(group=[{0}])
23842384
LogicalProject(DEPTNO=[$7])
23852385
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
2386-
]]>
2387-
</Resource>
2388-
</TestCase>
2389-
<TestCase name="testDecorrelationWithProject">
2390-
<Resource name="sql">
2391-
<![CDATA[select sal,
2392-
exists (select * from emp_b where emp.deptno = emp_b.deptno)
2393-
from sales.emp]]>
2394-
</Resource>
2395-
<Resource name="planBefore">
2396-
<![CDATA[
2397-
LogicalProject(variablesSet=[[$cor0]], SAL=[$5], EXPR$1=[EXISTS({
2398-
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
2399-
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
2400-
})])
2401-
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
2402-
]]>
2403-
</Resource>
2404-
<Resource name="planMid">
2405-
<![CDATA[
2406-
LogicalProject(SAL=[$5], EXPR$1=[IS NOT NULL($9)])
2407-
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
2408-
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
2409-
LogicalAggregate(group=[{0}])
2410-
LogicalProject(i=[true])
2411-
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
2412-
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
2413-
]]>
2414-
</Resource>
2415-
<Resource name="planAfter">
2416-
<![CDATA[
2417-
LogicalProject(SAL=[$5], EXPR$1=[IS NOT NULL($10)])
2418-
LogicalJoin(condition=[=($7, $9)], joinType=[left])
2419-
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
2420-
LogicalProject(DEPTNO=[$0], $f1=[true])
2421-
LogicalAggregate(group=[{0}])
2422-
LogicalProject(DEPTNO=[$7])
2423-
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
24242386
]]>
24252387
</Resource>
24262388
</TestCase>
@@ -2782,40 +2744,6 @@ LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
27822744
LogicalFilter(condition=[false])
27832745
LogicalAggregate(group=[{}], agg#0=[COUNT()])
27842746
LogicalTableScan(table=[[scott, EMP]])
2785-
]]>
2786-
</Resource>
2787-
</TestCase>
2788-
<TestCase name="testDoubleReduction">
2789-
<Resource name="sql">
2790-
<![CDATA[SELECT power(1004.3, 2)]]>
2791-
</Resource>
2792-
<Resource name="planBefore">
2793-
<![CDATA[
2794-
LogicalProject(EXPR$0=[POWER(1004.3:DECIMAL(5, 1), 2)])
2795-
LogicalValues(tuples=[[{ 0 }]])
2796-
]]>
2797-
</Resource>
2798-
<Resource name="planAfter">
2799-
<![CDATA[
2800-
LogicalProject(EXPR$0=[1008618.4899999999E0:DOUBLE])
2801-
LogicalValues(tuples=[[{ 0 }]])
2802-
]]>
2803-
</Resource>
2804-
</TestCase>
2805-
<TestCase name="testDoubleReduction2">
2806-
<Resource name="sql">
2807-
<![CDATA[SELECT 1.0 / 0.0e0]]>
2808-
</Resource>
2809-
<Resource name="planBefore">
2810-
<![CDATA[
2811-
LogicalProject(EXPR$0=[/(1.0:DECIMAL(2, 1), 0.0E0:DOUBLE)])
2812-
LogicalValues(tuples=[[{ 0 }]])
2813-
]]>
2814-
</Resource>
2815-
<Resource name="planAfter">
2816-
<![CDATA[
2817-
LogicalProject(EXPR$0=[Infinity:DOUBLE])
2818-
LogicalValues(tuples=[[{ 0 }]])
28192747
]]>
28202748
</Resource>
28212749
</TestCase>
@@ -10948,74 +10876,6 @@ LogicalProject(B=[ST_BUFFER(ST_POINT(0.0:DECIMAL(2, 1), 0.0:DECIMAL(2, 1)), 1, 4
1094810876
<![CDATA[
1094910877
LogicalProject(B=[CAST(POLYGON ((1 0, 0.9238795325112867 -0.3826834323650898, 0.7071067811865476 -0.7071067811865475, 0.3826834323650898 -0.9238795325112867, 0.0000000000000001 -1, -0.3826834323650897 -0.9238795325112867, -0.7071067811865475 -0.7071067811865476, -0.9238795325112867 -0.3826834323650899, -1 -0.0000000000000001, -0.9238795325112867 0.3826834323650897, -0.7071067811865477 0.7071067811865475, -0.3826834323650903 0.9238795325112865, -0.0000000000000002 1, 0.38268343236509 0.9238795325112866, 0.7071067811865474 0.7071067811865477, 0.9238795325112865 0.3826834323650904, 1 0)):GEOMETRY):GEOMETRY])
1095010878
LogicalTableScan(table=[[CATALOG, GEO, RESTAURANTS]])
10951-
]]>
10952-
</Resource>
10953-
</TestCase>
10954-
<TestCase name="testSplit">
10955-
<Resource name="sql">
10956-
<![CDATA[select split('1|2|3', '|')]]>
10957-
</Resource>
10958-
<Resource name="planBefore">
10959-
<![CDATA[
10960-
LogicalProject(EXPR$0=[SPLIT('1|2|3', '|')])
10961-
LogicalValues(tuples=[[{ 0 }]])
10962-
]]>
10963-
</Resource>
10964-
<Resource name="planAfter">
10965-
<![CDATA[
10966-
LogicalProject(EXPR$0=[ARRAY('1':VARCHAR, '2':VARCHAR, '3':VARCHAR)])
10967-
LogicalValues(tuples=[[{ 0 }]])
10968-
]]>
10969-
</Resource>
10970-
</TestCase>
10971-
<TestCase name="testSplitNull">
10972-
<Resource name="sql">
10973-
<![CDATA[select split('1|2|3', NULL)]]>
10974-
</Resource>
10975-
<Resource name="planBefore">
10976-
<![CDATA[
10977-
LogicalProject(EXPR$0=[SPLIT('1|2|3', null:NULL)])
10978-
LogicalValues(tuples=[[{ 0 }]])
10979-
]]>
10980-
</Resource>
10981-
<Resource name="planAfter">
10982-
<![CDATA[
10983-
LogicalProject(EXPR$0=[null:VARCHAR NOT NULL ARRAY])
10984-
LogicalValues(tuples=[[{ 0 }]])
10985-
]]>
10986-
</Resource>
10987-
</TestCase>
10988-
<TestCase name="testSplitNull1">
10989-
<Resource name="sql">
10990-
<![CDATA[select split(NULL, '|')]]>
10991-
</Resource>
10992-
<Resource name="planBefore">
10993-
<![CDATA[
10994-
LogicalProject(EXPR$0=[SPLIT(null:NULL, '|')])
10995-
LogicalValues(tuples=[[{ 0 }]])
10996-
]]>
10997-
</Resource>
10998-
<Resource name="planAfter">
10999-
<![CDATA[
11000-
LogicalProject(EXPR$0=[null:VARCHAR NOT NULL ARRAY])
11001-
LogicalValues(tuples=[[{ 0 }]])
11002-
]]>
11003-
</Resource>
11004-
</TestCase>
11005-
<TestCase name="testSplitNull2">
11006-
<Resource name="sql">
11007-
<![CDATA[select split(NULL, NULL)]]>
11008-
</Resource>
11009-
<Resource name="planBefore">
11010-
<![CDATA[
11011-
LogicalProject(EXPR$0=[SPLIT(null:NULL, null:NULL)])
11012-
LogicalValues(tuples=[[{ 0 }]])
11013-
]]>
11014-
</Resource>
11015-
<Resource name="planAfter">
11016-
<![CDATA[
11017-
LogicalProject(EXPR$0=[null:VARCHAR NOT NULL ARRAY])
11018-
LogicalValues(tuples=[[{ 0 }]])
1101910879
]]>
1102010880
</Resource>
1102110881
</TestCase>

core/src/test/resources/sql/rule/project-sub-query-to-correlate.iq

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,38 @@
2222
!use scott
2323
!set outputformat mysql
2424

25+
# testDecorrelationWithProject -------------------------------------------------
26+
# PROJECT_SUB_QUERY_TO_CORRELATE expands an EXISTS in a project, then
27+
# lateDecorrelate=true decorrelates (converting LogicalCorrelate to
28+
# LogicalJoin). Not using !ok: emp_b is not in scott database.
29+
# [CALCITE-2295] Correlated SubQuery with Project will generate error plan
30+
31+
select sal,
32+
exists (select * from emp_b where emp.deptno = emp_b.deptno)
33+
from sales.emp;
34+
LogicalProject(variablesSet=[[$cor0]], SAL=[$5], EXPR$1=[EXISTS({
35+
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
36+
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
37+
})])
38+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
39+
!sub-plan "NONE"
40+
LogicalProject(SAL=[$5], EXPR$1=[IS NOT NULL($9)])
41+
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
42+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
43+
LogicalAggregate(group=[{0}])
44+
LogicalProject(i=[true])
45+
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
46+
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
47+
!sub-plan "subQueryRules, NONE"
48+
LogicalProject(SAL=[$5], EXPR$1=[IS NOT NULL($10)])
49+
LogicalJoin(condition=[=($7, $9)], joinType=[left])
50+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
51+
LogicalProject(DEPTNO=[$0], $f1=[true])
52+
LogicalAggregate(group=[{0}])
53+
LogicalProject(DEPTNO=[$7])
54+
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
55+
!sub-plan "subQueryRules, lateDecorrelate=true, NONE"
56+
2557
# testExpandProjectExists ------------------------------------------------------
2658
# Tests that an EXISTS sub-query in a project is expanded to a left join.
2759

0 commit comments

Comments
 (0)