You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/11/14 22:32:21 UTC
[13/58] [abbrv] [partial] incubator-calcite git commit: [CALCITE-306]
Standardize code style for "import package.*; "
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 7c7472d..63038fe 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -14,63 +14,60 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.util.List;
-
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.rel.TableModificationRel;
-import org.eigenbase.rel.metadata.CachingRelMetadataProvider;
-import org.eigenbase.rel.metadata.ChainedRelMetadataProvider;
-import org.eigenbase.rel.metadata.DefaultRelMetadataProvider;
-import org.eigenbase.rel.metadata.RelMetadataProvider;
-import org.eigenbase.rel.rules.AddRedundantSemiJoinRule;
-import org.eigenbase.rel.rules.AggregateProjectMergeRule;
-import org.eigenbase.rel.rules.CoerceInputsRule;
-import org.eigenbase.rel.rules.ConvertMultiJoinRule;
-import org.eigenbase.rel.rules.ExtractJoinFilterRule;
-import org.eigenbase.rel.rules.FilterAggregateTransposeRule;
-import org.eigenbase.rel.rules.FilterToCalcRule;
-import org.eigenbase.rel.rules.MergeCalcRule;
-import org.eigenbase.rel.rules.MergeProjectRule;
-import org.eigenbase.rel.rules.ProjectToCalcRule;
-import org.eigenbase.rel.rules.PullConstantsThroughAggregatesRule;
-import org.eigenbase.rel.rules.PushAggregateThroughUnionRule;
-import org.eigenbase.rel.rules.PushFilterPastJoinRule;
-import org.eigenbase.rel.rules.PushFilterPastProjectRule;
-import org.eigenbase.rel.rules.PushFilterPastSetOpRule;
-import org.eigenbase.rel.rules.PushJoinThroughUnionRule;
-import org.eigenbase.rel.rules.PushProjectPastFilterRule;
-import org.eigenbase.rel.rules.PushProjectPastJoinRule;
-import org.eigenbase.rel.rules.PushProjectPastSetOpRule;
-import org.eigenbase.rel.rules.PushSemiJoinPastFilterRule;
-import org.eigenbase.rel.rules.PushSemiJoinPastJoinRule;
-import org.eigenbase.rel.rules.PushSemiJoinPastProjectRule;
-import org.eigenbase.rel.rules.ReduceAggregatesRule;
-import org.eigenbase.rel.rules.ReduceExpressionsRule;
-import org.eigenbase.rel.rules.ReduceValuesRule;
-import org.eigenbase.rel.rules.RemoveDistinctAggregateRule;
-import org.eigenbase.rel.rules.RemoveEmptyRules;
-import org.eigenbase.rel.rules.RemoveSemiJoinRule;
-import org.eigenbase.rel.rules.RemoveTrivialProjectRule;
-import org.eigenbase.rel.rules.SemiJoinRule;
-import org.eigenbase.rel.rules.TableAccessRule;
-import org.eigenbase.rel.rules.TransitivePredicatesOnJoinRule;
-import org.eigenbase.rel.rules.UnionToDistinctRule;
-import org.eigenbase.relopt.RelOptUtil;
-import org.eigenbase.relopt.hep.HepMatchOrder;
-import org.eigenbase.relopt.hep.HepPlanner;
-import org.eigenbase.relopt.hep.HepProgram;
-import org.eigenbase.relopt.hep.HepProgramBuilder;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeFactory;
-import org.eigenbase.sql.SqlNode;
-import org.eigenbase.sql.type.SqlTypeName;
-import org.eigenbase.sql.validate.SqlValidator;
-import org.eigenbase.sql2rel.SqlToRelConverter;
-import org.eigenbase.util.Util;
-
-import net.hydromatic.optiq.prepare.Prepare;
+package org.apache.calcite.test;
+
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.hep.HepMatchOrder;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.plan.hep.HepProgramBuilder;
+import org.apache.calcite.prepare.Prepare;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalTableModify;
+import org.apache.calcite.rel.metadata.CachingRelMetadataProvider;
+import org.apache.calcite.rel.metadata.ChainedRelMetadataProvider;
+import org.apache.calcite.rel.metadata.DefaultRelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelMetadataProvider;
+import org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule;
+import org.apache.calcite.rel.rules.AggregateProjectMergeRule;
+import org.apache.calcite.rel.rules.AggregateProjectPullUpConstantsRule;
+import org.apache.calcite.rel.rules.AggregateReduceFunctionsRule;
+import org.apache.calcite.rel.rules.AggregateUnionTransposeRule;
+import org.apache.calcite.rel.rules.CalcMergeRule;
+import org.apache.calcite.rel.rules.CoerceInputsRule;
+import org.apache.calcite.rel.rules.EmptyPruneRules;
+import org.apache.calcite.rel.rules.FilterAggregateTransposeRule;
+import org.apache.calcite.rel.rules.FilterJoinRule;
+import org.apache.calcite.rel.rules.FilterProjectTransposeRule;
+import org.apache.calcite.rel.rules.FilterSetOpTransposeRule;
+import org.apache.calcite.rel.rules.FilterToCalcRule;
+import org.apache.calcite.rel.rules.JoinAddRedundantSemiJoinRule;
+import org.apache.calcite.rel.rules.JoinExtractFilterRule;
+import org.apache.calcite.rel.rules.JoinPushTransitivePredicatesRule;
+import org.apache.calcite.rel.rules.JoinToMultiJoinRule;
+import org.apache.calcite.rel.rules.JoinUnionTransposeRule;
+import org.apache.calcite.rel.rules.ProjectFilterTransposeRule;
+import org.apache.calcite.rel.rules.ProjectJoinTransposeRule;
+import org.apache.calcite.rel.rules.ProjectMergeRule;
+import org.apache.calcite.rel.rules.ProjectRemoveRule;
+import org.apache.calcite.rel.rules.ProjectSetOpTransposeRule;
+import org.apache.calcite.rel.rules.ProjectToCalcRule;
+import org.apache.calcite.rel.rules.ReduceExpressionsRule;
+import org.apache.calcite.rel.rules.SemiJoinFilterTransposeRule;
+import org.apache.calcite.rel.rules.SemiJoinJoinTransposeRule;
+import org.apache.calcite.rel.rules.SemiJoinProjectTransposeRule;
+import org.apache.calcite.rel.rules.SemiJoinRemoveRule;
+import org.apache.calcite.rel.rules.SemiJoinRule;
+import org.apache.calcite.rel.rules.TableScanRule;
+import org.apache.calcite.rel.rules.UnionToDistinctRule;
+import org.apache.calcite.rel.rules.ValuesReduceRule;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql2rel.SqlToRelConverter;
+import org.apache.calcite.util.Util;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
@@ -78,14 +75,16 @@ import com.google.common.collect.Lists;
import org.junit.Ignore;
import org.junit.Test;
+import java.util.List;
+
import static org.junit.Assert.assertTrue;
/**
- * Unit test for rules in {@code org.eigenbase.rel} and subpackages.
+ * Unit test for rules in {@code org.apache.calcite.rel} and subpackages.
*
* <p>As input, the test supplies a SQL statement and a single rule; the SQL is
* translated into relational algebra and then fed into a
- * {@link org.eigenbase.relopt.hep.HepPlanner}. The planner fires the rule on
+ * {@link org.apache.calcite.plan.hep.HepPlanner}. The planner fires the rule on
* every
* pattern match in a depth-first left-to-right preorder traversal of the tree
* for as long as the rule continues to succeed in applying its transform. (For
@@ -128,20 +127,17 @@ public class RelOptRulesTest extends RelOptTestBase {
}
@Test public void testUnionToDistinctRule() {
- checkPlanning(
- UnionToDistinctRule.INSTANCE,
+ checkPlanning(UnionToDistinctRule.INSTANCE,
"select * from dept union select * from dept");
}
@Test public void testExtractJoinFilterRule() {
- checkPlanning(
- ExtractJoinFilterRule.INSTANCE,
+ checkPlanning(JoinExtractFilterRule.INSTANCE,
"select 1 from emp inner join dept on emp.deptno=dept.deptno");
}
@Test public void testAddRedundantSemiJoinRule() {
- checkPlanning(
- AddRedundantSemiJoinRule.INSTANCE,
+ checkPlanning(JoinAddRedundantSemiJoinRule.INSTANCE,
"select 1 from emp inner join dept on emp.deptno = dept.deptno");
}
@@ -151,68 +147,62 @@ public class RelOptRulesTest extends RelOptTestBase {
// NULL.
final HepProgram preProgram =
HepProgram.builder()
- .addRuleInstance(MergeProjectRule.INSTANCE)
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
.build();
final HepProgram program =
HepProgram.builder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
.build();
checkPlanning(tester.withDecorrelation(true).withTrim(true), preProgram,
new HepPlanner(program),
"select * from dept where exists (\n"
- + " select * from emp\n"
- + " where emp.deptno = dept.deptno\n"
- + " and emp.sal > 100)");
+ + " select * from emp\n"
+ + " where emp.deptno = dept.deptno\n"
+ + " and emp.sal > 100)");
}
@Test public void testFullOuterJoinSimplificationToLeftOuter() {
- checkPlanning(
- PushFilterPastJoinRule.FILTER_ON_JOIN,
+ checkPlanning(FilterJoinRule.FILTER_ON_JOIN,
"select 1 from sales.dept d full outer join sales.emp e"
- + " on d.deptno = e.deptno"
- + " where d.name = 'Charlie'");
+ + " on d.deptno = e.deptno"
+ + " where d.name = 'Charlie'");
}
@Test public void testFullOuterJoinSimplificationToRightOuter() {
- checkPlanning(
- PushFilterPastJoinRule.FILTER_ON_JOIN,
+ checkPlanning(FilterJoinRule.FILTER_ON_JOIN,
"select 1 from sales.dept d full outer join sales.emp e"
- + " on d.deptno = e.deptno"
- + " where e.sal > 100");
+ + " on d.deptno = e.deptno"
+ + " where e.sal > 100");
}
@Test public void testFullOuterJoinSimplificationToInner() {
- checkPlanning(
- PushFilterPastJoinRule.FILTER_ON_JOIN,
+ checkPlanning(FilterJoinRule.FILTER_ON_JOIN,
"select 1 from sales.dept d full outer join sales.emp e"
- + " on d.deptno = e.deptno"
- + " where d.name = 'Charlie' and e.sal > 100");
+ + " on d.deptno = e.deptno"
+ + " where d.name = 'Charlie' and e.sal > 100");
}
@Test public void testLeftOuterJoinSimplificationToInner() {
- checkPlanning(
- PushFilterPastJoinRule.FILTER_ON_JOIN,
+ checkPlanning(FilterJoinRule.FILTER_ON_JOIN,
"select 1 from sales.dept d left outer join sales.emp e"
- + " on d.deptno = e.deptno"
- + " where e.sal > 100");
+ + " on d.deptno = e.deptno"
+ + " where e.sal > 100");
}
@Test public void testRightOuterJoinSimplificationToInner() {
- checkPlanning(
- PushFilterPastJoinRule.FILTER_ON_JOIN,
+ checkPlanning(FilterJoinRule.FILTER_ON_JOIN,
"select 1 from sales.dept d right outer join sales.emp e"
- + " on d.deptno = e.deptno"
- + " where d.name = 'Charlie'");
+ + " on d.deptno = e.deptno"
+ + " where d.name = 'Charlie'");
}
@Test public void testPushFilterPastAgg() {
- checkPlanning(
- FilterAggregateTransposeRule.INSTANCE,
+ checkPlanning(FilterAggregateTransposeRule.INSTANCE,
"select dname, c from"
- + " (select name dname, count(*) as c from dept group by name) t"
- + " where dname = 'Charlie'");
+ + " (select name dname, count(*) as c from dept group by name) t"
+ + " where dname = 'Charlie'");
}
/** Test case for
@@ -221,17 +211,17 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testPushFilterPastAggTwo() {
checkPlanning(FilterAggregateTransposeRule.INSTANCE,
"select dept1.c1 from (\n"
- + " select dept.name as c1, count(*) as c2\n"
- + " from dept where dept.name > 'b' group by dept.name) dept1\n"
- + "where dept1.c1 > 'c' and (dept1.c2 > 30 or dept1.c1 < 'z')");
+ + " select dept.name as c1, count(*) as c2\n"
+ + " from dept where dept.name > 'b' group by dept.name) dept1\n"
+ + "where dept1.c1 > 'c' and (dept1.c2 > 30 or dept1.c1 < 'z')");
}
@Test public void testSemiJoinRule() {
final HepProgram preProgram =
HepProgram.builder()
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(MergeProjectRule.INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
.build();
final HepProgram program =
HepProgram.builder()
@@ -247,7 +237,7 @@ public class RelOptRulesTest extends RelOptTestBase {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-438">[CALCITE-438],
- * Push predicates through SemiJoinRel</a>. */
+ * Push predicates through SemiJoin</a>. */
@Test public void testPushFilterThroughSemiJoin() {
final HepProgram preProgram =
HepProgram.builder()
@@ -256,9 +246,9 @@ public class RelOptRulesTest extends RelOptTestBase {
final HepProgram program =
HepProgram.builder()
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(PushFilterPastJoinRule.JOIN)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(FilterJoinRule.JOIN)
.build();
checkPlanning(tester.withDecorrelation(true).withTrim(false), preProgram,
new HepPlanner(program),
@@ -298,9 +288,9 @@ public class RelOptRulesTest extends RelOptTestBase {
final HepProgram program =
HepProgram.builder()
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(MergeProjectRule.INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
.addRuleInstance(SemiJoinRule.INSTANCE)
.build();
@@ -321,66 +311,60 @@ public class RelOptRulesTest extends RelOptTestBase {
}
@Test public void testReduceAverage() {
- checkPlanning(
- ReduceAggregatesRule.INSTANCE,
+ checkPlanning(AggregateReduceFunctionsRule.INSTANCE,
"select name, max(name), avg(deptno), min(name)"
- + " from sales.dept group by name");
+ + " from sales.dept group by name");
}
@Test public void testDistinctCount() {
final HepProgram program = HepProgram.builder()
- .addRuleInstance(RemoveDistinctAggregateRule.INSTANCE)
+ .addRuleInstance(AggregateExpandDistinctAggregatesRule.INSTANCE)
.addRuleInstance(AggregateProjectMergeRule.INSTANCE)
.build();
checkPlanning(program,
"select deptno, count(distinct ename)"
- + " from sales.emp group by deptno");
+ + " from sales.emp group by deptno");
}
@Test public void testPushProjectPastFilter() {
- checkPlanning(
- PushProjectPastFilterRule.INSTANCE,
+ checkPlanning(ProjectFilterTransposeRule.INSTANCE,
"select empno + deptno from emp where sal = 10 * comm "
- + "and upper(ename) = 'FOO'");
+ + "and upper(ename) = 'FOO'");
}
@Test public void testPushProjectPastJoin() {
- checkPlanning(
- PushProjectPastJoinRule.INSTANCE,
+ checkPlanning(ProjectJoinTransposeRule.INSTANCE,
"select e.sal + b.comm from emp e inner join bonus b "
- + "on e.ename = b.ename and e.deptno = 10");
+ + "on e.ename = b.ename and e.deptno = 10");
}
@Test public void testPushProjectPastSetOp() {
- checkPlanning(
- PushProjectPastSetOpRule.INSTANCE,
+ checkPlanning(ProjectSetOpTransposeRule.INSTANCE,
"select sal from "
- + "(select * from emp e1 union all select * from emp e2)");
+ + "(select * from emp e1 union all select * from emp e2)");
}
@Test public void testPushJoinThroughUnionOnLeft() {
- checkPlanning(
- PushJoinThroughUnionRule.LEFT_UNION,
+ checkPlanning(JoinUnionTransposeRule.LEFT_UNION,
"select r1.sal from "
- + "(select * from emp e1 union all select * from emp e2) r1, "
- + "emp r2");
+ + "(select * from emp e1 union all select * from emp e2) r1, "
+ + "emp r2");
}
@Test public void testPushJoinThroughUnionOnRight() {
- checkPlanning(
- PushJoinThroughUnionRule.RIGHT_UNION,
+ checkPlanning(JoinUnionTransposeRule.RIGHT_UNION,
"select r1.sal from "
- + "emp r1, "
- + "(select * from emp e1 union all select * from emp e2) r2");
+ + "emp r1, "
+ + "(select * from emp e1 union all select * from emp e2) r2");
}
@Ignore("cycles")
@Test public void testMergeFilterWithJoinCondition() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(TableAccessRule.INSTANCE)
- .addRuleInstance(ExtractJoinFilterRule.INSTANCE)
+ .addRuleInstance(TableScanRule.INSTANCE)
+ .addRuleInstance(JoinExtractFilterRule.INSTANCE)
.addRuleInstance(FilterToCalcRule.INSTANCE)
- .addRuleInstance(MergeCalcRule.INSTANCE)
+ .addRuleInstance(CalcMergeRule.INSTANCE)
//.addRuleInstance(FennelCalcRule.instance);
//.addRuleInstance(FennelCartesianJoinRule.instance);
.addRuleInstance(ProjectToCalcRule.INSTANCE)
@@ -388,9 +372,9 @@ public class RelOptRulesTest extends RelOptTestBase {
checkPlanning(program,
"select d.name as dname,e.ename as ename"
- + " from emp e inner join dept d"
- + " on e.deptno=d.deptno"
- + " where d.name='Propane'");
+ + " from emp e inner join dept d"
+ + " on e.deptno=d.deptno"
+ + " where d.name='Propane'");
}
@Ignore("cycles")
@@ -406,7 +390,7 @@ public class RelOptRulesTest extends RelOptTestBase {
// and verify that it only applies to one usage of the
// table, not both (which would be incorrect).
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(TableAccessRule.INSTANCE)
+ .addRuleInstance(TableScanRule.INSTANCE)
.addRuleInstance(ProjectToCalcRule.INSTANCE)
// Control the calc conversion.
@@ -418,53 +402,53 @@ public class RelOptRulesTest extends RelOptTestBase {
checkPlanning(program,
"select upper(ename) from emp union all"
- + " select lower(ename) from emp");
+ + " select lower(ename) from emp");
}
@Test public void testPushSemiJoinPastJoinRuleLeft() throws Exception {
// tests the case where the semijoin is pushed to the left
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastJoinRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinJoinTransposeRule.INSTANCE)
.build();
checkPlanning(program,
"select e1.ename from emp e1, dept d, emp e2 "
- + "where e1.deptno = d.deptno and e1.empno = e2.empno");
+ + "where e1.deptno = d.deptno and e1.empno = e2.empno");
}
@Test public void testPushSemiJoinPastJoinRuleRight() throws Exception {
// tests the case where the semijoin is pushed to the right
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastJoinRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinJoinTransposeRule.INSTANCE)
.build();
checkPlanning(program,
"select e1.ename from emp e1, dept d, emp e2 "
- + "where e1.deptno = d.deptno and d.deptno = e2.deptno");
+ + "where e1.deptno = d.deptno and d.deptno = e2.deptno");
}
@Test public void testPushSemiJoinPastFilter() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastFilterRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinFilterTransposeRule.INSTANCE)
.build();
checkPlanning(program,
"select e.ename from emp e, dept d "
- + "where e.deptno = d.deptno and e.ename = 'foo'");
+ + "where e.deptno = d.deptno and e.ename = 'foo'");
}
@Test public void testConvertMultiJoinRule() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
.addMatchOrder(HepMatchOrder.BOTTOM_UP)
- .addRuleInstance(ConvertMultiJoinRule.INSTANCE)
+ .addRuleInstance(JoinToMultiJoinRule.INSTANCE)
.build();
checkPlanning(program,
"select e1.ename from emp e1, dept d, emp e2 "
- + "where e1.deptno = d.deptno and d.deptno = e2.deptno");
+ + "where e1.deptno = d.deptno and d.deptno = e2.deptno");
}
@Test public void testReduceConstants() throws Exception {
@@ -482,10 +466,10 @@ public class RelOptRulesTest extends RelOptTestBase {
// NULL" and we need "INTEGER".
checkPlanning(program,
"select 1+2, d.deptno+(3+4), (5+6)+d.deptno, cast(null as integer),"
- + " coalesce(2,null), row(7+8)"
- + " from dept d inner join emp e"
- + " on d.deptno = e.deptno + (5-5)"
- + " where d.deptno=(7+8) and d.deptno=coalesce(2,null)");
+ + " coalesce(2,null), row(7+8)"
+ + " from dept d inner join emp e"
+ + " on d.deptno = e.deptno + (5-5)"
+ + " where d.deptno=(7+8) and d.deptno=coalesce(2,null)");
}
@Test public void testReduceConstants2() throws Exception {
@@ -528,17 +512,17 @@ public class RelOptRulesTest extends RelOptTestBase {
// and reduce it to TRUE. Only in the Calc are projects and conditions
// combined.
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(PushFilterPastSetOpRule.INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(FilterSetOpTransposeRule.INSTANCE)
.addRuleInstance(FilterToCalcRule.INSTANCE)
.addRuleInstance(ProjectToCalcRule.INSTANCE)
- .addRuleInstance(MergeCalcRule.INSTANCE)
+ .addRuleInstance(CalcMergeRule.INSTANCE)
.addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE)
// the hard part is done... a few more rule calls to clean up
- .addRuleInstance(RemoveEmptyRules.UNION_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.UNION_INSTANCE)
.addRuleInstance(ProjectToCalcRule.INSTANCE)
- .addRuleInstance(MergeCalcRule.INSTANCE)
+ .addRuleInstance(CalcMergeRule.INSTANCE)
.addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE)
.build();
@@ -546,65 +530,65 @@ public class RelOptRulesTest extends RelOptTestBase {
// SELECT * FROM (VALUES ('TABLE ', 'T')) AS T(U, S)
checkPlanning(program,
"select * from (\n"
- + " select upper(substring(x FROM 1 FOR 2) || substring(x FROM 3)) as u,\n"
- + " substring(x FROM 1 FOR 1) as s\n"
- + " from (\n"
- + " select 'table' as x from (values (true))\n"
- + " union\n"
- + " select 'view' from (values (true))\n"
- + " union\n"
- + " select 'foreign table' from (values (true))\n"
- + " )\n"
- + ") where u = 'TABLE'");
+ + " select upper(substring(x FROM 1 FOR 2) || substring(x FROM 3)) as u,\n"
+ + " substring(x FROM 1 FOR 1) as s\n"
+ + " from (\n"
+ + " select 'table' as x from (values (true))\n"
+ + " union\n"
+ + " select 'view' from (values (true))\n"
+ + " union\n"
+ + " select 'foreign table' from (values (true))\n"
+ + " )\n"
+ + ") where u = 'TABLE'");
}
@Test public void testRemoveSemiJoin() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(RemoveSemiJoinRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinRemoveRule.INSTANCE)
.build();
checkPlanning(program,
"select e.ename from emp e, dept d "
- + "where e.deptno = d.deptno");
+ + "where e.deptno = d.deptno");
}
@Test public void testRemoveSemiJoinWithFilter() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastFilterRule.INSTANCE)
- .addRuleInstance(RemoveSemiJoinRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinFilterTransposeRule.INSTANCE)
+ .addRuleInstance(SemiJoinRemoveRule.INSTANCE)
.build();
checkPlanning(program,
"select e.ename from emp e, dept d "
- + "where e.deptno = d.deptno and e.ename = 'foo'");
+ + "where e.deptno = d.deptno and e.ename = 'foo'");
}
@Test public void testRemoveSemiJoinRight() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastJoinRule.INSTANCE)
- .addRuleInstance(RemoveSemiJoinRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinJoinTransposeRule.INSTANCE)
+ .addRuleInstance(SemiJoinRemoveRule.INSTANCE)
.build();
checkPlanning(program,
"select e1.ename from emp e1, dept d, emp e2 "
- + "where e1.deptno = d.deptno and d.deptno = e2.deptno");
+ + "where e1.deptno = d.deptno and d.deptno = e2.deptno");
}
@Test public void testRemoveSemiJoinRightWithFilter() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastFilterRule.INSTANCE)
- .addRuleInstance(RemoveSemiJoinRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinJoinTransposeRule.INSTANCE)
+ .addRuleInstance(SemiJoinFilterTransposeRule.INSTANCE)
+ .addRuleInstance(SemiJoinRemoveRule.INSTANCE)
.build();
checkPlanning(program,
"select e1.ename from emp e1, dept d, emp e2 "
- + "where e1.deptno = d.deptno and d.deptno = e2.deptno "
- + "and d.name = 'foo'");
+ + "where e1.deptno = d.deptno and d.deptno = e2.deptno "
+ + "and d.name = 'foo'");
}
private void checkPlanning(String query) throws Exception {
@@ -612,8 +596,7 @@ public class RelOptRulesTest extends RelOptTestBase {
new Function<RelDataTypeFactory, Prepare.CatalogReader>() {
public Prepare.CatalogReader apply(RelDataTypeFactory typeFactory) {
return new MockCatalogReader(typeFactory, true) {
- @Override
- public MockCatalogReader init() {
+ @Override public MockCatalogReader init() {
// CREATE SCHEMA abc;
// CREATE TABLE a(a INT);
// ...
@@ -636,8 +619,8 @@ public class RelOptRulesTest extends RelOptTestBase {
});
HepProgram program = new HepProgramBuilder()
.addMatchOrder(HepMatchOrder.BOTTOM_UP)
- .addRuleInstance(RemoveTrivialProjectRule.INSTANCE)
- .addRuleInstance(ConvertMultiJoinRule.INSTANCE)
+ .addRuleInstance(ProjectRemoveRule.INSTANCE)
+ .addRuleInstance(JoinToMultiJoinRule.INSTANCE)
.build();
checkPlanning(tester1, null,
new HepPlanner(program), query);
@@ -665,38 +648,38 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testConvertMultiJoinRuleOuterJoins2() throws Exception {
// in (A right join B) join C, pushing C is not allowed;
- // therefore there should be 2 MultiJoinRel
+ // therefore there should be 2 MultiJoin
checkPlanning("select * from A right join B on a = b join C on b = c");
}
@Test public void testConvertMultiJoinRuleOuterJoins3() throws Exception {
// in (A join B) left join C, pushing C is allowed;
- // therefore there should be 1 MultiJoinRel
+ // therefore there should be 1 MultiJoin
checkPlanning("select * from A join B on a = b left join C on b = c");
}
@Test public void testConvertMultiJoinRuleOuterJoins4() throws Exception {
// in (A join B) right join C, pushing C is not allowed;
- // therefore there should be 2 MultiJoinRel
+ // therefore there should be 2 MultiJoin
checkPlanning("select * from A join B on a = b right join C on b = c");
}
@Test public void testPushSemiJoinPastProject() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.FILTER_ON_JOIN)
- .addRuleInstance(AddRedundantSemiJoinRule.INSTANCE)
- .addRuleInstance(PushSemiJoinPastProjectRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
+ .addRuleInstance(JoinAddRedundantSemiJoinRule.INSTANCE)
+ .addRuleInstance(SemiJoinProjectTransposeRule.INSTANCE)
.build();
checkPlanning(program,
"select e.* from "
- + "(select ename, trim(job), sal * 2, deptno from emp) e, dept d "
- + "where e.deptno = d.deptno");
+ + "(select ename, trim(job), sal * 2, deptno from emp) e, dept d "
+ + "where e.deptno = d.deptno");
}
@Test public void testReduceValuesUnderFilter() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(ReduceValuesRule.FILTER_INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(ValuesReduceRule.FILTER_INSTANCE)
.build();
// Plan should be same as for
@@ -707,8 +690,8 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testReduceValuesUnderProject() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(MergeProjectRule.INSTANCE)
- .addRuleInstance(ReduceValuesRule.PROJECT_INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
+ .addRuleInstance(ValuesReduceRule.PROJECT_INSTANCE)
.build();
// Plan should be same as for
@@ -719,16 +702,16 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testReduceValuesUnderProjectFilter() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(MergeProjectRule.INSTANCE)
- .addRuleInstance(ReduceValuesRule.PROJECT_FILTER_INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
+ .addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE)
.build();
// Plan should be same as for
// select * from (values (11, 1, 10), (23, 3, 20)) as t(x, b, a)");
checkPlanning(program,
"select a + b as x, b, a from (values (10, 1), (30, 7), (20, 3)) as t(a, b)"
- + " where a - b < 21");
+ + " where a - b < 21");
}
@Ignore // Calcite does not support INSERT yet
@@ -736,7 +719,7 @@ public class RelOptRulesTest extends RelOptTestBase {
// The NULL literal presents pitfalls for value-reduction. Only
// an INSERT statement contains un-CASTed NULL values.
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(ReduceValuesRule.PROJECT_INSTANCE)
+ .addRuleInstance(ValuesReduceRule.PROJECT_INSTANCE)
.build();
checkPlanning(program,
"insert into sales.depts(deptno,name) values (NULL, 'null')");
@@ -744,89 +727,89 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testReduceValuesToEmpty() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(MergeProjectRule.INSTANCE)
- .addRuleInstance(ReduceValuesRule.PROJECT_FILTER_INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
+ .addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE)
.build();
// Plan should be same as for
// select * from (values (11, 1, 10), (23, 3, 20)) as t(x, b, a)");
checkPlanning(program,
"select a + b as x, b, a from (values (10, 1), (30, 7)) as t(a, b)"
- + " where a - b < 0");
+ + " where a - b < 0");
}
@Test public void testEmptyFilterProjectUnion() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastSetOpRule.INSTANCE)
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(MergeProjectRule.INSTANCE)
- .addRuleInstance(ReduceValuesRule.PROJECT_FILTER_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.PROJECT_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.UNION_INSTANCE)
+ .addRuleInstance(FilterSetOpTransposeRule.INSTANCE)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
+ .addRuleInstance(ValuesReduceRule.PROJECT_FILTER_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.PROJECT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.UNION_INSTANCE)
.build();
// Plan should be same as for
// select * from (values (30, 3)) as t(x, y)");
checkPlanning(program,
"select * from (\n"
- + "select * from (values (10, 1), (30, 3)) as t (x, y)\n"
- + "union all\n"
- + "select * from (values (20, 2))\n"
- + ")\n"
- + "where x + y > 30");
+ + "select * from (values (10, 1), (30, 3)) as t (x, y)\n"
+ + "union all\n"
+ + "select * from (values (20, 2))\n"
+ + ")\n"
+ + "where x + y > 30");
}
@Test public void testEmptyJoin() {
HepProgram program = new HepProgramBuilder()
.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.PROJECT_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.JOIN_LEFT_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.JOIN_RIGHT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.PROJECT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.JOIN_LEFT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.JOIN_RIGHT_INSTANCE)
.build();
// Plan should be empty
checkPlanning(program,
"select * from (\n"
- + "select * from emp where false)\n"
- + "join dept using (deptno)");
+ + "select * from emp where false)\n"
+ + "join dept using (deptno)");
}
@Test public void testEmptyJoinLeft() {
HepProgram program = new HepProgramBuilder()
.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.PROJECT_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.JOIN_LEFT_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.JOIN_RIGHT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.PROJECT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.JOIN_LEFT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.JOIN_RIGHT_INSTANCE)
.build();
// Plan should be empty
checkPlanning(program,
"select * from (\n"
- + "select * from emp where false)\n"
- + "left join dept using (deptno)");
+ + "select * from emp where false)\n"
+ + "left join dept using (deptno)");
}
@Test public void testEmptyJoinRight() {
HepProgram program = new HepProgramBuilder()
.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.PROJECT_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.JOIN_LEFT_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.JOIN_RIGHT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.PROJECT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.JOIN_LEFT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.JOIN_RIGHT_INSTANCE)
.build();
// Plan should be equivalent to "select * from emp join dept".
// Cannot optimize away the join because of RIGHT.
checkPlanning(program,
"select * from (\n"
- + "select * from emp where false)\n"
- + "right join dept using (deptno)");
+ + "select * from emp where false)\n"
+ + "right join dept using (deptno)");
}
@Test public void testEmptySort() {
HepProgram program = new HepProgramBuilder()
.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
- .addRuleInstance(RemoveEmptyRules.SORT_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.SORT_INSTANCE)
.build();
checkPlanning(program,
@@ -835,7 +818,7 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testEmptySortLimitZero() {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(RemoveEmptyRules.SORT_FETCH_ZERO_INSTANCE)
+ .addRuleInstance(EmptyPruneRules.SORT_FETCH_ZERO_INSTANCE)
.build();
checkPlanning(program,
@@ -852,9 +835,9 @@ public class RelOptRulesTest extends RelOptTestBase {
// The resulting plan should have no cast expressions
checkPlanning(program,
"select cast(d.name as varchar(128)), cast(e.empno as integer) "
- + "from dept as d inner join emp as e "
- + "on cast(d.deptno as integer) = cast(e.deptno as integer) "
- + "where cast(e.job as varchar(1)) = 'Manager'");
+ + "from dept as d inner join emp as e "
+ + "on cast(d.deptno as integer) = cast(e.deptno as integer) "
+ + "where cast(e.job as varchar(1)) = 'Manager'");
}
@Test public void testReduceCastAndConsts() throws Exception {
@@ -866,7 +849,7 @@ public class RelOptRulesTest extends RelOptTestBase {
// in addition to the casts.
checkPlanning(program,
"select * from emp "
- + "where cast((empno + (10/2)) as int) = 13");
+ + "where cast((empno + (10/2)) as int) = 13");
}
@Ignore // Calcite does not support INSERT yet
@@ -875,24 +858,24 @@ public class RelOptRulesTest extends RelOptTestBase {
// Simulate the way INSERT will insert casts to the target types
.addRuleInstance(
- new CoerceInputsRule(TableModificationRel.class, false))
+ new CoerceInputsRule(LogicalTableModify.class, false))
// Convert projects to calcs, merge two calcs, and then
// reduce redundant casts in merged calc.
.addRuleInstance(ProjectToCalcRule.INSTANCE)
- .addRuleInstance(MergeCalcRule.INSTANCE)
+ .addRuleInstance(CalcMergeRule.INSTANCE)
.addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE)
.build();
checkPlanning(program,
"insert into sales.depts(name) "
- + "select cast(gender as varchar(128)) from sales.emps");
+ + "select cast(gender as varchar(128)) from sales.emps");
}
private void basePushAggThroughUnion() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushProjectPastSetOpRule.INSTANCE)
- .addRuleInstance(MergeProjectRule.INSTANCE)
- .addRuleInstance(PushAggregateThroughUnionRule.INSTANCE)
+ .addRuleInstance(ProjectSetOpTransposeRule.INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
+ .addRuleInstance(AggregateUnionTransposeRule.INSTANCE)
.build();
checkPlanning(program, "${sql}");
}
@@ -940,9 +923,9 @@ public class RelOptRulesTest extends RelOptTestBase {
private void basePullConstantTroughAggregate() throws Exception {
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(MergeProjectRule.INSTANCE)
- .addRuleInstance(PullConstantsThroughAggregatesRule.INSTANCE)
- .addRuleInstance(MergeProjectRule.INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
+ .addRuleInstance(AggregateProjectPullUpConstantsRule.INSTANCE)
+ .addRuleInstance(ProjectMergeRule.INSTANCE)
.build();
checkPlanning(program, "${sql}");
}
@@ -993,9 +976,9 @@ public class RelOptRulesTest extends RelOptTestBase {
.build();
checkPlanning(program,
"select x, sum(z), y from (\n"
- + " select deptno as x, empno as y, sal as z, sal * 2 as zz\n"
- + " from emp)\n"
- + "group by x, y");
+ + " select deptno as x, empno as y, sal as z, sal * 2 as zz\n"
+ + " from emp)\n"
+ + "group by x, y");
}
public void transitiveInference() throws Exception {
@@ -1003,10 +986,10 @@ public class RelOptRulesTest extends RelOptTestBase {
String sql = diffRepos.expand(null, "${sql}");
HepProgram program = new HepProgramBuilder()
- .addRuleInstance(PushFilterPastJoinRule.DUMB_FILTER_ON_JOIN)
- .addRuleInstance(PushFilterPastJoinRule.JOIN)
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(PushFilterPastSetOpRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.DUMB_FILTER_ON_JOIN)
+ .addRuleInstance(FilterJoinRule.JOIN)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(FilterSetOpTransposeRule.INSTANCE)
.build();
HepPlanner planner = new HepPlanner(program);
@@ -1031,11 +1014,11 @@ public class RelOptRulesTest extends RelOptTestBase {
HepProgram program2 = new HepProgramBuilder()
.addMatchOrder(HepMatchOrder.BOTTOM_UP)
- .addRuleInstance(PushFilterPastJoinRule.DUMB_FILTER_ON_JOIN)
- .addRuleInstance(PushFilterPastJoinRule.JOIN)
- .addRuleInstance(PushFilterPastProjectRule.INSTANCE)
- .addRuleInstance(PushFilterPastSetOpRule.INSTANCE)
- .addRuleInstance(TransitivePredicatesOnJoinRule.INSTANCE)
+ .addRuleInstance(FilterJoinRule.DUMB_FILTER_ON_JOIN)
+ .addRuleInstance(FilterJoinRule.JOIN)
+ .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
+ .addRuleInstance(FilterSetOpTransposeRule.INSTANCE)
+ .addRuleInstance(JoinPushTransitivePredicatesRule.INSTANCE)
.build();
HepPlanner planner2 = new HepPlanner(program2);
planner.registerMetadataProviders(list);
@@ -1126,7 +1109,7 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testPushFilterWithRank() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(
- PushFilterPastProjectRule.INSTANCE).build();
+ FilterProjectTransposeRule.INSTANCE).build();
checkPlanning(program, "select e1.ename, r\n"
+ "from (\n"
+ " select ename, "
@@ -1137,7 +1120,7 @@ public class RelOptRulesTest extends RelOptTestBase {
@Test public void testPushFilterWithRankExpr() throws Exception {
HepProgram program = new HepProgramBuilder().addRuleInstance(
- PushFilterPastProjectRule.INSTANCE).build();
+ FilterProjectTransposeRule.INSTANCE).build();
checkPlanning(program, "select e1.ename, r\n"
+ "from (\n"
+ " select ename,\n"
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java b/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java
index faebe47..790aa25 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java
@@ -14,18 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.util.List;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.metadata.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.relopt.hep.*;
+package org.apache.calcite.test;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.plan.hep.HepProgramBuilder;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.metadata.ChainedRelMetadataProvider;
+import org.apache.calcite.rel.metadata.DefaultRelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelMetadataProvider;
import com.google.common.collect.Lists;
-import static org.junit.Assert.*;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
/**
* RelOptTestBase is an abstract base for tests which exercise a planner and/or
@@ -62,12 +68,8 @@ abstract class RelOptTestBase extends SqlToRelTestBase {
* @param program Planner program
* @param sql SQL query
*/
- protected void checkPlanning(
- HepProgram program,
- String sql) {
- checkPlanning(
- new HepPlanner(program),
- sql);
+ protected void checkPlanning(HepProgram program, String sql) {
+ checkPlanning(new HepPlanner(program), sql);
}
/**
@@ -77,9 +79,7 @@ abstract class RelOptTestBase extends SqlToRelTestBase {
* @param planner Planner
* @param sql SQL query
*/
- protected void checkPlanning(
- RelOptPlanner planner,
- String sql) {
+ protected void checkPlanning(RelOptPlanner planner, String sql) {
checkPlanning(tester, null, planner, sql);
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
index b3d8ebb..d1d0bae 100644
--- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
@@ -14,22 +14,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.math.BigDecimal;
-import java.util.*;
-
-import org.eigenbase.relopt.Strong;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-import org.eigenbase.sql.type.SqlTypeName;
-import org.eigenbase.util.*;
-
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-import net.hydromatic.optiq.jdbc.JavaTypeFactoryImpl;
-import net.hydromatic.optiq.test.OptiqAssert;
-import net.hydromatic.optiq.util.BitSets;
+package org.apache.calcite.test;
+
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.plan.Strong;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexDynamicParam;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexLocalRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.util.BitSets;
+import org.apache.calcite.util.TestUtil;
+import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -37,13 +44,18 @@ import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.List;
+
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* Unit tests for {@link RexProgram} and
- * {@link org.eigenbase.rex.RexProgramBuilder}.
+ * {@link org.apache.calcite.rex.RexProgramBuilder}.
*/
public class RexProgramTest {
//~ Instance fields --------------------------------------------------------
@@ -126,8 +138,8 @@ public class RexProgramTest {
final String programString = program.toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], "
- + "expr#4=[+($0, $1)], expr#5=[+($0, $0)], expr#6=[+($t4, $t2)], "
- + "a=[$t6], b=[$t5])",
+ + "expr#4=[+($0, $1)], expr#5=[+($0, $0)], expr#6=[+($t4, $t2)], "
+ + "a=[$t6], b=[$t5])",
programString);
// Normalize the program using the RexProgramBuilder.normalize API.
@@ -140,8 +152,8 @@ public class RexProgramTest {
final String normalizedProgramString = normalizedProgram.toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
- + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
- + "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])",
+ + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ + "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])",
normalizedProgramString);
}
@@ -166,8 +178,8 @@ public class RexProgramTest {
final String unnormalizedProgram = builder.getProgram(false).toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], "
- + "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], "
- + "expr#7=[+($t4, $t2)], a=[$t7], b=[$t6])",
+ + "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], "
+ + "expr#7=[+($t4, $t2)], a=[$t7], b=[$t6])",
unnormalizedProgram);
// normalize eliminates duplicates (specifically "+($0, $1)")
@@ -175,8 +187,8 @@ public class RexProgramTest {
final String program2 = builder2.getProgram(true).toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
- + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
- + "expr#6=[+($t0, $t4)], a=[$t5], b=[$t6])",
+ + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ + "expr#6=[+($t0, $t4)], a=[$t5], b=[$t6])",
program2);
}
@@ -191,10 +203,10 @@ public class RexProgramTest {
final String program = builder.getProgram(true).toString();
TestUtil.assertEqualsVerbose(
"(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
- + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
- + "expr#6=[+($t0, $t0)], expr#7=[>($t2, $t0)], "
- + "expr#8=[AND($t7, $t7)], expr#9=[AND($t8, $t7)], "
- + "a=[$t5], b=[$t6], $condition=[$t9])",
+ + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
+ + "expr#6=[+($t0, $t0)], expr#7=[>($t2, $t0)], "
+ + "expr#8=[AND($t7, $t7)], expr#9=[AND($t8, $t7)], "
+ + "a=[$t5], b=[$t6], $condition=[$t9])",
program);
}
@@ -314,7 +326,7 @@ public class RexProgramTest {
return Strong.is(e, b);
}
- /** Unit test for {@link org.eigenbase.relopt.Strong}. */
+ /** Unit test for {@link org.apache.calcite.plan.Strong}. */
@Test public void testStrong() {
final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
@@ -362,7 +374,7 @@ public class RexProgramTest {
assertThat(strongIf(andFalseTrue, c), is(false));
}
- /** Unit test for {@link org.eigenbase.rex.RexUtil#toCnf}. */
+ /** Unit test for {@link org.apache.calcite.rex.RexUtil#toCnf}. */
@Test public void testCnf() {
final RelDataType booleanType =
typeFactory.createSqlType(SqlTypeName.BOOLEAN);
@@ -478,40 +490,40 @@ public class RexProgramTest {
eq(aRef, literal3),
eq(bRef, literal3))),
"AND("
- + "OR(=(?0.x, 1), =(?0.x, 2), =(?0.x, 3)), "
- + "OR(=(?0.x, 1), =(?0.x, 2), =(?0.a, 3)), "
- + "OR(=(?0.x, 1), =(?0.x, 2), =(?0.b, 3)), "
- + "OR(=(?0.x, 1), =(?0.y, 2), =(?0.x, 3)), "
- + "OR(=(?0.x, 1), =(?0.y, 2), =(?0.a, 3)), "
- + "OR(=(?0.x, 1), =(?0.y, 2), =(?0.b, 3)), "
- + "OR(=(?0.x, 1), =(?0.a, 2), =(?0.x, 3)), "
- + "OR(=(?0.x, 1), =(?0.a, 2), =(?0.a, 3)), "
- + "OR(=(?0.x, 1), =(?0.a, 2), =(?0.b, 3)), "
- + "OR(=(?0.y, 1), =(?0.x, 2), =(?0.x, 3)), "
- + "OR(=(?0.y, 1), =(?0.x, 2), =(?0.a, 3)), "
- + "OR(=(?0.y, 1), =(?0.x, 2), =(?0.b, 3)), "
- + "OR(=(?0.y, 1), =(?0.y, 2), =(?0.x, 3)), "
- + "OR(=(?0.y, 1), =(?0.y, 2), =(?0.a, 3)), "
- + "OR(=(?0.y, 1), =(?0.y, 2), =(?0.b, 3)), "
- + "OR(=(?0.y, 1), =(?0.a, 2), =(?0.x, 3)), "
- + "OR(=(?0.y, 1), =(?0.a, 2), =(?0.a, 3)), "
- + "OR(=(?0.y, 1), =(?0.a, 2), =(?0.b, 3)), "
- + "OR(=(?0.z, 1), =(?0.x, 2), =(?0.x, 3)), "
- + "OR(=(?0.z, 1), =(?0.x, 2), =(?0.a, 3)), "
- + "OR(=(?0.z, 1), =(?0.x, 2), =(?0.b, 3)), "
- + "OR(=(?0.z, 1), =(?0.y, 2), =(?0.x, 3)), "
- + "OR(=(?0.z, 1), =(?0.y, 2), =(?0.a, 3)), "
- + "OR(=(?0.z, 1), =(?0.y, 2), =(?0.b, 3)), "
- + "OR(=(?0.z, 1), =(?0.a, 2), =(?0.x, 3)), "
- + "OR(=(?0.z, 1), =(?0.a, 2), =(?0.a, 3)), "
- + "OR(=(?0.z, 1), =(?0.a, 2), =(?0.b, 3)))");
+ + "OR(=(?0.x, 1), =(?0.x, 2), =(?0.x, 3)), "
+ + "OR(=(?0.x, 1), =(?0.x, 2), =(?0.a, 3)), "
+ + "OR(=(?0.x, 1), =(?0.x, 2), =(?0.b, 3)), "
+ + "OR(=(?0.x, 1), =(?0.y, 2), =(?0.x, 3)), "
+ + "OR(=(?0.x, 1), =(?0.y, 2), =(?0.a, 3)), "
+ + "OR(=(?0.x, 1), =(?0.y, 2), =(?0.b, 3)), "
+ + "OR(=(?0.x, 1), =(?0.a, 2), =(?0.x, 3)), "
+ + "OR(=(?0.x, 1), =(?0.a, 2), =(?0.a, 3)), "
+ + "OR(=(?0.x, 1), =(?0.a, 2), =(?0.b, 3)), "
+ + "OR(=(?0.y, 1), =(?0.x, 2), =(?0.x, 3)), "
+ + "OR(=(?0.y, 1), =(?0.x, 2), =(?0.a, 3)), "
+ + "OR(=(?0.y, 1), =(?0.x, 2), =(?0.b, 3)), "
+ + "OR(=(?0.y, 1), =(?0.y, 2), =(?0.x, 3)), "
+ + "OR(=(?0.y, 1), =(?0.y, 2), =(?0.a, 3)), "
+ + "OR(=(?0.y, 1), =(?0.y, 2), =(?0.b, 3)), "
+ + "OR(=(?0.y, 1), =(?0.a, 2), =(?0.x, 3)), "
+ + "OR(=(?0.y, 1), =(?0.a, 2), =(?0.a, 3)), "
+ + "OR(=(?0.y, 1), =(?0.a, 2), =(?0.b, 3)), "
+ + "OR(=(?0.z, 1), =(?0.x, 2), =(?0.x, 3)), "
+ + "OR(=(?0.z, 1), =(?0.x, 2), =(?0.a, 3)), "
+ + "OR(=(?0.z, 1), =(?0.x, 2), =(?0.b, 3)), "
+ + "OR(=(?0.z, 1), =(?0.y, 2), =(?0.x, 3)), "
+ + "OR(=(?0.z, 1), =(?0.y, 2), =(?0.a, 3)), "
+ + "OR(=(?0.z, 1), =(?0.y, 2), =(?0.b, 3)), "
+ + "OR(=(?0.z, 1), =(?0.a, 2), =(?0.x, 3)), "
+ + "OR(=(?0.z, 1), =(?0.a, 2), =(?0.a, 3)), "
+ + "OR(=(?0.z, 1), =(?0.a, 2), =(?0.b, 3)))");
}
/** Tests formulas of various sizes whose size is exponential when converted
* to CNF. */
@Test public void testCnfExponential() {
// run out of memory if limit is higher than about 20
- final int limit = OptiqAssert.ENABLE_SLOW ? 16 : 6;
+ final int limit = CalciteAssert.ENABLE_SLOW ? 16 : 6;
for (int i = 2; i < limit; i++) {
checkExponentialCnf(i);
}
@@ -538,15 +550,14 @@ public class RexProgramTest {
assertThat((n + 1) * (int) Math.pow(2, n) + 1, equalTo(nodeCount));
if (n == 3) {
assertThat(cnf.toString(),
- equalTo(
- "AND(OR(?0.x0, ?0.x1, ?0.x2), OR(?0.x0, ?0.x1, ?0.y2),"
+ equalTo("AND(OR(?0.x0, ?0.x1, ?0.x2), OR(?0.x0, ?0.x1, ?0.y2),"
+ " OR(?0.x0, ?0.y1, ?0.x2), OR(?0.x0, ?0.y1, ?0.y2),"
+ " OR(?0.y0, ?0.x1, ?0.x2), OR(?0.y0, ?0.x1, ?0.y2),"
+ " OR(?0.y0, ?0.y1, ?0.x2), OR(?0.y0, ?0.y1, ?0.y2))"));
}
}
- /** Unit test for {@link org.eigenbase.rex.RexUtil#pullFactors}. */
+ /** Unit test for {@link org.apache.calcite.rex.RexUtil#pullFactors}. */
@Test public void testPullFactors() {
final RelDataType booleanType =
typeFactory.createSqlType(SqlTypeName.BOOLEAN);
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java b/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
index 95f0a58..8f8f799 100644
--- a/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
@@ -14,19 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
+package org.apache.calcite.test;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.fun.*;
-import org.eigenbase.sql.type.*;
-
-import net.hydromatic.optiq.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexTransformer;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeName;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Tests transformations on rex nodes.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java b/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java
index ed989ab..78bdab7 100644
--- a/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java
+++ b/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java
@@ -14,33 +14,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
-
-import net.hydromatic.linq4j.AbstractEnumerable;
-import net.hydromatic.linq4j.Enumerable;
-import net.hydromatic.linq4j.Enumerator;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.impl.AbstractSchema;
-import net.hydromatic.optiq.impl.AbstractTable;
-import net.hydromatic.optiq.impl.java.ReflectiveSchema;
-import net.hydromatic.optiq.jdbc.OptiqConnection;
-
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeFactory;
-import org.eigenbase.rex.RexCall;
-import org.eigenbase.rex.RexInputRef;
-import org.eigenbase.rex.RexLiteral;
-import org.eigenbase.rex.RexNode;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-import org.eigenbase.sql.type.SqlTypeName;
-import org.eigenbase.util.Bug;
+package org.apache.calcite.test;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.ReflectiveSchema;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.linq4j.AbstractEnumerable;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.schema.FilterableTable;
+import org.apache.calcite.schema.ProjectableFilterableTable;
+import org.apache.calcite.schema.ScannableTable;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Statistic;
+import org.apache.calcite.schema.Statistics;
+import org.apache.calcite.schema.impl.AbstractSchema;
+import org.apache.calcite.schema.impl.AbstractTable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.util.Bug;
import org.junit.Assert;
import org.junit.Test;
import java.math.BigDecimal;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -51,7 +60,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
- * Unit test for {@link net.hydromatic.optiq.ScannableTable}.
+ * Unit test for {@link org.apache.calcite.schema.ScannableTable}.
*/
public class ScannableTableTest {
@Test public void testTens() throws SQLException {
@@ -72,15 +81,15 @@ public class ScannableTableTest {
@Test public void testSimple() throws Exception {
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
schema.add("simple", new SimpleTable());
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
ResultSet resultSet = connection.createStatement().executeQuery(
"select * from \"s\".\"simple\"");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo("i=0\ni=10\ni=20\ni=30\n"));
}
@@ -88,15 +97,15 @@ public class ScannableTableTest {
@Test public void testSimple2() throws Exception {
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
schema.add("beatles", new BeatlesTable());
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
ResultSet resultSet = connection.createStatement().executeQuery(
"select * from \"s\".\"beatles\"");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo("i=4; j=John\ni=4; j=Paul\ni=6; j=George\ni=5; j=Ringo\n"));
}
@@ -104,16 +113,16 @@ public class ScannableTableTest {
@Test public void testSimpleFilter2() throws Exception {
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
final StringBuilder buf = new StringBuilder();
schema.add("beatles", new BeatlesFilterableTable(buf, true));
final Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(
"select * from \"s\".\"beatles\" where \"i\" = 4");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo("i=4; j=John; k=1940\ni=4; j=Paul; k=1942\n"));
resultSet.close();
// Only 2 rows came out of the table. If the value is 4, it means that the
@@ -126,28 +135,28 @@ public class ScannableTableTest {
schema.add("beatles2", new BeatlesFilterableTable(buf, false));
resultSet = statement.executeQuery(
"select * from \"s\".\"beatles2\" where \"i\" = 4");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo("i=4; j=John; k=1940\ni=4; j=Paul; k=1942\n"));
resultSet.close();
assertThat(buf.toString(), equalTo("returnCount=4"));
buf.setLength(0);
}
- /** A filter on a {@link net.hydromatic.optiq.ProjectableFilterableTable} with
- * two columns. */
+ /** A filter on a {@link org.apache.calcite.schema.ProjectableFilterableTable}
+ * with two columns. */
@Test public void testProjectableFilterable2() throws Exception {
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
final StringBuilder buf = new StringBuilder();
schema.add("beatles", new BeatlesProjectableFilterableTable(buf, true));
final Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(
"select * from \"s\".\"beatles\" where \"i\" = 4");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo("i=4; j=John; k=1940\ni=4; j=Paul; k=1942\n"));
resultSet.close();
// Only 2 rows came out of the table. If the value is 4, it means that the
@@ -160,21 +169,21 @@ public class ScannableTableTest {
schema.add("beatles2", new BeatlesProjectableFilterableTable(buf, false));
resultSet = statement.executeQuery(
"select * from \"s\".\"beatles2\" where \"i\" = 4");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo("i=4; j=John; k=1940\ni=4; j=Paul; k=1942\n"));
resultSet.close();
assertThat(buf.toString(), equalTo("returnCount=4"));
buf.setLength(0);
}
- /** A filter on a {@link net.hydromatic.optiq.ProjectableFilterableTable} with
- * two columns, and a project in the query. */
+ /** A filter on a {@link org.apache.calcite.schema.ProjectableFilterableTable}
+ * with two columns, and a project in the query. */
@Test public void testProjectableFilterable2WithProject() throws Exception {
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
final StringBuilder buf = new StringBuilder();
schema.add("beatles", new BeatlesProjectableFilterableTable(buf, true));
@@ -183,7 +192,7 @@ public class ScannableTableTest {
final Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(
"select \"k\",\"j\" from \"s\".\"beatles\" where \"i\" = 4");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo("k=1940; j=John\nk=1942; j=Paul\n"));
resultSet.close();
assertThat(buf.toString(), equalTo("returnCount=2, projects=[2, 1]"));
@@ -191,15 +200,15 @@ public class ScannableTableTest {
}
/** A filter and project on a
- * {@link net.hydromatic.optiq.ProjectableFilterableTable}. The table
+ * {@link org.apache.calcite.schema.ProjectableFilterableTable}. The table
* refuses to execute the filter, so Calcite should add a pull up and
* transform the filter (projecting the column needed by the filter). */
@Test public void testPFTableRefusesFilter() throws Exception {
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
final StringBuilder buf = new StringBuilder();
schema.add("beatles2", new BeatlesProjectableFilterableTable(buf, false));
@@ -209,7 +218,7 @@ public class ScannableTableTest {
final Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(
"select \"k\" from \"s\".\"beatles2\" where \"i\" = 4");
- assertThat(OptiqAssert.toString(resultSet),
+ assertThat(CalciteAssert.toString(resultSet),
equalTo(Bug.CALCITE_445_FIXED ? "k=1940\nk=1942\n" : ""));
resultSet.close();
assertThat(buf.toString(),
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java b/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java
index 9473cc0..293e886 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java
@@ -14,20 +14,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.avatica.ByteString;
-
-import net.hydromatic.optiq.runtime.*;
+import org.apache.calcite.avatica.ByteString;
+import org.apache.calcite.runtime.SqlFunctions;
+import org.apache.calcite.runtime.Utilities;
import org.junit.Test;
-import java.util.*;
-
-import static net.hydromatic.optiq.runtime.SqlFunctions.*;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.calcite.runtime.SqlFunctions.EPOCH_JULIAN;
+import static org.apache.calcite.runtime.SqlFunctions.TimeUnitRange;
+import static org.apache.calcite.runtime.SqlFunctions.charLength;
+import static org.apache.calcite.runtime.SqlFunctions.concat;
+import static org.apache.calcite.runtime.SqlFunctions.dateStringToUnixDate;
+import static org.apache.calcite.runtime.SqlFunctions.greater;
+import static org.apache.calcite.runtime.SqlFunctions.initcap;
+import static org.apache.calcite.runtime.SqlFunctions.intervalDayTimeToString;
+import static org.apache.calcite.runtime.SqlFunctions.intervalYearMonthToString;
+import static org.apache.calcite.runtime.SqlFunctions.lesser;
+import static org.apache.calcite.runtime.SqlFunctions.lower;
+import static org.apache.calcite.runtime.SqlFunctions.ltrim;
+import static org.apache.calcite.runtime.SqlFunctions.rtrim;
+import static org.apache.calcite.runtime.SqlFunctions.timeStringToUnixDate;
+import static org.apache.calcite.runtime.SqlFunctions.timestampStringToUnixDate;
+import static org.apache.calcite.runtime.SqlFunctions.trim;
+import static org.apache.calcite.runtime.SqlFunctions.unixDateExtract;
+import static org.apache.calcite.runtime.SqlFunctions.unixDateToString;
+import static org.apache.calcite.runtime.SqlFunctions.unixTimeToString;
+import static org.apache.calcite.runtime.SqlFunctions.unixTimestampToString;
+import static org.apache.calcite.runtime.SqlFunctions.upper;
+import static org.apache.calcite.runtime.SqlFunctions.ymdToJulian;
+import static org.apache.calcite.runtime.SqlFunctions.ymdToUnixDate;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
/**
* Unit test for the methods in {@link SqlFunctions} that implement SQL
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/SqlLimitsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlLimitsTest.java b/core/src/test/java/org/apache/calcite/test/SqlLimitsTest.java
index cbc2ce2..8c58676 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlLimitsTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlLimitsTest.java
@@ -14,26 +14,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.io.*;
-import java.text.*;
-import java.util.*;
-
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeFactory;
-import org.eigenbase.reltype.RelDataTypeSystem;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.parser.*;
-import org.eigenbase.sql.type.*;
-
-import net.hydromatic.optiq.jdbc.JavaTypeFactoryImpl;
+package org.apache.calcite.test;
+
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.BasicSqlType;
+import org.apache.calcite.sql.type.SqlTypeName;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
/**
* Unit test for SQL limits.
*/
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
index 64e3dc7..c5ed8c0 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
@@ -14,17 +14,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.io.*;
-import java.lang.reflect.*;
-import java.nio.charset.*;
-import java.util.*;
-
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.test.*;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.util.*;
+package org.apache.calcite.test;
+
+import org.apache.calcite.sql.SqlCollation;
+import org.apache.calcite.sql.test.DefaultSqlTestFactory;
+import org.apache.calcite.sql.test.DelegatingSqlTestFactory;
+import org.apache.calcite.sql.test.SqlTestFactory;
+import org.apache.calcite.sql.test.SqlTester;
+import org.apache.calcite.sql.test.SqlTesterImpl;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.util.BarfingInvocationHandler;
+import org.apache.calcite.util.Util;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
/**
* Utility to generate a SQL script from validator test.
@@ -107,8 +119,7 @@ public class SqlTestGen {
public SqlTester getTester() {
final SqlTestFactory factory =
new DelegatingSqlTestFactory(DefaultSqlTestFactory.INSTANCE) {
- @Override
- public SqlValidator getValidator(SqlTestFactory factory) {
+ @Override public SqlValidator getValidator(SqlTestFactory factory) {
return (SqlValidator) Proxy.newProxyInstance(
SqlValidatorSpooler.class.getClassLoader(),
new Class[]{SqlValidator.class},
@@ -133,12 +144,10 @@ public class SqlTestGen {
}
}
- @Override
- public void checkColumnType(String sql, String expected) {
+ @Override public void checkColumnType(String sql, String expected) {
}
- @Override
- public void checkResultType(String sql, String expected) {
+ @Override public void checkResultType(String sql, String expected) {
}
public void checkType(
@@ -163,19 +172,16 @@ public class SqlTestGen {
// ignore it for now.
}
- @Override
- public void checkIntervalConv(String sql, String expected) {
+ @Override public void checkIntervalConv(String sql, String expected) {
}
- @Override
- public void checkRewrite(
+ @Override public void checkRewrite(
SqlValidator validator,
String query,
String expectedRewrite) {
}
- @Override
- public void checkFieldOrigin(
+ @Override public void checkFieldOrigin(
String sql,
String fieldOriginList) {
}
@@ -184,7 +190,7 @@ public class SqlTestGen {
/**
* Handles the methods in
- * {@link org.eigenbase.sql.validate.SqlValidator} that are called
+ * {@link org.apache.calcite.sql.validate.SqlValidator} that are called
* from validator tests.
*/
public static class MyInvocationHandler extends BarfingInvocationHandler {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java
index e44277b..2deab9d 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterExtendedTest.java
@@ -14,16 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.optiq.SchemaPlus;
-import net.hydromatic.optiq.runtime.Hook;
-import net.hydromatic.optiq.tools.Frameworks;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelOptSchema;
-import org.eigenbase.test.SqlToRelConverterTest;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptSchema;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelShuttleImpl;
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rel.externalize.RelJsonReader;
+import org.apache.calcite.rel.externalize.RelJsonWriter;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.tools.Frameworks;
import com.google.common.base.Function;
@@ -33,7 +35,7 @@ import org.junit.Before;
import java.io.IOException;
/**
- * Runs {@link org.eigenbase.test.SqlToRelConverterTest} with extensions.
+ * Runs {@link org.apache.calcite.test.SqlToRelConverterTest} with extensions.
*/
public class SqlToRelConverterExtendedTest extends SqlToRelConverterTest {
Hook.Closeable closeable;
@@ -64,8 +66,7 @@ public class SqlToRelConverterExtendedTest extends SqlToRelConverterTest {
// Find the schema. If there are no tables in the plan, we won't need one.
final RelOptSchema[] schemas = {null};
rel.accept(new RelShuttleImpl() {
- @Override
- public RelNode visit(TableAccessRelBase scan) {
+ @Override public RelNode visit(TableScan scan) {
schemas[0] = scan.getTable().getRelOptSchema();
return super.visit(scan);
}