calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [5/5] incubator-calcite git commit: [CALCITE-675] Enable AggregateProjectMergeRule in standard rule set
Date Thu, 16 Apr 2015 16:16:45 GMT
[CALCITE-675] Enable AggregateProjectMergeRule in standard rule set

Fix various bugs involving field mix-ups in Aggregates


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

Branch: refs/heads/master
Commit: 8276f2580ed427d02cee7f3695f182e77a7ae978
Parents: a42b88d
Author: Julian Hyde <jhyde@apache.org>
Authored: Thu Apr 9 18:45:04 2015 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Tue Apr 14 18:27:47 2015 -0700

----------------------------------------------------------------------
 .../adapter/enumerable/PhysTypeImpl.java        | 10 +--
 .../calcite/plan/volcano/VolcanoPlanner.java    |  2 +
 .../rel/rules/AggregateProjectMergeRule.java    |  3 +-
 .../rel/rules/AggregateReduceFunctionsRule.java |  7 +-
 .../calcite/rel/rules/AggregateRemoveRule.java  | 28 +++++---
 .../test/JdbcFrontJdbcBackLinqMiddleTest.java   |  2 +-
 .../java/org/apache/calcite/test/JdbcTest.java  | 75 +++++++++-----------
 .../org/apache/calcite/test/LatticeTest.java    | 17 +++--
 .../enumerable/EnumerableCorrelateTest.java     |  9 ++-
 core/src/test/resources/sql/join.oq             | 19 +++--
 core/src/test/resources/sql/misc.oq             | 54 +++++++-------
 core/src/test/resources/sql/subquery.oq         | 11 ++-
 12 files changed, 117 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
index 6d51b97..1cc6628 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java
@@ -17,6 +17,7 @@
 package org.apache.calcite.adapter.enumerable;
 
 import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.linq4j.Ord;
 import org.apache.calcite.linq4j.function.Function1;
 import org.apache.calcite.linq4j.tree.BlockBuilder;
 import org.apache.calcite.linq4j.tree.Expression;
