calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [12/18] incubator-calcite git commit: [CALCITE-819] Add RelRoot, a contract for the result of a relational expression
Date Wed, 02 Sep 2015 00:09:48 GMT
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/main/java/org/apache/calcite/tools/Programs.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/Programs.java b/core/src/main/java/org/apache/calcite/tools/Programs.java
index 3f6c05f..fd249a4 100644
--- a/core/src/main/java/org/apache/calcite/tools/Programs.java
+++ b/core/src/main/java/org/apache/calcite/tools/Programs.java
@@ -29,6 +29,7 @@ import org.apache.calcite.plan.hep.HepProgram;
 import org.apache.calcite.plan.hep.HepProgramBuilder;
 import org.apache.calcite.prepare.CalcitePrepareImpl;
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Calc;
 import org.apache.calcite.rel.metadata.ChainedRelMetadataProvider;
 import org.apache.calcite.rel.metadata.DefaultRelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelMetadataProvider;
@@ -61,7 +62,6 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.List;
 
 /**
@@ -94,7 +94,7 @@ public class Programs {
           FilterCalcMergeRule.INSTANCE,
           ProjectCalcMergeRule.INSTANCE);
 
-  /** Program that converts filters and projects to calcs. */
+  /** Program that converts filters and projects to {@link Calc}s. */
   public static final Program CALC_PROGRAM =
       hep(CALC_RULES, true, new DefaultRelMetadataProvider());
 
@@ -157,7 +157,7 @@ public class Programs {
   }
 
   /** Creates a program from a list of rules. */
