calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [8/9] incubator-calcite git commit: [CALCITE-573] Use user-given names in RelOptUtil.createProject and createRename
Date Sun, 08 Feb 2015 17:25:07 GMT
[CALCITE-573] Use user-given names in RelOptUtil.createProject and createRename

Close apache/incubator-calcite#46


Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/8f1e3b28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/8f1e3b28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/8f1e3b28

Branch: refs/heads/master
Commit: 8f1e3b2803edda876c31a0a491e901b33c92da34
Parents: 2709896
Author: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Authored: Thu Jan 29 22:06:55 2015 +0300
Committer: Julian Hyde <jhyde@apache.org>
Committed: Sun Feb 8 01:17:58 2015 -0800

----------------------------------------------------------------------
 .../org/apache/calcite/plan/RelOptUtil.java     |  38 +++----
 .../rel/rules/AggregateStarTableRule.java       |   2 +-
 .../calcite/sql2rel/SqlToRelConverter.java      |   2 +-
 .../org/apache/calcite/test/CalciteAssert.java  |   9 ++
 .../org/apache/calcite/test/LatticeTest.java    |   6 +-
 .../enumerable/EnumerableCorrelateTest.java     |   4 +-
 .../org/apache/calcite/tools/PlannerTest.java   | 106 ++++++++++++++-----
 .../org/apache/calcite/test/RelOptRulesTest.xml |  20 ++--
 .../calcite/test/SqlToRelConverterTest.xml      |  42 ++++----
 core/src/test/resources/sql/misc.oq             |  22 ++--
 10 files changed, 157 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index bbcb75d..d09bf1f 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -2433,19 +2433,10 @@ public abstract class RelOptUtil {
    * Creates a {@link org.apache.calcite.rel.logical.LogicalProject} that
    * projects particular fields of its input, according to a mapping.
    */
-  public static LogicalProject project(
+  public static RelNode createProject(
       RelNode child,
       Mappings.TargetMapping mapping) {
-    List<RexNode> nodes = new ArrayList<RexNode>();
-    List<String> names = new ArrayList<String>();
-    final List<RelDataTypeField> fields = child.getRowType().getFieldList();
-    for (int i = 0; i < mapping.getTargetCount(); i++) {
-      int source = mapping.getSourceOpt(i);
-      RelDataTypeField field = fields.get(source);
-      nodes.add(new RexInputRef(source, field.getType()));
-      names.add(field.getName());
-    }
-    return LogicalProject.create(child, nodes, names);
+    return createProject(child, Mappings.asList(mapping.inverse()));
   }
 
   /** Returns whether relational expression {@code target} occurs within a
@@ -2657,17 +2648,17 @@ public abstract class RelOptUtil {
       List<String> fieldNames) {
     final List<RelDataTypeField> fields = rel.getRowType().getFieldList();
     assert fieldNames.size() == fields.size();
-    final List<Pair<RexNode, String>> refs =
-        new AbstractList<Pair<RexNode, String>>() {
+    final List<RexNode> refs =
+        new AbstractList<RexNode>() {
           public int size() {
             return fields.size();
           }
 
-          public Pair<RexNode, String> get(int index) {
-            return RexInputRef.of2(index, fields);
+          public RexNode get(int index) {
+            return RexInputRef.of(index, fields);
           }
         };
-    return createProject(rel, refs, true);
+    return createProject(rel, refs, fieldNames, true);
   }
 
   /**
@@ -2769,9 +2760,11 @@ public abstract class RelOptUtil {
    */
   public static RelNode createProject(final RelFactories.ProjectFactory factory,
       final RelNode child, final List<Integer> posList) {
-    if (Mappings.isIdentity(posList, child.getRowType().getFieldCount())) {
+    RelDataType rowType = child.getRowType();
+    if (Mappings.isIdentity(posList, rowType.getFieldCount())) {
       return child;
     }
+    final List<String> fieldNames = rowType.getFieldNames();
     final RexBuilder rexBuilder = child.getCluster().getRexBuilder();
     return factory.createProject(child,
         new AbstractList<RexNode>() {
@@ -2784,7 +2777,16 @@ public abstract class RelOptUtil {
             return rexBuilder.makeInputRef(child, pos);
           }
         },
-        null);
+        new AbstractList<String>() {
+          public int size() {
+            return posList.size();
+          }
+
+          public String get(int index) {
+            final int pos = posList.get(index);
+            return fieldNames.get(pos);
+          }
+        });
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java
index fd66ddf..10dfafc 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java
@@ -156,7 +156,7 @@ public class AggregateStarTableRule extends RelOptRule {
           + aggregateRelOptTable.getQualifiedName()
           + ", right granularity, but different measures "
           + aggregate.getAggCallList());
-      rel = RelOptUtil.project(rel,
+      rel = RelOptUtil.createProject(rel,
           new AbstractSourceMapping(
               tileKey.dimensions.cardinality() + tileKey.measures.size(),
               aggregate.getRowType().getFieldCount()) {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 0ace1e9..ad3f7c0 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -2212,7 +2212,7 @@ public class SqlToRelConverter {
                   + rightCount + extraRightExprs.size(),
               0, 0, leftCount,
               leftCount, leftCount + extraLeftExprs.size(), rightCount);
-      return RelOptUtil.project(join, mapping);
+      return RelOptUtil.createProject(join, mapping);
     }
     return join;
   }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
index 77faaf0..4ac014b 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
@@ -469,6 +469,15 @@ public class CalciteAssert {
       statement.close();
       connection.close();
     } catch (Throwable e) {
+      // We ignore extended message for non-runtime exception, however
+      // it does not matter much since it is better to have AssertionError
+      // at the very top level of the exception stack.
+      if (e instanceof RuntimeException) {
+        throw (RuntimeException) e;
+      }
+      if (e instanceof Error) {
+        throw (Error) e;
+      }
       throw new RuntimeException(message, e);
     } finally {
       for (Hook.Closeable closeable : closeableList) {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/test/java/org/apache/calcite/test/LatticeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/LatticeTest.java b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
index b51e51c..c68cf5f 100644
--- a/core/src/test/java/org/apache/calcite/test/LatticeTest.java
+++ b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
@@ -191,7 +191,7 @@ public class LatticeTest {
         .substitutionMatches(
             CalciteAssert.checkRel(
                 "LogicalProject(unit_sales=[$7], brand_name=[$10])\n"
-                    + "  LogicalProject($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], $f5=[$5], $f6=[$6], $f7=[$7], $f8=[$8], $f9=[$9], $f10=[$10], $f11=[$11], $f12=[$12], $f13=[$13], $f14=[$14], $f15=[$15], $f16=[$16], $f17=[$17], $f18=[$18], $f19=[$19], $f20=[$20], $f21=[$21], $f22=[$22])\n"
+                    + "  LogicalProject(product_id=[$0], time_id=[$1], customer_id=[$2], promotion_id=[$3], store_id=[$4], store_sales=[$5], store_cost=[$6], unit_sales=[$7], product_class_id=[$8], product_id0=[$9], brand_name=[$10], product_name=[$11], SKU=[$12], SRP=[$13], gross_weight=[$14], net_weight=[$15], recyclable_package=[$16], low_fat=[$17], units_per_case=[$18], cases_per_pallet=[$19], shelf_width=[$20], shelf_height=[$21], shelf_depth=[$22])\n"
                     + "    LogicalTableScan(table=[[adhoc, star]])\n",
                 counter));
     assertThat(counter.intValue(), equalTo(1));
@@ -213,7 +213,7 @@ public class LatticeTest {
                 assertThat(s,
                     anyOf(
                         containsString(
-                            "LogicalProject($f0=[$1], $f1=[$0])\n"
+                            "LogicalProject(brand_name=[$1], customer_id=[$0])\n"
                             + "  LogicalAggregate(group=[{2, 10}])\n"
                             + "    LogicalTableScan(table=[[adhoc, star]])\n"),
                         containsString(
@@ -224,7 +224,7 @@ public class LatticeTest {
             });
     assertThat(counter.intValue(), equalTo(2));
     that.explainContains(""
-        + "EnumerableCalc(expr#0..1=[{inputs}], $f0=[$t1], $f1=[$t0])\n"
+        + "EnumerableCalc(expr#0..1=[{inputs}], brand_name=[$t1], customer_id=[$t0])\n"
         + "  EnumerableTableScan(table=[[adhoc, m{2, 10}]])")
         .returnsCount(69203);
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
index c90bc92..710d1c1 100644
--- a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
+++ b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java
@@ -35,10 +35,10 @@ public class EnumerableCorrelateTest {
             "EnumerableCalc(expr#0..4=[{inputs}], empid=[$t0], name=[$t2])\n"
             + "  EnumerableSemiJoin(condition=[=($1, $5)], joinType=[inner])\n"
             + "    EnumerableTableScan(table=[[s, emps]])\n"
-            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f01=[$t0], $f0=[$t5])\n"
+            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], deptno0=[$t0], $f0=[$t5])\n"
             + "      EnumerableJoin(condition=[=($0, $1)], joinType=[inner])\n"
             + "        EnumerableAggregate(group=[{0}])\n"
-            + "          EnumerableCalc(expr#0..4=[{inputs}], $f0=[$t1])\n"
+            + "          EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])\n"
             + "            EnumerableTableScan(table=[[s, emps]])\n"
             + "        EnumerableTableScan(table=[[s, depts]])")
         .returnsUnordered(

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/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 701d66a..55f287c 100644
--- a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
+++ b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
@@ -41,6 +41,7 @@ import org.apache.calcite.rel.convert.ConverterRule;
 import org.apache.calcite.rel.core.TableScan;
 import org.apache.calcite.rel.metadata.RelMetadataQuery;
 import org.apache.calcite.rel.rules.FilterMergeRule;
+import org.apache.calcite.rel.rules.ProjectToWindowRule;
 import org.apache.calcite.rel.rules.SortRemoveRule;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
@@ -69,6 +70,7 @@ import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -105,8 +107,8 @@ public class PlannerTest {
             + "WHERE `name` LIKE '%e%'",
 
         "LogicalProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
-            + "  LogicalFilter(condition=[LIKE($2, '%e%')])\n"
-            + "    EnumerableTableScan(table=[[hr, emps]])\n");
+        + "  LogicalFilter(condition=[LIKE($2, '%e%')])\n"
+        + "    EnumerableTableScan(table=[[hr, emps]])\n");
   }
 
   @Test(expected = SqlParseException.class)
@@ -139,8 +141,8 @@ public class PlannerTest {
             + "OFFSET 10 ROWS",
 
         "LogicalSort(sort0=[$1], dir0=[ASC], offset=[10])\n"
-            + "  LogicalProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
-            + "    EnumerableTableScan(table=[[hr, emps]])\n");
+        + "  LogicalProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
+        + "    EnumerableTableScan(table=[[hr, emps]])\n");
   }
 
   private String toString(RelNode rel) {
@@ -324,7 +326,7 @@ public class PlannerTest {
     assertThat(toString(transform),
         equalTo(
             "EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
-                + "  EnumerableTableScan(table=[[hr, emps]])\n"));
+            + "  EnumerableTableScan(table=[[hr, emps]])\n"));
   }
 
   /** Unit test that parses, validates, converts and
@@ -354,18 +356,75 @@ public class PlannerTest {
    * plans for query using two duplicate order by.
    * The duplicate order by should be removed by SortRemoveRule. */
   @Test public void testDuplicateSortPlan() throws Exception {
+    runDuplicateSortCheck(
+        "select empid from ( "
+        + "select * "
+        + "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");
+  }
+
+  /** Unit test that parses, validates, converts and
+   * plans for query using two duplicate order by.
+   * The duplicate order by should be removed by SortRemoveRule*/
+  @Test public void testDuplicateSortPlanWithExpr() throws Exception {
+    runDuplicateSortCheck("select empid+deptno from ( "
+        + "select empid, deptno "
+        + "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");
+  }
+
+  /** Tests that outer order by is not removed since window function
+   * might reorder the rows in-between */
+  @Ignore("RelOptPlanner$CannotPlanException: Node [rel#27:Subset#6"
+      + ".ENUMERABLE.[]] could not be implemented; planner state:\n"
+      + "\n"
+      + "Root: rel#27:Subset#6.ENUMERABLE.[]")
+  @Test public void testDuplicateSortPlanWithOver() throws Exception {
+    runDuplicateSortCheck("select empid+deptno from ( "
+        + "select empid, deptno, count(*) over (partition by deptno) emp_cnt from ( "
+        + "  select empid, deptno "
+        + "    from emps "
+        + "   order by emps.deptno) "
+        + ")"
+        + "order by deptno",
+        "EnumerableProject(EXPR$0=[$0])\n"
+        + "  EnumerableSort(sort0=[$1], dir0=[ASC])\n"
+        + "    EnumerableProject(EXPR$0=[+($0, $1)], deptno=[$1])\n"
+        + "      EnumerableProject(empid=[$0], deptno=[$1], $2=[$2])\n"
+        + "        EnumerableWindow(window#0=[window(partition {1} order by [] range between UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING aggs [COUNT()])])\n"
+        + "          EnumerableSort(sort0=[$1], dir0=[ASC])\n"
+        + "            EnumerableProject(empid=[$0], deptno=[$1])\n"
+        + "              EnumerableTableScan(table=[[hr, emps]])\n");
+  }
+
+  // If proper "SqlParseException, ValidationException, RelConversionException"
+  // is used, then checkstyle fails with
+  // "Redundant throws: 'ValidationException' listed more then one time"
+  // "Redundant throws: 'RelConversionException' listed more then one time"
+  private void runDuplicateSortCheck(String sql, String plan) throws Exception {
     RuleSet ruleSet =
         RuleSets.ofList(
             SortRemoveRule.INSTANCE,
             EnumerableRules.ENUMERABLE_PROJECT_RULE,
-            EnumerableRules.ENUMERABLE_SORT_RULE);
-    Planner planner = getPlanner(null, Programs.of(ruleSet));
-    SqlNode parse = planner.parse(
-        "select \"empid\" from ( "
-            + "select * "
-            + "from \"emps\" "
-            + "order by \"emps\".\"deptno\") "
-            + "order by \"deptno\"");
+            EnumerableRules.ENUMERABLE_WINDOW_RULE,
+            EnumerableRules.ENUMERABLE_SORT_RULE,
+            ProjectToWindowRule.PROJECT);
+    Planner planner = getPlanner(null,
+        SqlParser.configBuilder().setLex(Lex.JAVA).build(),
+        Programs.of(ruleSet));
+    SqlNode parse = planner.parse(sql);
     SqlNode validate = planner.validate(parse);
     RelNode convert = planner.convert(validate);
     RelTraitSet traitSet = planner.getEmptyTraitSet()
@@ -375,12 +434,7 @@ public class PlannerTest {
       return;
     }
     RelNode transform = planner.transform(0, traitSet, convert);
-    assertThat(toString(transform),
-        equalTo("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"));
+    assertThat(toString(transform), equalTo(plan));
   }
 
   /** Unit test that parses, validates, converts and
@@ -655,7 +709,7 @@ public class PlannerTest {
             + "where c.\"city\" = 'San Francisco'\n"
             + "and p.\"brand_name\" = 'Washington'",
         "EnumerableProject(product_id=[$0], time_id=[$1], customer_id=[$2], promotion_id=[$3], store_id=[$4], store_sales=[$5], store_cost=[$6], unit_sales=[$7], customer_id0=[$8], account_num=[$9], lname=[$10], fname=[$11], mi=[$12], address1=[$13], address2=[$14], address3=[$15], address4=[$16], city=[$17], state_province=[$18], postal_code=[$19], country=[$20], customer_region_id=[$21], phone1=[$22], phone2=[$23], birthdate=[$24], marital_status=[$25], yearly_income=[$26], gender=[$27], total_children=[$28], num_children_at_home=[$29], education=[$30], date_accnt_opened=[$31], member_card=[$32], occupation=[$33], houseowner=[$34], num_cars_owned=[$35], fullname=[$36], product_class_id=[$37], product_id0=[$38], brand_name=[$39], product_name=[$40], SKU=[$41], SRP=[$42], gross_weight=[$43], net_weight=[$44], recyclable_package=[$45], low_fat=[$46], units_per_case=[$47], cases_per_pallet=[$48], shelf_width=[$49], shelf_height=[$50], shelf_depth=[$51])\n"
-            + "  EnumerableProject($f0=[$44], $f1=[$45], $f2=[$46], $f3=[$47], $f4=[$48], $f5=[$49], $f6=[$50], $f7=[$51], $f8=[$15], $f9=[$16], $f10=[$17], $f11=[$18], $f12=[$19], $f13=[$20], $f14=[$21], $f15=[$22], $f16=[$23], $f17=[$24], $f18=[$25], $f19=[$26], $f20=[$27], $f21=[$28], $f22=[$29], $f23=[$30], $f24=[$31], $f25=[$32], $f26=[$33], $f27=[$34], $f28=[$35], $f29=[$36], $f30=[$37], $f31=[$38], $f32=[$39], $f33=[$40], $f34=[$41], $f35=[$42], $f36=[$43], $f37=[$0], $f38=[$1], $f39=[$2], $f40=[$3], $f41=[$4], $f42=[$5], $f43=[$6], $f44=[$7], $f45=[$8], $f46=[$9], $f47=[$10], $f48=[$11], $f49=[$12], $f50=[$13], $f51=[$14])\n"
+            + "  EnumerableProject(product_id0=[$44], time_id=[$45], customer_id0=[$46], promotion_id=[$47], store_id=[$48], store_sales=[$49], store_cost=[$50], unit_sales=[$51], customer_id=[$15], account_num=[$16], lname=[$17], fname=[$18], mi=[$19], address1=[$20], address2=[$21], address3=[$22], address4=[$23], city=[$24], state_province=[$25], postal_code=[$26], country=[$27], customer_region_id=[$28], phone1=[$29], phone2=[$30], birthdate=[$31], marital_status=[$32], yearly_income=[$33], gender=[$34], total_children=[$35], num_children_at_home=[$36], education=[$37], date_accnt_opened=[$38], member_card=[$39], occupation=[$40], houseowner=[$41], num_cars_owned=[$42], fullname=[$43], product_class_id=[$0], product_id=[$1], brand_name=[$2], product_name=[$3], SKU=[$4], SRP=[$5], gross_weight=[$6], net_weight=[$7], recyclable_package=[$8], low_fat=[$9], units_per_case=[$10], cases_per_pallet=[$11], shelf_width=[$12], shelf_height=[$13], shelf_depth=[$14])\n"
             + "    EnumerableJoin(condition=[=($1, $44)], joinType=[inner])\n"
             + "      EnumerableFilter(condition=[=($2, 'Washington')])\n"
             + "        EnumerableTableScan(table=[[foodmart2, product]])\n"
@@ -681,7 +735,7 @@ public class PlannerTest {
             + "where c.\"city\" = 'San Francisco'\n"
             + "and p.\"brand_name\" = 'Washington'",
         "EnumerableProject(product_id=[$0], time_id=[$1], customer_id=[$2], promotion_id=[$3], store_id=[$4], store_sales=[$5], store_cost=[$6], unit_sales=[$7], customer_id0=[$8], account_num=[$9], lname=[$10], fname=[$11], mi=[$12], address1=[$13], address2=[$14], address3=[$15], address4=[$16], city=[$17], state_province=[$18], postal_code=[$19], country=[$20], customer_region_id=[$21], phone1=[$22], phone2=[$23], birthdate=[$24], marital_status=[$25], yearly_income=[$26], gender=[$27], total_children=[$28], num_children_at_home=[$29], education=[$30], date_accnt_opened=[$31], member_card=[$32], occupation=[$33], houseowner=[$34], num_cars_owned=[$35], fullname=[$36], product_class_id=[$37], product_id0=[$38], brand_name=[$39], product_name=[$40], SKU=[$41], SRP=[$42], gross_weight=[$43], net_weight=[$44], recyclable_package=[$45], low_fat=[$46], units_per_case=[$47], cases_per_pallet=[$48], shelf_width=[$49], shelf_height=[$50], shelf_depth=[$51], product_class_id0=[$52], produc
 t_subcategory=[$53], product_category=[$54], product_department=[$55], product_family=[$56])\n"
-            + "  EnumerableProject($f0=[$49], $f1=[$50], $f2=[$51], $f3=[$52], $f4=[$53], $f5=[$54], $f6=[$55], $f7=[$56], $f8=[$0], $f9=[$1], $f10=[$2], $f11=[$3], $f12=[$4], $f13=[$5], $f14=[$6], $f15=[$7], $f16=[$8], $f17=[$9], $f18=[$10], $f19=[$11], $f20=[$12], $f21=[$13], $f22=[$14], $f23=[$15], $f24=[$16], $f25=[$17], $f26=[$18], $f27=[$19], $f28=[$20], $f29=[$21], $f30=[$22], $f31=[$23], $f32=[$24], $f33=[$25], $f34=[$26], $f35=[$27], $f36=[$28], $f37=[$34], $f38=[$35], $f39=[$36], $f40=[$37], $f41=[$38], $f42=[$39], $f43=[$40], $f44=[$41], $f45=[$42], $f46=[$43], $f47=[$44], $f48=[$45], $f49=[$46], $f50=[$47], $f51=[$48], $f52=[$29], $f53=[$30], $f54=[$31], $f55=[$32], $f56=[$33])\n"
+            + "  EnumerableProject(product_id0=[$49], time_id=[$50], customer_id0=[$51], promotion_id=[$52], store_id=[$53], store_sales=[$54], store_cost=[$55], unit_sales=[$56], customer_id=[$0], account_num=[$1], lname=[$2], fname=[$3], mi=[$4], address1=[$5], address2=[$6], address3=[$7], address4=[$8], city=[$9], state_province=[$10], postal_code=[$11], country=[$12], customer_region_id=[$13], phone1=[$14], phone2=[$15], birthdate=[$16], marital_status=[$17], yearly_income=[$18], gender=[$19], total_children=[$20], num_children_at_home=[$21], education=[$22], date_accnt_opened=[$23], member_card=[$24], occupation=[$25], houseowner=[$26], num_cars_owned=[$27], fullname=[$28], product_class_id0=[$34], product_id=[$35], brand_name=[$36], product_name=[$37], SKU=[$38], SRP=[$39], gross_weight=[$40], net_weight=[$41], recyclable_package=[$42], low_fat=[$43], units_per_case=[$44], cases_per_pallet=[$45], shelf_width=[$46], shelf_height=[$47], shelf_depth=[$48], product_class_id=[$29]
 , product_subcategory=[$30], product_category=[$31], product_department=[$32], product_family=[$33])\n"
             + "    EnumerableJoin(condition=[=($0, $51)], joinType=[inner])\n"
             + "      EnumerableFilter(condition=[=($9, 'San Francisco')])\n"
             + "        EnumerableTableScan(table=[[foodmart2, customer]])\n"
@@ -704,7 +758,7 @@ public class PlannerTest {
             + "  join \"store\" as st using (\"store_id\")\n"
             + "where c.\"city\" = 'San Francisco'\n",
         "EnumerableProject(product_id=[$0], time_id=[$1], customer_id=[$2], promotion_id=[$3], store_id=[$4], store_sales=[$5], store_cost=[$6], unit_sales=[$7], customer_id0=[$8], account_num=[$9], lname=[$10], fname=[$11], mi=[$12], address1=[$13], address2=[$14], address3=[$15], address4=[$16], city=[$17], state_province=[$18], postal_code=[$19], country=[$20], customer_region_id=[$21], phone1=[$22], phone2=[$23], birthdate=[$24], marital_status=[$25], yearly_income=[$26], gender=[$27], total_children=[$28], num_children_at_home=[$29], education=[$30], date_accnt_opened=[$31], member_card=[$32], occupation=[$33], houseowner=[$34], num_cars_owned=[$35], fullname=[$36], product_class_id=[$37], product_id0=[$38], brand_name=[$39], product_name=[$40], SKU=[$41], SRP=[$42], gross_weight=[$43], net_weight=[$44], recyclable_package=[$45], low_fat=[$46], units_per_case=[$47], cases_per_pallet=[$48], shelf_width=[$49], shelf_height=[$50], shelf_depth=[$51], product_class_id0=[$52], produc
 t_subcategory=[$53], product_category=[$54], product_department=[$55], product_family=[$56], store_id0=[$57], store_type=[$58], region_id=[$59], store_name=[$60], store_number=[$61], store_street_address=[$62], store_city=[$63], store_state=[$64], store_postal_code=[$65], store_country=[$66], store_manager=[$67], store_phone=[$68], store_fax=[$69], first_opened_date=[$70], last_remodel_date=[$71], store_sqft=[$72], grocery_sqft=[$73], frozen_sqft=[$74], meat_sqft=[$75], coffee_bar=[$76], video_store=[$77], salad_bar=[$78], prepared_food=[$79], florist=[$80])\n"
-            + "  EnumerableProject($f0=[$73], $f1=[$74], $f2=[$75], $f3=[$76], $f4=[$77], $f5=[$78], $f6=[$79], $f7=[$80], $f8=[$24], $f9=[$25], $f10=[$26], $f11=[$27], $f12=[$28], $f13=[$29], $f14=[$30], $f15=[$31], $f16=[$32], $f17=[$33], $f18=[$34], $f19=[$35], $f20=[$36], $f21=[$37], $f22=[$38], $f23=[$39], $f24=[$40], $f25=[$41], $f26=[$42], $f27=[$43], $f28=[$44], $f29=[$45], $f30=[$46], $f31=[$47], $f32=[$48], $f33=[$49], $f34=[$50], $f35=[$51], $f36=[$52], $f37=[$58], $f38=[$59], $f39=[$60], $f40=[$61], $f41=[$62], $f42=[$63], $f43=[$64], $f44=[$65], $f45=[$66], $f46=[$67], $f47=[$68], $f48=[$69], $f49=[$70], $f50=[$71], $f51=[$72], $f52=[$53], $f53=[$54], $f54=[$55], $f55=[$56], $f56=[$57], $f57=[$0], $f58=[$1], $f59=[$2], $f60=[$3], $f61=[$4], $f62=[$5], $f63=[$6], $f64=[$7], $f65=[$8], $f66=[$9], $f67=[$10], $f68=[$11], $f69=[$12], $f70=[$13], $f71=[$14], $f72=[$15], $f73=[$16], $f74=[$17], $f75=[$18], $f76=[$19], $f77=[$20], $f78=[$21], $f79=[$22], $f80=[$23])\n"
+            + "  EnumerableProject(product_id0=[$73], time_id=[$74], customer_id0=[$75], promotion_id=[$76], store_id0=[$77], store_sales=[$78], store_cost=[$79], unit_sales=[$80], customer_id=[$24], account_num=[$25], lname=[$26], fname=[$27], mi=[$28], address1=[$29], address2=[$30], address3=[$31], address4=[$32], city=[$33], state_province=[$34], postal_code=[$35], country=[$36], customer_region_id=[$37], phone1=[$38], phone2=[$39], birthdate=[$40], marital_status=[$41], yearly_income=[$42], gender=[$43], total_children=[$44], num_children_at_home=[$45], education=[$46], date_accnt_opened=[$47], member_card=[$48], occupation=[$49], houseowner=[$50], num_cars_owned=[$51], fullname=[$52], product_class_id0=[$58], product_id=[$59], brand_name=[$60], product_name=[$61], SKU=[$62], SRP=[$63], gross_weight=[$64], net_weight=[$65], recyclable_package=[$66], low_fat=[$67], units_per_case=[$68], cases_per_pallet=[$69], shelf_width=[$70], shelf_height=[$71], shelf_depth=[$72], product_cla
 ss_id=[$53], product_subcategory=[$54], product_category=[$55], product_department=[$56], product_family=[$57], store_id=[$0], store_type=[$1], region_id=[$2], store_name=[$3], store_number=[$4], store_street_address=[$5], store_city=[$6], store_state=[$7], store_postal_code=[$8], store_country=[$9], store_manager=[$10], store_phone=[$11], store_fax=[$12], first_opened_date=[$13], last_remodel_date=[$14], store_sqft=[$15], grocery_sqft=[$16], frozen_sqft=[$17], meat_sqft=[$18], coffee_bar=[$19], video_store=[$20], salad_bar=[$21], prepared_food=[$22], florist=[$23])\n"
             + "    EnumerableJoin(condition=[=($0, $77)], joinType=[inner])\n"
             + "      EnumerableTableScan(table=[[foodmart2, store]])\n"
             + "      EnumerableJoin(condition=[=($0, $51)], joinType=[inner])\n"
@@ -724,8 +778,7 @@ public class PlannerTest {
             + "join \"customer\" using (\"customer_id\")\n"
             + "cross join \"department\"",
         "EnumerableProject(product_id=[$0], time_id=[$1], customer_id=[$2], promotion_id=[$3], store_id=[$4], store_sales=[$5], store_cost=[$6], unit_sales=[$7], customer_id0=[$8], account_num=[$9], lname=[$10], fname=[$11], mi=[$12], address1=[$13], address2=[$14], address3=[$15], address4=[$16], city=[$17], state_province=[$18], postal_code=[$19], country=[$20], customer_region_id=[$21], phone1=[$22], phone2=[$23], birthdate=[$24], marital_status=[$25], yearly_income=[$26], gender=[$27], total_children=[$28], num_children_at_home=[$29], education=[$30], date_accnt_opened=[$31], member_card=[$32], occupation=[$33], houseowner=[$34], num_cars_owned=[$35], fullname=[$36], department_id=[$37], department_description=[$38])\n"
-            + "  EnumerableProject($f0=[$31], $f1=[$32], $f2=[$33], $f3=[$34], $f4=[$35], $f5=[$36], $f6=[$37], $f7=[$38], $f8=[$2], $f9=[$3], $f10=[$4], $f11=[$5], $f12=[$6], $f13=[$7], $f14=[$8], $f15=[$9], $f16=[$10], $f17=[$11], $f18=[$12], $f19=[$13], $f20=[$14], $f21=[$15], $f22=[$16], $f23=[$17], $f24=[$18], $f25=[$19], $f26=[$20], $f27=[$21], $f28=[$22], $f29=[$23], $f30=[$24], $f31=[$25], $f32=[$26], $f33=[$27], $f34=[$28], $f35=[$29], $f36=[$30], $f37=[$0], $f38=[$1])\n"
-            //+ "    EnumerableMergeJoin(condition=[true], joinType=[inner])\n"
+            + "  EnumerableProject(product_id=[$31], time_id=[$32], customer_id0=[$33], promotion_id=[$34], store_id=[$35], store_sales=[$36], store_cost=[$37], unit_sales=[$38], customer_id=[$2], account_num=[$3], lname=[$4], fname=[$5], mi=[$6], address1=[$7], address2=[$8], address3=[$9], address4=[$10], city=[$11], state_province=[$12], postal_code=[$13], country=[$14], customer_region_id=[$15], phone1=[$16], phone2=[$17], birthdate=[$18], marital_status=[$19], yearly_income=[$20], gender=[$21], total_children=[$22], num_children_at_home=[$23], education=[$24], date_accnt_opened=[$25], member_card=[$26], occupation=[$27], houseowner=[$28], num_cars_owned=[$29], fullname=[$30], department_id=[$0], department_description=[$1])\n"
             + "    EnumerableJoin(condition=[true], joinType=[inner])\n"
             + "      EnumerableTableScan(table=[[foodmart2, department]])\n"
             + "      EnumerableJoin(condition=[=($0, $31)], joinType=[inner])\n"
@@ -741,8 +794,7 @@ public class PlannerTest {
             + "cross join \"department\"\n"
             + "join \"employee\" using (\"department_id\")",
         "EnumerableProject(product_id=[$0], time_id=[$1], customer_id=[$2], promotion_id=[$3], store_id=[$4], store_sales=[$5], store_cost=[$6], unit_sales=[$7], customer_id0=[$8], account_num=[$9], lname=[$10], fname=[$11], mi=[$12], address1=[$13], address2=[$14], address3=[$15], address4=[$16], city=[$17], state_province=[$18], postal_code=[$19], country=[$20], customer_region_id=[$21], phone1=[$22], phone2=[$23], birthdate=[$24], marital_status=[$25], yearly_income=[$26], gender=[$27], total_children=[$28], num_children_at_home=[$29], education=[$30], date_accnt_opened=[$31], member_card=[$32], occupation=[$33], houseowner=[$34], num_cars_owned=[$35], fullname=[$36], department_id=[$37], department_description=[$38], employee_id=[$39], full_name=[$40], first_name=[$41], last_name=[$42], position_id=[$43], position_title=[$44], store_id0=[$45], department_id0=[$46], birth_date=[$47], hire_date=[$48], end_date=[$49], salary=[$50], supervisor_id=[$51], education_level=[$52], marita
 l_status0=[$53], gender0=[$54], management_role=[$55])\n"
-            + "  EnumerableProject($f0=[$48], $f1=[$49], $f2=[$50], $f3=[$51], $f4=[$52], $f5=[$53], $f6=[$54], $f7=[$55], $f8=[$19], $f9=[$20], $f10=[$21], $f11=[$22], $f12=[$23], $f13=[$24], $f14=[$25], $f15=[$26], $f16=[$27], $f17=[$28], $f18=[$29], $f19=[$30], $f20=[$31], $f21=[$32], $f22=[$33], $f23=[$34], $f24=[$35], $f25=[$36], $f26=[$37], $f27=[$38], $f28=[$39], $f29=[$40], $f30=[$41], $f31=[$42], $f32=[$43], $f33=[$44], $f34=[$45], $f35=[$46], $f36=[$47], $f37=[$0], $f38=[$1], $f39=[$2], $f40=[$3], $f41=[$4], $f42=[$5], $f43=[$6], $f44=[$7], $f45=[$8], $f46=[$9], $f47=[$10], $f48=[$11], $f49=[$12], $f50=[$13], $f51=[$14], $f52=[$15], $f53=[$16], $f54=[$17], $f55=[$18])\n"
-            // + "    EnumerableMergeJoin(condition=[true], joinType=[inner])\n"
+            + "  EnumerableProject(product_id=[$48], time_id=[$49], customer_id0=[$50], promotion_id=[$51], store_id0=[$52], store_sales=[$53], store_cost=[$54], unit_sales=[$55], customer_id=[$19], account_num=[$20], lname=[$21], fname=[$22], mi=[$23], address1=[$24], address2=[$25], address3=[$26], address4=[$27], city=[$28], state_province=[$29], postal_code=[$30], country=[$31], customer_region_id=[$32], phone1=[$33], phone2=[$34], birthdate=[$35], marital_status0=[$36], yearly_income=[$37], gender0=[$38], total_children=[$39], num_children_at_home=[$40], education=[$41], date_accnt_opened=[$42], member_card=[$43], occupation=[$44], houseowner=[$45], num_cars_owned=[$46], fullname=[$47], department_id=[$0], department_description=[$1], employee_id=[$2], full_name=[$3], first_name=[$4], last_name=[$5], position_id=[$6], position_title=[$7], store_id=[$8], department_id0=[$9], birth_date=[$10], hire_date=[$11], end_date=[$12], salary=[$13], supervisor_id=[$14], education_level=[$1
 5], marital_status=[$16], gender=[$17], management_role=[$18])\n"
             + "    EnumerableJoin(condition=[true], joinType=[inner])\n"
             + "      EnumerableJoin(condition=[=($0, $9)], joinType=[inner])\n"
             + "        EnumerableTableScan(table=[[foodmart2, department]])\n"
@@ -867,7 +919,7 @@ public class PlannerTest {
             + "    where\n"
             + "      p.`pPartkey` = ps.`psPartkey`\n"
             + "  )\n")
-            .contains("Correlator"));
+            .contains("Correlat"));
   }
 
   public String checkTpchQuery(String tpchTestQuery) throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index a81cfdc..e305849 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -2808,7 +2808,7 @@ LogicalProject(DEPTNO=[$0], NAME=[$1])
       LogicalJoin(condition=[=($0, $2)], joinType=[left])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
         LogicalAggregate(group=[{0}], agg#0=[MIN($1)])
-          LogicalProject($f01=[$2], $f0=[true])
+          LogicalProject(DEPTNO0=[$2], $f0=[true])
             LogicalFilter(condition=[AND(=($1, $2), >($0, 100))])
               LogicalJoin(condition=[true], joinType=[inner])
                 LogicalProject(SAL=[$5], DEPTNO=[$7])
@@ -2822,11 +2822,11 @@ LogicalProject(DEPTNO=[$0], NAME=[$1])
             <![CDATA[
 LogicalProject(DEPTNO=[$0], NAME=[$1])
   LogicalProject(DEPTNO=[$0], NAME=[$1], $f0=[$3])
-    LogicalProject(DEPTNO=[$0], NAME=[$1], $f01=[CAST($2):INTEGER], $f1=[CAST($3):BOOLEAN])
+    LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[CAST($2):INTEGER], $f1=[CAST($3):BOOLEAN])
       LogicalJoin(condition=[=($0, $2)], joinType=[inner])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
         LogicalAggregate(group=[{0}], agg#0=[MIN($1)])
-          LogicalProject($f01=[$2], $f0=[true])
+          LogicalProject(DEPTNO0=[$2], $f0=[true])
             LogicalJoin(condition=[=($1, $2)], joinType=[inner])
               LogicalFilter(condition=[>($0, 100)])
                 LogicalProject(SAL=[$5], DEPTNO=[$7])
@@ -2850,7 +2850,7 @@ LogicalProject(DEPTNO=[$0], NAME=[$1])
   LogicalJoin(condition=[=($0, $2)], joinType=[inner])
     LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
     LogicalAggregate(group=[{0}], agg#0=[MIN($1)])
-      LogicalProject($f01=[$2], $f0=[true])
+      LogicalProject(DEPTNO0=[$2], $f0=[true])
         LogicalJoin(condition=[=($1, $2)], joinType=[inner])
           LogicalFilter(condition=[>($0, 100)])
             LogicalProject(SAL=[$5], DEPTNO=[$7])
@@ -2864,7 +2864,7 @@ LogicalProject(DEPTNO=[$0], NAME=[$1])
             <![CDATA[
 SemiJoin(condition=[=($0, $2)], joinType=[inner])
   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
-  LogicalProject($f01=[$2], $f0=[true])
+  LogicalProject(DEPTNO0=[$2], $f0=[true])
     LogicalJoin(condition=[=($1, $2)], joinType=[inner])
       LogicalFilter(condition=[>($0, 100)])
         LogicalProject(SAL=[$5], DEPTNO=[$7])
@@ -2888,12 +2888,12 @@ LogicalProject(DEPTNO=[$0])
   LogicalJoin(condition=[=($0, $2)], joinType=[inner])
     SemiJoin(condition=[=($0, $2)], joinType=[inner])
       LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
-      LogicalProject($f01=[$9], $f0=[true])
+      LogicalProject(DEPTNO0=[$9], $f0=[true])
         LogicalJoin(condition=[=($7, $9)], joinType=[inner])
           LogicalFilter(condition=[>($5, 100)])
             LogicalTableScan(table=[[CATALOG, SALES, EMP]])
           LogicalAggregate(group=[{0}])
-            LogicalProject($f0=[$0])
+            LogicalProject(DEPTNO=[$0])
               LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
     LogicalTableScan(table=[[CATALOG, CUSTOMER, ACCOUNT]])
 ]]>
@@ -2905,7 +2905,7 @@ LogicalProject(DEPTNO=[$0])
     SemiJoin(condition=[=($0, $1)], joinType=[inner])
       LogicalProject(DEPTNO=[$0])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
-      LogicalProject($f01=[$2])
+      LogicalProject(DEPTNO0=[$2])
         LogicalJoin(condition=[=($1, $2)], joinType=[inner])
           LogicalFilter(condition=[>($0, 100)])
             LogicalProject(SAL=[$5], DEPTNO=[$7])
@@ -2937,7 +2937,7 @@ LogicalProject(X=[$0], EXPR$1=[$2], Y=[$1])
         <Resource name="planAfter">
             <![CDATA[
 LogicalProject(X=[$0], EXPR$1=[$2], Y=[$1])
-  LogicalProject($f0=[$1], $f1=[$0], $f2=[$2])
+  LogicalProject(DEPTNO=[$1], EMPNO=[$0], EXPR$1=[$2])
     LogicalAggregate(group=[{0, 7}], EXPR$1=[SUM($5)])
       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 ]]>
@@ -2964,7 +2964,7 @@ LogicalProject(X=[$0], EXPR$1=[$4], Y=[$1])
             <![CDATA[
 LogicalProject(X=[$0], EXPR$1=[$4], Y=[$1])
   LogicalProject(X=[CASE($2, null, $0)], Y=[CASE($3, null, $1)], i$X=[$2], i$Y=[$3], EXPR$1=[$4])
-    LogicalProject($f0=[$1], $f1=[$0], $f2=[$3], $f3=[$2], $f4=[$4])
+    LogicalProject(DEPTNO=[$1], EMPNO=[$0], i$DEPTNO=[$3], i$EMPNO=[$2], EXPR$1=[$4])
       LogicalAggregate(group=[{0, 7}], groups=[[{0, 7}, {7}, {}]], indicator=[true], EXPR$1=[SUM($5)])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 ]]>

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/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 22ea262..551c9ec 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -1678,12 +1678,12 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
 LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
   LogicalJoin(condition=[=($7, $11)], joinType=[inner])
     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
-    LogicalProject(DEPTNO=[$0], NAME=[$1], $f0=[$2])
+    LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[$2])
       LogicalFilter(condition=[=($2, $0)])
         LogicalJoin(condition=[true], joinType=[inner])
           LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
           LogicalAggregate(group=[{0}])
-            LogicalProject($f0=[$7])
+            LogicalProject(DEPTNO=[$7])
               LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 ]]>
         </Resource>
@@ -1734,19 +1734,19 @@ LogicalProject(D2=[$0], D3=[$1])
         LogicalProject(D2=[+(2, $7)], D3=[+(3, $7)])
           LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalAggregate(group=[{0, 1}], agg#0=[MIN($2)])
-          LogicalProject($f00=[$1], $f03=[$2], $f0=[$0])
-            LogicalProject($f0=[true], $f00=[$1], $f03=[$2])
-              LogicalProject(EXPR$0=[1], $f00=[$3], $f03=[$2])
+          LogicalProject(D2=[$1], D3=[$2], $f0=[$0])
+            LogicalProject($f0=[true], D2=[$1], D3=[$2])
+              LogicalProject(EXPR$0=[1], D2=[$3], D3=[$2])
                 LogicalFilter(condition=[AND(=($0, $3), IS NOT NULL($1))])
                   LogicalJoin(condition=[true], joinType=[inner])
-                    LogicalProject(D1=[$0], $f0=[$4], $f03=[$3])
+                    LogicalProject(D1=[$0], $f0=[$4], D3=[$3])
                       LogicalJoin(condition=[AND(=($0, $1), =($0, $2))], joinType=[left])
                         LogicalProject(D1=[+($0, 1)])
                           LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
                         LogicalAggregate(group=[{0, 1, 2}], agg#0=[MIN($3)])
-                          LogicalProject(D1=[$1], D12=[$2], $f03=[$3], $f0=[$0])
-                            LogicalProject($f0=[true], D1=[$1], D12=[$2], $f03=[$3])
-                              LogicalProject(EXPR$0=[2], D1=[$3], D12=[$3], $f0=[$4])
+                          LogicalProject(D1=[$1], D12=[$2], D3=[$3], $f0=[$0])
+                            LogicalProject($f0=[true], D1=[$1], D12=[$2], D3=[$3])
+                              LogicalProject(EXPR$0=[2], D1=[$3], D12=[$3], D3=[$4])
                                 LogicalFilter(condition=[AND(=($0, $3), =($1, $3), =($2, $4))])
                                   LogicalJoin(condition=[true], joinType=[inner])
                                     LogicalProject(D4=[+($0, 4)], D5=[+($0, 5)], D6=[+($0, 6)])
@@ -1756,11 +1756,11 @@ LogicalProject(D2=[$0], D3=[$1])
                                         LogicalProject(D1=[+($0, 1)])
                                           LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
                                       LogicalAggregate(group=[{0}])
-                                        LogicalProject($f0=[$1])
+                                        LogicalProject(D3=[$1])
                                           LogicalProject(D2=[+(2, $7)], D3=[+(3, $7)])
                                             LogicalTableScan(table=[[CATALOG, SALES, EMP]])
                     LogicalAggregate(group=[{0}])
-                      LogicalProject($f0=[$0])
+                      LogicalProject(D2=[$0])
                         LogicalProject(D2=[+(2, $7)], D3=[+(3, $7)])
                           LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 ]]>
@@ -1781,20 +1781,20 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
       LogicalJoin(condition=[AND(=($7, $9), =($7, $10))], joinType=[left])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalAggregate(group=[{0, 1}], agg#0=[MIN($2)])
-          LogicalProject($f00=[$1], $f02=[$2], $f0=[$0])
-            LogicalProject($f0=[true], $f00=[$1], $f02=[$2])
-              LogicalProject(EXPR$0=[1], $f00=[$3], $f0=[$2])
+          LogicalProject(DEPTNO1=[$1], DEPTNO0=[$2], $f0=[$0])
+            LogicalProject($f0=[true], DEPTNO1=[$1], DEPTNO0=[$2])
+              LogicalProject(EXPR$0=[1], DEPTNO1=[$3], DEPTNO0=[$2])
                 LogicalFilter(condition=[<=($0, $3)])
                   LogicalJoin(condition=[true], joinType=[inner])
-                    LogicalProject(DEPTNO=[$0], NAME=[$1], $f0=[$2])
+                    LogicalProject(DEPTNO=[$0], NAME=[$1], DEPTNO0=[$2])
                       LogicalFilter(condition=[>=($0, $2)])
                         LogicalJoin(condition=[true], joinType=[inner])
                           LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
                           LogicalAggregate(group=[{0}])
-                            LogicalProject($f0=[$7])
+                            LogicalProject(DEPTNO=[$7])
                               LogicalTableScan(table=[[CATALOG, SALES, EMP]])
                     LogicalAggregate(group=[{0}])
-                      LogicalProject($f0=[$7])
+                      LogicalProject(DEPTNO=[$7])
                         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 ]]>
         </Resource>
@@ -1811,14 +1811,14 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
       LogicalJoin(condition=[=($7, $9)], joinType=[left])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalAggregate(group=[{0}], agg#0=[MIN($1)])
-          LogicalProject($f01=[$1], $f0=[$0])
-            LogicalProject($f0=[true], $f01=[$1])
-              LogicalProject(EXPR$0=[1], $f0=[$2])
+          LogicalProject(DEPTNO0=[$1], $f0=[$0])
+            LogicalProject($f0=[true], DEPTNO0=[$1])
+              LogicalProject(EXPR$0=[1], DEPTNO0=[$2])
                 LogicalFilter(condition=[=($2, $0)])
                   LogicalJoin(condition=[true], joinType=[inner])
                     LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
                     LogicalAggregate(group=[{0}])
-                      LogicalProject($f0=[$7])
+                      LogicalProject(DEPTNO=[$7])
                         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 ]]>
         </Resource>

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8f1e3b28/core/src/test/resources/sql/misc.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/misc.oq b/core/src/test/resources/sql/misc.oq
index 142eba6..7b8ccb7 100644
--- a/core/src/test/resources/sql/misc.oq
+++ b/core/src/test/resources/sql/misc.oq
@@ -244,10 +244,10 @@ where exists (
 !ok
 EnumerableSemiJoin(condition=[=($1, $5)], joinType=[inner])
   EnumerableTableScan(table=[[hr, emps]])
-  EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f01=[$t0], $f0=[$t5])
+  EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], deptno0=[$t0], $f0=[$t5])
     EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
       EnumerableAggregate(group=[{0}])
-        EnumerableCalc(expr#0..4=[{inputs}], $f0=[$t1])
+        EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])
           EnumerableTableScan(table=[[hr, emps]])
       EnumerableTableScan(table=[[hr, depts]])
 !plan
@@ -269,10 +269,10 @@ EnumerableCalc(expr#0..6=[{inputs}], expr#7=[IS NOT NULL($t6)], expr#8=[NOT($t7)
   EnumerableJoin(condition=[=($1, $5)], joinType=[left])
     EnumerableTableScan(table=[[hr, emps]])
     EnumerableAggregate(group=[{0}], agg#0=[MIN($1)])
-      EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f01=[$t0], $f0=[$t5])
+      EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], deptno0=[$t0], $f0=[$t5])
         EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
           EnumerableAggregate(group=[{0}])
-            EnumerableCalc(expr#0..4=[{inputs}], $f0=[$t1])
+            EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])
               EnumerableTableScan(table=[[hr, emps]])
           EnumerableTableScan(table=[[hr, depts]])
 !plan
@@ -301,23 +301,23 @@ EnumerableCalc(expr#0..7=[{inputs}], expr#8=[IS NOT NULL($t5)], expr#9=[NOT($t8)
       EnumerableJoin(condition=[=($1, $5)], joinType=[left])
         EnumerableTableScan(table=[[hr, emps]])
         EnumerableAggregate(group=[{0}], agg#0=[MIN($1)])
-          EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f01=[$t0], $f0=[$t5])
+          EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], deptno0=[$t0], $f0=[$t5])
             EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
               EnumerableAggregate(group=[{0}])
-                EnumerableCalc(expr#0..4=[{inputs}], $f0=[$t1])
+                EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])
                   EnumerableTableScan(table=[[hr, emps]])
               EnumerableTableScan(table=[[hr, depts]])
     EnumerableAggregate(group=[{0}], agg#0=[MIN($1)])
-      EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], expr#6=[90], expr#7=[+($t1, $t6)], expr#8=[CAST($t0):INTEGER NOT NULL], expr#9=[=($t7, $t8)], $f01=[$t0], $f0=[$t5], $condition=[$t9])
+      EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], expr#6=[90], expr#7=[+($t1, $t6)], expr#8=[CAST($t0):INTEGER NOT NULL], expr#9=[=($t7, $t8)], empid=[$t0], $f0=[$t5], $condition=[$t9])
         EnumerableJoin(condition=[true], joinType=[inner])
           EnumerableAggregate(group=[{0}])
-            EnumerableCalc(expr#0..4=[{inputs}], $f0=[$t0])
+            EnumerableCalc(expr#0..4=[{inputs}], empid=[$t0])
               EnumerableSemiJoin(condition=[=($1, $5)], joinType=[inner])
                 EnumerableTableScan(table=[[hr, emps]])
-                EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f01=[$t0], $f0=[$t5])
+                EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], deptno0=[$t0], $f0=[$t5])
                   EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
                     EnumerableAggregate(group=[{0}])
-                      EnumerableCalc(expr#0..4=[{inputs}], $f0=[$t1])
+                      EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])
                         EnumerableTableScan(table=[[hr, emps]])
                     EnumerableTableScan(table=[[hr, depts]])
           EnumerableTableScan(table=[[hr, depts]])
@@ -480,7 +480,7 @@ from "sales_fact_1997" as s
   join "product_class" as pc using ("product_class_id")
 where c."city" = 'San Francisco'
  and pc."product_department" = 'Snacks';
-EnumerableCalc(expr#0..56=[{inputs}], product_id=[$t20], time_id=[$t21], customer_id=[$t22], promotion_id=[$t23], store_id=[$t24], store_sales=[$t25], store_cost=[$t26], unit_sales=[$t27], customer_id0=[$t28], account_num=[$t29], lname=[$t30], fname=[$t31], mi=[$t32], address1=[$t33], address2=[$t34], address3=[$t35], address4=[$t36], city=[$t37], state_province=[$t38], postal_code=[$t39], country=[$t40], customer_region_id=[$t41], phone1=[$t42], phone2=[$t43], birthdate=[$t44], marital_status=[$t45], yearly_income=[$t46], gender=[$t47], total_children=[$t48], num_children_at_home=[$t49], education=[$t50], date_accnt_opened=[$t51], member_card=[$t52], occupation=[$t53], houseowner=[$t54], num_cars_owned=[$t55], fullname=[$t56], product_class_id=[$t5], product_id0=[$t6], brand_name=[$t7], product_name=[$t8], SKU=[$t9], SRP=[$t10], gross_weight=[$t11], net_weight=[$t12], recyclable_package=[$t13], low_fat=[$t14], units_per_case=[$t15], cases_per_pallet=[$t16], shelf_width=[$t17], shel
 f_height=[$t18], shelf_depth=[$t19], product_class_id0=[$t0], product_subcategory=[$t1], product_category=[$t2], product_department=[$t3], product_family=[$t4])
+EnumerableCalc(expr#0..56=[{inputs}], product_id0=[$t20], time_id=[$t21], customer_id=[$t22], promotion_id=[$t23], store_id=[$t24], store_sales=[$t25], store_cost=[$t26], unit_sales=[$t27], customer_id0=[$t28], account_num=[$t29], lname=[$t30], fname=[$t31], mi=[$t32], address1=[$t33], address2=[$t34], address3=[$t35], address4=[$t36], city=[$t37], state_province=[$t38], postal_code=[$t39], country=[$t40], customer_region_id=[$t41], phone1=[$t42], phone2=[$t43], birthdate=[$t44], marital_status=[$t45], yearly_income=[$t46], gender=[$t47], total_children=[$t48], num_children_at_home=[$t49], education=[$t50], date_accnt_opened=[$t51], member_card=[$t52], occupation=[$t53], houseowner=[$t54], num_cars_owned=[$t55], fullname=[$t56], product_class_id0=[$t5], product_id=[$t6], brand_name=[$t7], product_name=[$t8], SKU=[$t9], SRP=[$t10], gross_weight=[$t11], net_weight=[$t12], recyclable_package=[$t13], low_fat=[$t14], units_per_case=[$t15], cases_per_pallet=[$t16], shelf_width=[$t17], she
 lf_height=[$t18], shelf_depth=[$t19], product_class_id=[$t0], product_subcategory=[$t1], product_category=[$t2], product_department=[$t3], product_family=[$t4])
   EnumerableJoin(condition=[=($6, $20)], joinType=[inner])
     EnumerableJoin(condition=[=($0, $5)], joinType=[inner])
       EnumerableCalc(expr#0..4=[{inputs}], expr#5=['Snacks'], expr#6=[=($t3, $t5)], proj#0..4=[{exprs}], $condition=[$t6])


Mime
View raw message