@@ -55,7 +56,7 @@ public class PhysTypeImpl implements PhysType {
   private final JavaTypeFactory typeFactory;
   private final RelDataType rowType;
   private final Type javaRowClass;
-  private final List<Class> fieldClasses = new ArrayList<Class>();
+  private final List<Class> fieldClasses = new ArrayList<>();
   final JavaRowFormat format;
 
   /** Creates a PhysTypeImpl. */
@@ -171,12 +172,13 @@ public class PhysTypeImpl implements PhysType {
     final PhysType targetPhysType =
         project(fields, true, targetFormat);
     final List<Expression> expressions = Lists.newArrayList();
-    for (Integer field : fields) {
+    for (Ord<Integer> ord : Ord.zip(fields)) {
+      final Integer field = ord.e;
       if (usedFields.contains(field)) {
         expressions.add(fieldReference(parameter, field));
       } else {
         final Primitive primitive =
-            Primitive.of(targetPhysType.fieldClass(field));
+            Primitive.of(targetPhysType.fieldClass(ord.i));
         expressions.add(
             Expressions.constant(
                 primitive != null ? primitive.defaultValue : null));
@@ -213,7 +215,7 @@ public class PhysTypeImpl implements PhysType {
   }
 
   public List<Expression> accessors(Expression v1, List<Integer> argList) {
-    final List<Expression> expressions = new ArrayList<Expression>();
+    final List<Expression> expressions = new ArrayList<>();
     for (int field : argList) {
       expressions.add(
           Types.castIfNecessary(

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
index 42d1b56..dbaf7cc 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
@@ -51,6 +51,7 @@ import org.apache.calcite.rel.core.TableScan;
 import org.apache.calcite.rel.metadata.RelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelMetadataQuery;
 import org.apache.calcite.rel.rules.AggregateJoinTransposeRule;
+import org.apache.calcite.rel.rules.AggregateProjectMergeRule;
 import org.apache.calcite.rel.rules.AggregateRemoveRule;
 import org.apache.calcite.rel.rules.CalcRemoveRule;
 import org.apache.calcite.rel.rules.FilterJoinRule;
@@ -1070,6 +1071,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
     addRule(UnionToDistinctRule.INSTANCE);
     addRule(ProjectRemoveRule.INSTANCE);
     addRule(AggregateJoinTransposeRule.INSTANCE);
+    addRule(AggregateProjectMergeRule.INSTANCE);
     addRule(CalcRemoveRule.INSTANCE);
     addRule(SortRemoveRule.INSTANCE);
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectMergeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectMergeRule.java
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectMergeRule.java
index 0f611da..91e33f2 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectMergeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectMergeRule.java
@@ -114,8 +114,7 @@ public class AggregateProjectMergeRule extends RelOptRule {
     // Add a project if the group set is not in the same order or
     // contains duplicates.
     RelNode rel = newAggregate;
-    //noinspection EqualsBetweenInconvertibleTypes
-    if (!newGroupSet.toList().equals(newKeys)) {
+    if (!newKeys.equals(newGroupSet.asList())) {
       final List<Integer> posList = Lists.newArrayList();
       for (int newKey : newKeys) {
         posList.add(newGroupSet.indexOf(newKey));

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
index ead7cd5..95ca9c8 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
@@ -153,7 +153,7 @@ public class AggregateReduceFunctionsRule extends RelOptRule {
     // will add an expression to the end, and we will create an extra
     // project.
     RelNode input = oldAggRel.getInput();
-    List<RexNode> inputExprs = new ArrayList<RexNode>();
+    final List<RexNode> inputExprs = new ArrayList<>();
     for (RelDataTypeField field : input.getRowType().getFieldList()) {
       inputExprs.add(
           rexBuilder.makeInputRef(
@@ -249,8 +249,9 @@ public class AggregateReduceFunctionsRule extends RelOptRule {
       // anything else:  preserve original call
       RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();
       final int nGroups = oldAggRel.getGroupCount();
-      List<RelDataType> oldArgTypes = SqlTypeUtil
-          .projectTypes(oldAggRel.getRowType(), oldCall.getArgList());
+      List<RelDataType> oldArgTypes =
+          SqlTypeUtil.projectTypes(
+              oldAggRel.getInput().getRowType(), oldCall.getArgList());
       return rexBuilder.addAggCall(oldCall,
           nGroups,
           oldAggRel.indicator,

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
index 5c11012..6031717 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
@@ -18,6 +18,7 @@ package org.apache.calcite.rel.rules;
 
 import org.apache.calcite.plan.RelOptRule;
 import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.logical.LogicalAggregate;
 
@@ -52,20 +53,29 @@ public class AggregateRemoveRule extends RelOptRule {
   //~ Methods ----------------------------------------------------------------
 
   public void onMatch(RelOptRuleCall call) {
-    LogicalAggregate distinct = call.rel(0);
-    RelNode child = call.rel(1);
-    if (!distinct.getAggCallList().isEmpty()
-        || !child.isKey(distinct.getGroupSet())) {
+    final LogicalAggregate aggregate = call.rel(0);
+    final RelNode input = call.rel(1);
+    if (!aggregate.getAggCallList().isEmpty()
+        || aggregate.indicator
+        || !input.isKey(aggregate.getGroupSet())) {
       return;
     }
     // Distinct is "GROUP BY c1, c2" (where c1, c2 are a set of columns on
     // which the input is unique, i.e. contain a key) and has no aggregate
     // functions. It can be removed.
-    child = call.getPlanner().register(child, distinct);
-    call.transformTo(
-        convert(
-            child,
-            distinct.getTraitSet()));
+    final RelNode newInput = convert(input, aggregate.getTraitSet());
+
+    // If aggregate was projecting a subset of columns, add a project for the
+    // same effect.
+    RelNode rel;
+    if (newInput.getRowType().getFieldCount()
+        > aggregate.getRowType().getFieldCount()) {
+      rel = RelOptUtil.createProject(newInput,
+          aggregate.getGroupSet().toList());
+    } else {
+      rel = newInput;
+    }
+    call.transformTo(rel);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackLinqMiddleTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackLinqMiddleTest.java
b/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackLinqMiddleTest.java
index 3100a86..e6235de 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackLinqMiddleTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackLinqMiddleTest.java
@@ -270,7 +270,7 @@ public class JdbcFrontJdbcBackLinqMiddleTest {
         .query(
             "select \"store\".\"store_country\" as \"c0\", sum(\"inventory_fact_1997\".\"supply_time\")
as \"m0\" from \"store\" as \"store\", \"inventory_fact_1997\" as \"inventory_fact_1997\"
where \"inventory_fact_1997\".\"store_id\" = \"store\".\"store_id\" group by \"store\".\"store_country\"")
         .planContains(
-            "  final org.apache.calcite.linq4j.Enumerable _inputEnumerable1 = left.join(right,
new org.apache.calcite.linq4j.function.Function1() {\n");
+            "  return left.join(right, new org.apache.calcite.linq4j.function.Function1()
{\n");
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/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 0f0e162..c5a75ca 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -125,6 +125,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Properties;
+import java.util.Set;
 import java.util.TimeZone;
 import java.util.regex.Pattern;
 import javax.sql.DataSource;
@@ -863,7 +864,7 @@ public class JdbcTest {
     java.sql.Driver driver = DriverManager.getDriver("jdbc:calcite:");
     final DriverPropertyInfo[] propertyInfo =
         driver.getPropertyInfo("jdbc:calcite:", new Properties());
-    final HashSet<String> names = new HashSet<String>();
+    final Set<String> names = new HashSet<>();
     for (DriverPropertyInfo info : propertyInfo) {
       names.add(info.name);
     }
@@ -1801,8 +1802,7 @@ public class JdbcTest {
   /** Returns a list of (query, expected) pairs. The expected result is
    * sometimes null. */
   private static List<Pair<String, String>> querify(String[] queries1) {
-    final List<Pair<String, String>> list =
-        new ArrayList<Pair<String, String>>();
+    final List<Pair<String, String>> list = new ArrayList<>();
     for (int i = 0; i < queries1.length; i++) {
       String query = queries1[i];
       String expected = null;
@@ -2477,11 +2477,12 @@ public class JdbcTest {
         .query("select empno, desc from sales.emps,\n"
             + "  (SELECT * FROM (VALUES (10, 'SameName')) AS t (id, desc)) as sn\n"
             + "where emps.deptno = sn.id and sn.desc = 'SameName' group by empno, desc")
-        .explainContains("EnumerableAggregate(group=[{0, 1}])\n"
-            + "  EnumerableCalc(expr#0..3=[{inputs}], expr#4=[CAST($t3):INTEGER NOT NULL],
expr#5=[=($t4, $t0)], expr#6=['SameName'], expr#7=[=($t1, $t6)], expr#8=[AND($t5, $t7)], EMPNO=[$t2],
DESC=[$t1], $condition=[$t8])\n"
-            + "    EnumerableJoin(condition=[true], joinType=[inner])\n"
-            + "      EnumerableValues(tuples=[[{ 10, 'SameName' }]])\n"
-            + "      EnumerableTableScan(table=[[SALES, EMPS]])\n")
+        .explainContains("EnumerableCalc(expr#0..1=[{inputs}], EMPNO=[$t1], DESC=[$t0])\n"
+            + "  EnumerableAggregate(group=[{1, 2}])\n"
+            + "    EnumerableCalc(expr#0..3=[{inputs}], expr#4=[CAST($t3):INTEGER NOT NULL],
expr#5=[=($t4, $t0)], expr#6=['SameName'], expr#7=[=($t1, $t6)], expr#8=[AND($t5, $t7)], proj#0..3=[{exprs}],
$condition=[$t8])\n"
+            + "      EnumerableJoin(condition=[true], joinType=[inner])\n"
+            + "        EnumerableValues(tuples=[[{ 10, 'SameName' }]])\n"
+            + "        EnumerableTableScan(table=[[SALES, EMPS]])\n")
         .returns("EMPNO=1; DESC=SameName\n");
   }
 
@@ -2525,9 +2526,8 @@ public class JdbcTest {
         .with(CalciteAssert.Config.FOODMART_CLONE)
         .query(s)
         .explainContains("EnumerableAggregate(group=[{}], m0=[COUNT($0)])\n"
-            + "  EnumerableAggregate(group=[{0}])\n"
-            + "    EnumerableCalc(expr#0..7=[{inputs}], unit_sales=[$t7])\n"
-            + "      EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])")
+            + "  EnumerableAggregate(group=[{7}])\n"
+            + "    EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])")
         .returns("m0=6\n");
   }
 
@@ -2541,10 +2541,9 @@ public class JdbcTest {
         .query(s)
         .explainContains(""
             + "EnumerableCalc(expr#0..1=[{inputs}], expr#2=[CAST($t0):INTEGER NOT NULL],
u=[$t2], m0=[$t1])\n"
-            + "  EnumerableAggregate(group=[{0}], m0=[COUNT($1)])\n"
-            + "    EnumerableAggregate(group=[{0, 1}])\n"
-            + "      EnumerableCalc(expr#0..7=[{inputs}], unit_sales=[$t7], customer_id=[$t2])\n"
-            + "        EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])")
+            + "  EnumerableAggregate(group=[{1}], m0=[COUNT($0)])\n"
+            + "    EnumerableAggregate(group=[{2, 7}])\n"
+            + "      EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])")
         .returnsUnordered(
             "u=1; m0=523",
             "u=5; m0=1059",
@@ -2567,13 +2566,12 @@ public class JdbcTest {
         .query(s)
         .explainContains(""
             + "EnumerableAggregate(group=[{0}], m0=[COUNT($1)])\n"
-            + "  EnumerableAggregate(group=[{0, 1}])\n"
-            + "    EnumerableCalc(expr#0..3=[{inputs}], c0=[$t1], unit_sales=[$t3])\n"
-            + "      EnumerableJoin(condition=[=($0, $2)], joinType=[inner])\n"
-            + "        EnumerableCalc(expr#0..9=[{inputs}], expr#10=[CAST($t4):INTEGER],
expr#11=[1997], expr#12=[=($t10, $t11)], time_id=[$t0], the_year=[$t4], $condition=[$t12])\n"
-            + "          EnumerableTableScan(table=[[foodmart2, time_by_day]])\n"
-            + "        EnumerableCalc(expr#0..7=[{inputs}], time_id=[$t1], unit_sales=[$t7])\n"
-            + "          EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])")
+            + "  EnumerableAggregate(group=[{1, 3}])\n"
+            + "    EnumerableJoin(condition=[=($0, $2)], joinType=[inner])\n"
+            + "      EnumerableCalc(expr#0..9=[{inputs}], expr#10=[CAST($t4):INTEGER], expr#11=[1997],
expr#12=[=($t10, $t11)], time_id=[$t0], the_year=[$t4], $condition=[$t12])\n"
+            + "        EnumerableTableScan(table=[[foodmart2, time_by_day]])\n"
+            + "      EnumerableCalc(expr#0..7=[{inputs}], time_id=[$t1], unit_sales=[$t7])\n"
+            + "        EnumerableTableScan(table=[[foodmart2, sales_fact_1997]])")
         .returns("c0=1997; m0=6\n");
   }
 
@@ -2610,10 +2608,10 @@ public class JdbcTest {
             + "            EnumerableTableScan(table=[[hr, emps]])")
         .explainContains(""
             + "EnumerableCalc(expr#0..4=[{inputs}], proj#0..3=[{exprs}])\n"
-            + "  EnumerableSemiJoin(condition=[=($4, $5)], joinType=[inner])\n"
+            + "  EnumerableSemiJoin(condition=[=($4, $6)], joinType=[inner])\n"
             + "    EnumerableCalc(expr#0..3=[{inputs}], proj#0..3=[{exprs}], $f4=[$t0])\n"
             + "      EnumerableTableScan(table=[[hr, depts]])\n"
-            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[150], expr#6=[<($t0, $t5)],
deptno=[$t1], $condition=[$t6])\n"
+            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[150], expr#6=[<($t0, $t5)],
proj#0..4=[{exprs}], $condition=[$t6])\n"
             + "      EnumerableTableScan(table=[[hr, emps]])")
         .returnsUnordered(
             "deptno=10; name=Sales; employees=[Employee [empid: 100, deptno: 10, name: Bill],
Employee [empid: 150, deptno: 10, name: Sebastian]]; location=Location [x: -122, y: 38]");
@@ -2919,12 +2917,11 @@ public class JdbcTest {
         .returns("C=25\n")
         .explainContains("JdbcToEnumerableConverter\n"
             + "  JdbcAggregate(group=[{}], C=[COUNT()])\n"
-            + "    JdbcProject(DUMMY=[0])\n"
-            + "      JdbcJoin(condition=[=($0, $1)], joinType=[inner])\n"
-            + "        JdbcProject(store_id=[$0])\n"
-            + "          JdbcTableScan(table=[[foodmart, store]])\n"
-            + "        JdbcProject(store_id=[$0])\n"
-            + "          JdbcTableScan(table=[[foodmart, store]])\n");
+            + "    JdbcJoin(condition=[=($0, $1)], joinType=[inner])\n"
+            + "      JdbcProject(store_id=[$0])\n"
+            + "        JdbcTableScan(table=[[foodmart, store]])\n"
+            + "      JdbcProject(store_id=[$0])\n"
+            + "        JdbcTableScan(table=[[foodmart, store]])\n");
   }
 
   /** Tests composite GROUP BY where one of the columns has NULL values. */
@@ -3136,8 +3133,8 @@ public class JdbcTest {
             + "where \"deptno\" < 0")
         .explainContains(""
             + "PLAN=EnumerableCalc(expr#0..1=[{inputs}], expr#2=[0], expr#3=[=($t0, $t2)],
expr#4=[null], expr#5=[CASE($t3, $t4, $t1)], expr#6=[/($t5, $t0)], expr#7=[CAST($t6):JavaType(class
java.lang.Integer)], CS=[$t0], C=[$t0], S=[$t5], A=[$t7])\n"
-            + "  EnumerableAggregate(group=[{}], CS=[COUNT()], agg#1=[$SUM0($0)])\n"
-            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[<($t1, $t5)],
deptno=[$t1], $condition=[$t6])\n"
+            + "  EnumerableAggregate(group=[{}], CS=[COUNT()], agg#1=[$SUM0($1)])\n"
+            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[<($t1, $t5)],
proj#0..4=[{exprs}], $condition=[$t6])\n"
             + "      EnumerableTableScan(table=[[hr, emps]])\n")
         .returns("CS=0; C=0; S=null; A=null\n");
   }
@@ -3153,7 +3150,7 @@ public class JdbcTest {
         .explainContains(""
             + "PLAN=EnumerableCalc(expr#0=[{inputs}], CS=[$t0], CS2=[$t0])\n"
             + "  EnumerableAggregate(group=[{}], CS=[COUNT()])\n"
-            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[<($t1, $t5)],
deptno=[$t1], $condition=[$t6])\n"
+            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[<($t1, $t5)],
proj#0..4=[{exprs}], $condition=[$t6])\n"
             + "      EnumerableTableScan(table=[[hr, emps]])\n")
         .returns("CS=0; CS2=0\n");
   }
@@ -4925,7 +4922,7 @@ public class JdbcTest {
   /** Tests saving query results into temporary tables, per
    * {@link org.apache.calcite.avatica.Handler.ResultSink}. */
   @Test public void testAutomaticTemporaryTable() throws Exception {
-    final List<Object> objects = new ArrayList<Object>();
+    final List<Object> objects = new ArrayList<>();
     CalciteAssert.that()
         .with(
             new CalciteAssert.ConnectionFactory() {
@@ -5876,9 +5873,8 @@ public class JdbcTest {
     case HSQLDB:
       assertThat(Util.toLinux(sqls[0]),
           equalTo("SELECT COUNT(*) AS \"C\"\n"
-              + "FROM (SELECT 0 AS \"DUMMY\"\n"
               + "FROM \"foodmart\".\"employee\"\n"
-              + "WHERE \"first_name\" = 'abcde' AND \"gender\" = 'F') AS \"t0\""));
+              + "WHERE \"first_name\" = 'abcde' AND \"gender\" = 'F'"));
       break;
     }
   }
@@ -5891,7 +5887,7 @@ public class JdbcTest {
     final SchemaPlus rootSchema = calciteConnection.getRootSchema();
 
     // create schema "/a"
-    final Map<String, Schema> aSubSchemaMap = new HashMap<String, Schema>();
+    final Map<String, Schema> aSubSchemaMap = new HashMap<>();
     final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() {
       @Override protected Map<String, Schema> getSubSchemaMap() {
         return aSubSchemaMap;
@@ -5933,7 +5929,7 @@ public class JdbcTest {
     }
 
     // create schema "/a2"
-    final Map<String, Schema> a2SubSchemaMap = new HashMap<String, Schema>();
+    final Map<String, Schema> a2SubSchemaMap = new HashMap<>();
     final boolean[] changed = {false};
     final SchemaPlus a2Schema = rootSchema.add("a", new AbstractSchema() {
       @Override protected Map<String, Schema> getSubSchemaMap() {
@@ -6437,8 +6433,7 @@ public class JdbcTest {
 
   /** Mock driver that a given {@link Handler}. */
   public static class HandlerDriver extends org.apache.calcite.jdbc.Driver {
-    private static final ThreadLocal<Handler> HANDLERS =
-        new ThreadLocal<Handler>();
+    private static final ThreadLocal<Handler> HANDLERS = new ThreadLocal<>();
 
     public HandlerDriver() {
     }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/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 510cf8f..492b377 100644
--- a/core/src/test/java/org/apache/calcite/test/LatticeTest.java
+++ b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
@@ -358,15 +358,14 @@ public class LatticeTest {
                 + "GROUP BY \"s\".\"unit_sales\", \"p\".\"recyclable_package\", \"t\".\"the_day\",
\"t\".\"the_year\", \"t\".\"quarter\", \"pc\".\"product_family\"")
         .explainContains(
             "JdbcToEnumerableConverter\n"
-                + "  JdbcAggregate(group=[{0, 1, 2, 3, 4, 5}], m0=[COUNT()], m1=[SUM($6)],
m2=[SUM($0)])\n"
-                + "    JdbcProject(unit_sales=[$12], recyclable_package=[$21], the_day=[$30],
the_year=[$32], quarter=[$36], product_family=[$4], store_sales=[$10])\n"
-                + "      JdbcJoin(condition=[=($13, $0)], joinType=[inner])\n"
-                + "        JdbcTableScan(table=[[foodmart, product_class]])\n"
-                + "        JdbcJoin(condition=[=($1, $23)], joinType=[inner])\n"
-                + "          JdbcJoin(condition=[=($0, $9)], joinType=[inner])\n"
-                + "            JdbcTableScan(table=[[foodmart, sales_fact_1997]])\n"
-                + "            JdbcTableScan(table=[[foodmart, product]])\n"
-                + "          JdbcTableScan(table=[[foodmart, time_by_day]])");
+                + "  JdbcAggregate(group=[{7, 16, 25, 27, 31, 37}], m0=[COUNT()], m1=[SUM($5)],
m2=[SUM($7)])\n"
+                + "    JdbcJoin(condition=[=($8, $33)], joinType=[inner])\n"
+                + "      JdbcJoin(condition=[=($1, $23)], joinType=[inner])\n"
+                + "        JdbcJoin(condition=[=($0, $9)], joinType=[inner])\n"
+                + "          JdbcTableScan(table=[[foodmart, sales_fact_1997]])\n"
+                + "          JdbcTableScan(table=[[foodmart, product]])\n"
+                + "        JdbcTableScan(table=[[foodmart, time_by_day]])\n"
+                + "      JdbcTableScan(table=[[foodmart, product_class]])");
   }
 
   /** Tests a query that uses no columns from the fact table. */

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/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 710d1c1..e4ae781 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
@@ -33,13 +33,12 @@ public class EnumerableCorrelateTest {
             "select empid, name from emps e where exists (select 1 from depts d where d.deptno=e.deptno)")
         .explainContains(
             "EnumerableCalc(expr#0..4=[{inputs}], empid=[$t0], name=[$t2])\n"
-            + "  EnumerableSemiJoin(condition=[=($1, $5)], joinType=[inner])\n"
+            + "  EnumerableSemiJoin(condition=[=($1, $6)], joinType=[inner])\n"
             + "    EnumerableTableScan(table=[[s, emps]])\n"
-            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], deptno0=[$t0], $f0=[$t5])\n"
+            + "    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f0=[$t5], deptno0=[$t0])\n"
             + "      EnumerableJoin(condition=[=($0, $1)], joinType=[inner])\n"
-            + "        EnumerableAggregate(group=[{0}])\n"
-            + "          EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])\n"
-            + "            EnumerableTableScan(table=[[s, emps]])\n"
+            + "        EnumerableAggregate(group=[{1}])\n"
+            + "          EnumerableTableScan(table=[[s, emps]])\n"
             + "        EnumerableTableScan(table=[[s, depts]])")
         .returnsUnordered(
             "empid=100; name=Bill",

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/test/resources/sql/join.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/join.oq b/core/src/test/resources/sql/join.oq
index 08ea3f1..a840f19 100644
--- a/core/src/test/resources/sql/join.oq
+++ b/core/src/test/resources/sql/join.oq
@@ -127,11 +127,9 @@ from "scott".emp join "scott".dept using (deptno);
 !ok
 EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
   EnumerableAggregate(group=[{0}])
-    EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
-      EnumerableTableScan(table=[[scott, DEPT]])
-  EnumerableAggregate(group=[{0}])
-    EnumerableCalc(expr#0..7=[{inputs}], DEPTNO=[$t7])
-      EnumerableTableScan(table=[[scott, EMP]])
+    EnumerableTableScan(table=[[scott, DEPT]])
+  EnumerableAggregate(group=[{7}])
+    EnumerableTableScan(table=[[scott, EMP]])
 !plan
 
 select distinct dept.deptno
@@ -147,12 +145,11 @@ from "scott".emp join "scott".dept using (deptno);
 
 !ok
 EnumerableAggregate(group=[{0}])
-  EnumerableCalc(expr#0..1=[{inputs}], DEPTNO=[$t0])
-    EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
-      EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
-        EnumerableTableScan(table=[[scott, DEPT]])
-      EnumerableCalc(expr#0..7=[{inputs}], DEPTNO=[$t7])
-        EnumerableTableScan(table=[[scott, EMP]])
+  EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
+    EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
+      EnumerableTableScan(table=[[scott, DEPT]])
+    EnumerableCalc(expr#0..7=[{inputs}], DEPTNO=[$t7])
+      EnumerableTableScan(table=[[scott, EMP]])
 !plan
 
 # [CALCITE-676] AssertionError in GROUPING SETS query

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/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 dbd1fbc..4d4bc80 100644
--- a/core/src/test/resources/sql/misc.oq
+++ b/core/src/test/resources/sql/misc.oq
@@ -244,9 +244,8 @@ EnumerableSemiJoin(condition=[=($1, $5)], joinType=[inner])
   EnumerableTableScan(table=[[hr, emps]])
   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}], deptno=[$t1])
-          EnumerableTableScan(table=[[hr, emps]])
+      EnumerableAggregate(group=[{1}])
+        EnumerableTableScan(table=[[hr, emps]])
       EnumerableTableScan(table=[[hr, depts]])
 !plan
 
@@ -266,12 +265,11 @@ where not exists (
 EnumerableCalc(expr#0..6=[{inputs}], expr#7=[IS NOT NULL($t6)], expr#8=[NOT($t7)], proj#0..4=[{exprs}],
$condition=[$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], deptno0=[$t0], $f0=[$t5])
+    EnumerableAggregate(group=[{1}], agg#0=[MIN($0)])
+      EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f0=[$t5], deptno0=[$t0])
         EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
-          EnumerableAggregate(group=[{0}])
-            EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])
-              EnumerableTableScan(table=[[hr, emps]])
+          EnumerableAggregate(group=[{1}])
+            EnumerableTableScan(table=[[hr, emps]])
           EnumerableTableScan(table=[[hr, depts]])
 !plan
 
@@ -298,26 +296,23 @@ EnumerableCalc(expr#0..7=[{inputs}], expr#8=[IS NOT NULL($t5)], expr#9=[NOT($t8)
     EnumerableCalc(expr#0..6=[{inputs}], proj#0..4=[{exprs}], $f0=[$t6])
       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], deptno0=[$t0], $f0=[$t5])
+        EnumerableAggregate(group=[{1}], agg#0=[MIN($0)])
+          EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f0=[$t5], deptno0=[$t0])
             EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
-              EnumerableAggregate(group=[{0}])
-                EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])
-                  EnumerableTableScan(table=[[hr, emps]])
+              EnumerableAggregate(group=[{1}])
+                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)], empid=[$t0], $f0=[$t5], $condition=[$t9])
+    EnumerableAggregate(group=[{1}], agg#0=[MIN($0)])
+      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)], $f0=[$t5], empid=[$t0], $condition=[$t9])
         EnumerableJoin(condition=[true], joinType=[inner])
           EnumerableAggregate(group=[{0}])
-            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], deptno0=[$t0], $f0=[$t5])
-                  EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
-                    EnumerableAggregate(group=[{0}])
-                      EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1])
-                        EnumerableTableScan(table=[[hr, emps]])
-                    EnumerableTableScan(table=[[hr, depts]])
+            EnumerableSemiJoin(condition=[=($1, $6)], joinType=[inner])
+              EnumerableTableScan(table=[[hr, emps]])
+              EnumerableCalc(expr#0..4=[{inputs}], expr#5=[true], $f0=[$t5], deptno0=[$t0])
+                EnumerableJoin(condition=[=($0, $1)], joinType=[inner])
+                  EnumerableAggregate(group=[{1}])
+                    EnumerableTableScan(table=[[hr, emps]])
+                  EnumerableTableScan(table=[[hr, depts]])
           EnumerableTableScan(table=[[hr, depts]])
 !plan
 
@@ -380,12 +375,11 @@ select count(*) as c from "hr"."emps", "hr"."depts";
 
 !ok
 EnumerableAggregate(group=[{}], C=[COUNT()])
-  EnumerableCalc(expr#0..1=[{inputs}], expr#2=[0], DUMMY=[$t2])
-    EnumerableJoin(condition=[true], joinType=[inner])
-      EnumerableCalc(expr#0..3=[{inputs}], expr#4=[0], DUMMY=[$t4])
-        EnumerableTableScan(table=[[hr, depts]])
-      EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], DUMMY=[$t5])
-        EnumerableTableScan(table=[[hr, emps]])
+  EnumerableJoin(condition=[true], joinType=[inner])
+    EnumerableCalc(expr#0..3=[{inputs}], expr#4=[0], DUMMY=[$t4])
+      EnumerableTableScan(table=[[hr, depts]])
+    EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], DUMMY=[$t5])
+      EnumerableTableScan(table=[[hr, emps]])
 !plan
 
 # [CALCITE-345] AssertionError in RexToLixTranslator comparing to date literal

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8276f258/core/src/test/resources/sql/subquery.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/subquery.oq b/core/src/test/resources/sql/subquery.oq
index 409ca4e..db345a5 100644
--- a/core/src/test/resources/sql/subquery.oq
+++ b/core/src/test/resources/sql/subquery.oq
@@ -37,12 +37,11 @@ EnumerableCalc(expr#0..5=[{inputs}], expr#6=[0], expr#7=[=($t1, $t6)],
expr#8=[f
     EnumerableCalc(expr#0..2=[{inputs}], $f0=[$t2], $f1=[$t0], $f2=[$t1], $f3=[$t2])
       EnumerableJoin(condition=[true], joinType=[inner])
         EnumerableAggregate(group=[{}], agg#0=[COUNT()], agg#1=[COUNT($0)])
-          EnumerableCalc(expr#0=[{inputs}], expr#1=[true], proj#0..1=[{exprs}])
-            EnumerableUnion(all=[true])
-              EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
-                EnumerableValues(tuples=[[{ 0 }]])
-              EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null],
expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
-                EnumerableValues(tuples=[[{ 0 }]])
+          EnumerableUnion(all=[true])
+            EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
+              EnumerableValues(tuples=[[{ 0 }]])
+            EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null],
expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
+              EnumerableValues(tuples=[[{ 0 }]])
         EnumerableUnion(all=[true])
           EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
             EnumerableValues(tuples=[[{ 0 }]])


Mime
View raw message