-  public static Program ofRules(Collection<RelOptRule> rules) {
+  public static Program ofRules(Iterable<? extends RelOptRule> rules) {
     return of(RuleSets.ofList(rules));
   }
 
@@ -167,8 +167,8 @@ public class Programs {
   }
 
   /** Creates a program that executes a list of rules in a HEP planner. */
-  public static Program hep(ImmutableList<RelOptRule> rules, boolean noDag,
-      RelMetadataProvider metadataProvider) {
+  public static Program hep(Iterable<? extends RelOptRule> rules,
+      boolean noDag, RelMetadataProvider metadataProvider) {
     final HepProgramBuilder builder = HepProgram.builder();
     for (RelOptRule rule : rules) {
       builder.addRuleInstance(rule);
@@ -205,7 +205,8 @@ public class Programs {
    * {@link org.apache.calcite.rel.rules.MultiJoin} and
    * {@link org.apache.calcite.rel.rules.LoptOptimizeJoinRule})
    * if there are 6 or more joins (7 or more relations). */
-  public static Program heuristicJoinOrder(final Collection<RelOptRule> rules,
+  public static Program heuristicJoinOrder(
+      final Iterable<? extends RelOptRule> rules,
       final boolean bushy, final int minJoinCount) {
     return new Program() {
       public RelNode run(RelOptPlanner planner, RelNode rel,

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/main/java/org/apache/calcite/tools/RuleSets.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/RuleSets.java b/core/src/main/java/org/apache/calcite/tools/RuleSets.java
index 8a1cdc0..62bb5a1 100644
--- a/core/src/main/java/org/apache/calcite/tools/RuleSets.java
+++ b/core/src/main/java/org/apache/calcite/tools/RuleSets.java
@@ -20,7 +20,6 @@ import org.apache.calcite.plan.RelOptRule;
 
 import com.google.common.collect.ImmutableList;
 
-import java.util.Collection;
 import java.util.Iterator;
 
 /**
@@ -38,7 +37,7 @@ public class RuleSets {
   }
 
   /** Creates a rule set with a given collection of rules. */
-  public static RuleSet ofList(Collection<RelOptRule> rules) {
+  public static RuleSet ofList(Iterable<? extends RelOptRule> rules) {
     return new ListRuleSet(ImmutableList.copyOf(rules));
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java b/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java
index 3dcfae6..8610dea 100644
--- a/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java
+++ b/core/src/main/java/org/apache/calcite/util/ImmutableIntList.java
@@ -17,6 +17,7 @@
 package org.apache.calcite.util;
 
 import org.apache.calcite.runtime.FlatLists;
+import org.apache.calcite.util.mapping.Mappings;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
@@ -246,7 +247,10 @@ public class ImmutableIntList extends FlatLists.AbstractFlatList<Integer>
{
     };
   }
 
-  /** Returns the identity list [0, ..., count - 1]. */
+  /** Returns the identity list [0, ..., count - 1].
+   *
+   * @see Mappings#isIdentity(List, int)
+   */
   public static ImmutableIntList identity(int count) {
     final int[] integers = new int[count];
     for (int i = 0; i < integers.length; i++) {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/InterpreterTest.java b/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
index 9f5200c..eea164b 100644
--- a/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/InterpreterTest.java
@@ -106,6 +106,19 @@ public class InterpreterTest {
     assertRows(interpreter, "[b, 2]", "[c, 3]");
   }
 
+  /** Tests a plan where the sort field is projected away. */
+  @Test public void testInterpretOrder() throws Exception {
+    final String sql = "select y\n"
+        + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
+        + "order by -x";
+    SqlNode parse = planner.parse(sql);
+    SqlNode validate = planner.validate(parse);
+    RelNode convert = planner.rel(validate).project();
+
+    final Interpreter interpreter = new Interpreter(dataContext, convert);
+    assertRows(interpreter, "[c]", "[b]", "[a]");
+  }
+
   private static void assertRows(Interpreter interpreter, String... rows) {
     assertRows(interpreter, false, rows);
   }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java b/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
index e4131c3..5f41784 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcFrontLinqBackTest.java
@@ -93,8 +93,8 @@ public class JdbcFrontLinqBackTest {
         .query("select upper(\"name\") as un, \"deptno\"\n"
             + "from \"hr\".\"emps\" as e\n"
             + "order by \"deptno\", \"name\" desc")
-        .explainContains(
-            "EnumerableCalc(expr#0..1=[{inputs}], expr#2=[UPPER($t1)], UN=[$t2], deptno=[$t0])\n"
+        .explainContains(""
+            + "EnumerableCalc(expr#0..1=[{inputs}], expr#2=[UPPER($t1)], UN=[$t2], deptno=[$t0],
name=[$t1])\n"
             + "  EnumerableSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[DESC])\n"
             + "    EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1], name=[$t2])\n"
             + "      EnumerableTableScan(table=[[hr, emps]])")
@@ -209,8 +209,7 @@ public class JdbcFrontLinqBackTest {
   }
 
   @Test public void testInsert() {
-    final List<JdbcTest.Employee> employees =
-        new ArrayList<JdbcTest.Employee>();
+    final List<JdbcTest.Employee> employees = new ArrayList<>();
     CalciteAssert.AssertThat with = mutable(employees);
     with.query("select * from \"foo\".\"bar\"")
         .returns(
@@ -293,8 +292,7 @@ public class JdbcFrontLinqBackTest {
   }
 
   @Test public void testInsert2() {
-    final List<JdbcTest.Employee> employees =
-        new ArrayList<JdbcTest.Employee>();
+    final List<JdbcTest.Employee> employees = new ArrayList<>();
     CalciteAssert.AssertThat with = mutable(employees);
     with.query("insert into \"foo\".\"bar\" values (1, 1, 'second', 2, 2)")
         .returns("ROWCOUNT=1\n");
@@ -311,8 +309,7 @@ public class JdbcFrontLinqBackTest {
 
   /** Some of the rows have the wrong number of columns. */
   @Test public void testInsertMultipleRowMismatch() {
-    final List<JdbcTest.Employee> employees =
-        new ArrayList<JdbcTest.Employee>();
+    final List<JdbcTest.Employee> employees = new ArrayList<>();
     CalciteAssert.AssertThat with = mutable(employees);
     with.query("insert into \"foo\".\"bar\" values\n"
         + " (1, 3, 'third'),\n"

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/java/org/apache/calcite/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
index 2ff7e99..e1ee242 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -2940,11 +2940,9 @@ public class JdbcTest {
     CalciteAssert.hr()
         .query("select * from \"hr\".\"emps\"\n"
             + "order by - \"empid\"")
-        .explainContains(""
-            + "EnumerableCalc(expr#0..5=[{inputs}], proj#0..4=[{exprs}])\n"
-            + "  EnumerableSort(sort0=[$5], dir0=[ASC])\n"
-            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[-($t0)], proj#0..5=[{exprs}])\n"
-            + "      EnumerableTableScan(table=[[hr, emps]])")
+        .explainContains("EnumerableSort(sort0=[$5], dir0=[ASC])\n"
+            + "  EnumerableCalc(expr#0..4=[{inputs}], expr#5=[-($t0)], proj#0..5=[{exprs}])\n"
+            + "    EnumerableTableScan(table=[[hr, emps]])")
         .returns(""
             + "empid=200; deptno=20; name=Eric; salary=8000.0; commission=500\n"
             + "empid=150; deptno=10; name=Sebastian; salary=7000.0; commission=null\n"

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index 5ade0c8..c53cc7a 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -28,6 +28,7 @@ import org.apache.calcite.rel.RelCollationTraitDef;
 import org.apache.calcite.rel.RelCollations;
 import org.apache.calcite.rel.RelFieldCollation;
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelRoot;
 import org.apache.calcite.rel.core.Aggregate;
 import org.apache.calcite.rel.core.AggregateCall;
 import org.apache.calcite.rel.core.Join;
@@ -127,10 +128,10 @@ public class RelMetadataTest extends SqlToRelTestBase {
   // ----------------------------------------------------------------------
 
   private RelNode convertSql(String sql) {
-    RelNode rel = tester.convertSqlToRel(sql);
+    final RelRoot root = tester.convertSqlToRel(sql);
     DefaultRelMetadataProvider provider = new DefaultRelMetadataProvider();
-    rel.getCluster().setMetadataProvider(provider);
-    return rel;
+    root.rel.getCluster().setMetadataProvider(provider);
+    return root.rel;
   }
 
   private void checkPercentageOriginalRows(String sql, double expected) {
@@ -996,7 +997,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
             ImmutableList.<ImmutableBitSet>of(),
             ImmutableList.of(
                 AggregateCall.create(
-                    SqlStdOperatorTable.COUNT, false, ImmutableIntList.of(),
+                    SqlStdOperatorTable.COUNT, false, ImmutableIntList.of(), -1,
                     2, join, null, null)));
     rowSize = RelMetadataQuery.getAverageRowSize(aggregate);
     columnSizes = RelMetadataQuery.getAverageColumnSizes(aggregate);

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/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 b98bf73..fc6d5bb 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -24,6 +24,7 @@ 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.RelRoot;
 import org.apache.calcite.rel.core.Join;
 import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.core.RelFactories;
@@ -424,9 +425,9 @@ public class RelOptRulesTest extends RelOptTestBase {
     }
 
     final SqlNode validatedQuery = validator.validate(sqlQuery);
-    RelNode rel =
+    RelRoot root =
         converter.convertQuery(validatedQuery, false, true);
-    rel = converter.decorrelate(sqlQuery, rel);
+    root = root.withRel(converter.decorrelate(sqlQuery, root.rel));
 
     final HepProgram program =
         HepProgram.builder()
@@ -437,14 +438,14 @@ public class RelOptRulesTest extends RelOptTestBase {
             .build();
 
     HepPlanner planner = new HepPlanner(program);
-    planner.setRoot(rel);
-    rel = planner.findBestExp();
+    planner.setRoot(root.rel);
+    root = root.withRel(planner.findBestExp());
 
-    String planBefore = NL + RelOptUtil.toString(rel);
+    String planBefore = NL + RelOptUtil.toString(root.rel);
     diffRepos.assertEquals("planBefore", "${planBefore}", planBefore);
     converter.setTrimUnusedFields(true);
-    rel = converter.trimUnusedFields(false, rel);
-    String planAfter = NL + RelOptUtil.toString(rel);
+    root = root.withRel(converter.trimUnusedFields(false, root.rel));
+    String planAfter = NL + RelOptUtil.toString(root.rel);
     diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
   }
 
@@ -858,7 +859,7 @@ public class RelOptRulesTest extends RelOptTestBase {
         .build();
 
     // Remove the executor
-    tester.convertSqlToRel("values 1").getCluster().getPlanner()
+    tester.convertSqlToRel("values 1").rel.getCluster().getPlanner()
         .setExecutor(null);
 
     // Rule should not fire, but there should be no NPE
@@ -1474,7 +1475,8 @@ public class RelOptRulesTest extends RelOptTestBase {
         .build();
     HepPlanner planner = new HepPlanner(program);
 
-    RelNode relInitial = tester.convertSqlToRel(sql);
+    final RelRoot root = tester.convertSqlToRel(sql);
+    final RelNode relInitial = root.rel;
 
     assertTrue(relInitial != null);
 
@@ -1488,9 +1490,9 @@ public class RelOptRulesTest extends RelOptTestBase {
         new CachingRelMetadataProvider(plannerChain, planner));
 
     planner.setRoot(relInitial);
-    RelNode relAfter = planner.findBestExp();
+    RelNode relBefore = planner.findBestExp();
 
-    String planBefore = NL + RelOptUtil.toString(relAfter);
+    String planBefore = NL + RelOptUtil.toString(relBefore);
     diffRepos.assertEquals("planBefore", "${planBefore}", planBefore);
 
     HepProgram program2 = new HepProgramBuilder()
@@ -1504,8 +1506,8 @@ public class RelOptRulesTest extends RelOptTestBase {
         .build();
     HepPlanner planner2 = new HepPlanner(program2);
     planner.registerMetadataProviders(list);
-    planner2.setRoot(relAfter);
-    relAfter = planner2.findBestExp();
+    planner2.setRoot(relBefore);
+    RelNode relAfter = planner2.findBestExp();
 
     String planAfter = NL + RelOptUtil.toString(relAfter);
     diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/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 790aa25..777991a 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptTestBase.java
@@ -23,6 +23,7 @@ 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.RelRoot;
 import org.apache.calcite.rel.metadata.ChainedRelMetadataProvider;
 import org.apache.calcite.rel.metadata.DefaultRelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelMetadataProvider;
@@ -99,7 +100,8 @@ abstract class RelOptTestBase extends SqlToRelTestBase {
       String sql) {
     final DiffRepository diffRepos = getDiffRepos();
     String sql2 = diffRepos.expand("sql", sql);
-    RelNode relInitial = tester.convertSqlToRel(sql2);
+    final RelRoot root = tester.convertSqlToRel(sql2);
+    final RelNode relInitial = root.rel;
 
     assertTrue(relInitial != null);
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/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 b7ea814..22bb852 100644
--- a/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
@@ -20,6 +20,7 @@ import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
 import org.apache.calcite.plan.RelOptUtil;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.logical.LogicalProject;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.rel.type.RelDataTypeField;
@@ -67,7 +68,7 @@ public class RexTransformerTest {
   private static RelNode toRel(String sql) {
     final SqlToRelTestBase test = new SqlToRelTestBase() {
     };
-    return test.createTester().convertSqlToRel(sql);
+    return test.createTester().convertSqlToRel(sql).rel;
   }
 
   @Before public void setUp() {
@@ -377,7 +378,8 @@ public class RexTransformerTest {
         + "ON CAST(a.empno AS int) <> b.deptno";
 
     final RelNode relNode = toRel(sql);
-    final LogicalJoin join = (LogicalJoin) relNode.getInput(0);
+    final LogicalProject project = (LogicalProject) relNode;
+    final LogicalJoin join = (LogicalJoin) project.getInput(0);
     final List<RexNode> leftJoinKeys = new ArrayList<>();
     final List<RexNode> rightJoinKeys = new ArrayList<>();
     final ArrayList<RelDataTypeField> sysFieldList = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index cb0310c..28f31f5 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1076,7 +1076,7 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
 
   @Test public void testExplainAsXml() {
     String sql = "select 1 + 2, 3 from (values (true))";
-    final RelNode rel = tester.convertSqlToRel(sql);
+    final RelNode rel = tester.convertSqlToRel(sql).rel;
     StringWriter sw = new StringWriter();
     PrintWriter pw = new PrintWriter(sw);
     RelXmlWriter planWriter =

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
index f9752e5..9ec1eea 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
@@ -30,6 +30,7 @@ import org.apache.calcite.rel.RelDistribution;
 import org.apache.calcite.rel.RelDistributions;
 import org.apache.calcite.rel.RelFieldCollation;
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelRoot;
 import org.apache.calcite.rel.logical.LogicalTableScan;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
@@ -124,7 +125,7 @@ public abstract class SqlToRelTestBase {
      * @param sql SQL statement
      * @return Relational expression, never null
      */
-    RelNode convertSqlToRel(String sql);
+    RelRoot convertSqlToRel(String sql);
 
     SqlNode parseQuery(String sql) throws Exception;
 
@@ -463,7 +464,7 @@ public abstract class SqlToRelTestBase {
       this.catalogReaderFactory = catalogReaderFactory;
     }
 
-    public RelNode convertSqlToRel(String sql) {
+    public RelRoot convertSqlToRel(String sql) {
       Util.pre(sql != null, "sql != null");
       final SqlNode sqlQuery;
       try {
@@ -484,20 +485,20 @@ public abstract class SqlToRelTestBase {
               typeFactory);
       converter.setTrimUnusedFields(true);
       final SqlNode validatedQuery = validator.validate(sqlQuery);
-      RelNode rel =
+      RelRoot root =
           converter.convertQuery(validatedQuery, false, true);
-      assert rel != null;
+      assert root != null;
       if (enableDecorrelate || enableTrim) {
-        rel = converter.flattenTypes(rel, true);
+        root = root.withRel(converter.flattenTypes(root.rel, true));
       }
       if (enableDecorrelate) {
-        rel = converter.decorrelate(sqlQuery, rel);
+        root = root.withRel(converter.decorrelate(sqlQuery, root.rel));
       }
       if (enableTrim) {
         converter.setTrimUnusedFields(true);
-        rel = converter.trimUnusedFields(false, rel);
+        root = root.withRel(converter.trimUnusedFields(false, root.rel));
       }
-      return rel;
+      return root;
     }
 
     protected SqlToRelConverter createSqlToRelConverter(
@@ -591,7 +592,7 @@ public abstract class SqlToRelTestBase {
         String plan,
         boolean trim) {
       String sql2 = getDiffRepos().expand("sql", sql);
-      RelNode rel = convertSqlToRel(sql2);
+      RelNode rel = convertSqlToRel(sql2).project();
 
       assertTrue(rel != null);
       assertValid(rel);

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
index 551a612..b00b3ee 100644
--- a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
+++ b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
@@ -364,11 +364,10 @@ public class PlannerTest {
         + "from emps "
         + "order by emps.deptno) "
         + "order by deptno",
-        "EnumerableProject(empid=[$0])\n"
-        + "  EnumerableProject(empid=[$0], deptno=[$1])\n"
-        + "    EnumerableSort(sort0=[$1], dir0=[ASC])\n"
-        + "      EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
-        + "        EnumerableTableScan(table=[[hr, emps]])\n");
+        "EnumerableProject(empid=[$0], deptno=[$1])\n"
+        + "  EnumerableSort(sort0=[$1], dir0=[ASC])\n"
+        + "    EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
+        + "      EnumerableTableScan(table=[[hr, emps]])\n");
   }
 
   /** Unit test that parses, validates, converts and
@@ -380,11 +379,10 @@ public class PlannerTest {
         + "from emps "
         + "order by emps.deptno) "
         + "order by deptno",
-        "EnumerableProject(EXPR$0=[$0])\n"
-        + "  EnumerableProject(EXPR$0=[+($0, $1)], deptno=[$1])\n"
-        + "    EnumerableSort(sort0=[$1], dir0=[ASC])\n"
-        + "      EnumerableProject(empid=[$0], deptno=[$1])\n"
-        + "        EnumerableTableScan(table=[[hr, emps]])\n");
+        "EnumerableProject(EXPR$0=[+($0, $1)], deptno=[$1])\n"
+        + "  EnumerableSort(sort0=[$1], dir0=[ASC])\n"
+        + "    EnumerableProject(empid=[$0], deptno=[$1])\n"
+        + "      EnumerableTableScan(table=[[hr, emps]])\n");
   }
 
   /** Tests that outer order by is not removed since window function
@@ -459,12 +457,11 @@ public class PlannerTest {
         .replace(EnumerableConvention.INSTANCE);
     RelNode transform = planner.transform(0, traitSet, convert);
     assertThat(toString(transform),
-        equalTo("EnumerableProject(empid=[$0])\n"
-            + "  EnumerableSort(sort0=[$1], dir0=[ASC])\n"
-            + "    EnumerableProject(empid=[$0], deptno=[$1])\n"
-            + "      EnumerableSort(sort0=[$1], dir0=[ASC])\n"
-            + "        EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3],
commission=[$4])\n"
-            + "          EnumerableTableScan(table=[[hr, emps]])\n"));
+        equalTo("EnumerableSort(sort0=[$1], dir0=[ASC])\n"
+            + "  EnumerableProject(empid=[$0], deptno=[$1])\n"
+            + "    EnumerableSort(sort0=[$1], dir0=[ASC])\n"
+            + "      EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
+            + "        EnumerableTableScan(table=[[hr, emps]])\n"));
   }
 
   /** Unit test that parses, validates, converts and plans. Planner is

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index a9f7727..0ff7c29 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -2409,12 +2409,11 @@ LogicalAggregate(group=[{0}], EMPID=[MIN($1)])
 ]]>
         </Resource>
     </TestCase>
-
     <TestCase name="testCorrelationScalarAggAndFilter">
         <Resource name="sql">
             <![CDATA[SELECT e1.empno FROM emp e1, dept d1 where e1.deptno = d1.deptno
-     and e1.deptno < 10 and d1.deptno < 15
-     and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)]]>
+and e1.deptno < 10 and d1.deptno < 15
+and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)]]>
         </Resource>
         <Resource name="plan">
             <![CDATA[
@@ -2442,12 +2441,11 @@ LogicalProject(EMPNO=[$0])
 ]]>
         </Resource>
     </TestCase>
-
     <TestCase name="testCorrelationExistsAndFilter">
         <Resource name="sql">
             <![CDATA[SELECT e1.empno FROM emp e1, dept d1 where e1.deptno = d1.deptno
-     and e1.deptno < 10 and d1.deptno < 15
-     and exists (select * from emp e2 where e1.empno = e2.empno)]]>
+and e1.deptno < 10 and d1.deptno < 15
+and exists (select * from emp e2 where e1.empno = e2.empno)]]>
         </Resource>
         <Resource name="plan">
             <![CDATA[
@@ -2476,12 +2474,11 @@ LogicalProject(EMPNO=[$0])
 ]]>
         </Resource>
     </TestCase>
-
     <TestCase name="testCorrelationNotExistsAndFilter">
         <Resource name="sql">
             <![CDATA[SELECT e1.empno FROM emp e1, dept d1 where e1.deptno = d1.deptno
-     and e1.deptno < 10 and d1.deptno < 15
-     and not exists (select * from emp e2 where e1.empno = e2.empno)]]>
+and e1.deptno < 10 and d1.deptno < 15
+and not exists (select * from emp e2 where e1.empno = e2.empno)]]>
         </Resource>
         <Resource name="plan">
             <![CDATA[

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/5a397063/core/src/test/resources/sql/sort.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/sort.oq b/core/src/test/resources/sql/sort.oq
index 931d58f..5a25b6b 100644
--- a/core/src/test/resources/sql/sort.oq
+++ b/core/src/test/resources/sql/sort.oq
@@ -85,6 +85,19 @@ select * from e as e1, e as e2 order by e1.empid + e2.empid, e1.empid;
 
 !ok
 
+# WITH ... LIMIT
+with e as (select "empid" as empid from "hr"."emps" where "empid" < 200)
+select * from e where empid > 100 limit 5;
++-------+
+| EMPID |
++-------+
+|   150 |
+|   110 |
++-------+
+(2 rows)
+
+!ok
+
 # [CALCITE-634] Allow ORDER BY aggregate function in SELECT DISTINCT, provided
 # that it occurs in SELECT clause
 select distinct "deptno", count(*) as c


Mime
View raw message