calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [1/4] calcite git commit: More improvements to RexUtil.simplify
Date Tue, 06 Sep 2016 23:44:27 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 29daa4513 -> 547aa67c2


More improvements to RexUtil.simplify

Use Ordering.sortedCopy rather than sorting lists in-place.

Fix a couple more manifestations of [CALCITE-1283].


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

Branch: refs/heads/master
Commit: 8eca1c9f42d7ee63fa2007d9154b56ab7ab3d9f1
Parents: 29daa45
Author: Julian Hyde <jhyde@apache.org>
Authored: Tue Aug 30 12:03:07 2016 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Tue Sep 6 11:38:58 2016 -0700

----------------------------------------------------------------------
 .../apache/calcite/plan/volcano/RuleQueue.java  | 17 +++----
 .../calcite/plan/volcano/VolcanoPlanner.java    |  8 ++-
 .../calcite/rel/metadata/RelMdPredicates.java   |  2 +-
 .../rel/rules/LoptSemiJoinOptimizer.java        | 16 +++---
 .../java/org/apache/calcite/rex/RexUtil.java    | 41 ++++++++++-----
 .../calcite/sql/type/SqlTypeFactoryImpl.java    |  9 ++--
 .../test/JdbcFrontJdbcBackLinqMiddleTest.java   |  2 +-
 .../java/org/apache/calcite/test/JdbcTest.java  |  2 +-
 .../org/apache/calcite/test/RexProgramTest.java | 53 +++++++++++++++++---
 .../org/apache/calcite/tools/PlannerTest.java   |  6 +--
 .../org/apache/calcite/test/RelOptRulesTest.xml |  6 +--
 .../org/apache/calcite/test/MongoAdapterIT.java |  9 ++--
 .../java/org/apache/calcite/test/Fluent.java    | 12 ++---
 13 files changed, 118 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java b/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
index ddfe14a..dca56a5 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
@@ -28,6 +28,7 @@ import org.apache.calcite.util.trace.CalciteTrace;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Ordering;
 
 import org.slf4j.Logger;
 
@@ -35,7 +36,6 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -100,8 +100,8 @@ class RuleQueue {
   /**
    * Compares relexps according to their cached 'importance'.
    */
-  private final Comparator<RelSubset> relImportanceComparator =
-      new RelImportanceComparator();
+  private final Ordering<RelSubset> relImportanceOrdering =
+      Ordering.from(new RelImportanceComparator());
 
   /**
    * Maps a {@link VolcanoPlannerPhase} to a set of rule names.  Named rules
@@ -413,14 +413,9 @@ class RuleQueue {
   private void dump(PrintWriter pw) {
     planner.dump(pw);
     pw.print("Importances: {");
-    final RelSubset[] subsets =
-        subsetImportances.keySet().toArray(
-            new RelSubset[subsetImportances.keySet().size()]);
-    Arrays.sort(subsets, relImportanceComparator);
-    for (RelSubset subset : subsets) {
-      pw.print(
-          " " + subset.toString() + "="
-          + subsetImportances.get(subset));
+    for (RelSubset subset
+        : relImportanceOrdering.sortedCopy(subsetImportances.keySet())) {
+      pw.print(" " + subset.toString() + "=" + subsetImportances.get(subset));
     }
     pw.println("}");
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/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 45aea2b..9e02adf 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
@@ -87,6 +87,7 @@ import com.google.common.collect.LinkedListMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Ordering;
 import com.google.common.collect.SetMultimap;
 import com.google.common.collect.Sets;
 
@@ -94,7 +95,6 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -1344,9 +1344,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
     pw.println("Original rel:");
     pw.println(originalRootString);
     pw.println("Sets:");
-    RelSet[] sets = allSets.toArray(new RelSet[allSets.size()]);
-    Arrays.sort(
-        sets,
+    Ordering<RelSet> ordering = Ordering.from(
         new Comparator<RelSet>() {
           public int compare(
               RelSet o1,
@@ -1354,7 +1352,7 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
             return o1.id - o2.id;
           }
         });
-    for (RelSet set : sets) {
+    for (RelSet set : ordering.immutableSortedCopy(allSets)) {
       pw.println("Set#" + set.id
           + ", type: " + set.subsets.get(0).getRowType());
       int j = -1;

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
index c416f4c..e8f3790 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
@@ -358,7 +358,7 @@ public class RelMdPredicates
     }
 
     List<RexNode> preds = new ArrayList<>(finalPreds.values());
-    RexNode disjPred = RexUtil.composeDisjunction(rB, finalResidualPreds, false);
+    RexNode disjPred = RexUtil.simplifyOrs(rB, finalResidualPreds);
     if (!disjPred.isAlwaysTrue()) {
       preds.add(disjPred);
     }

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java b/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
index 308091e..c673df7 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/LoptSemiJoinOptimizer.java
@@ -34,11 +34,12 @@ import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Util;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
@@ -78,8 +79,8 @@ public class LoptSemiJoinOptimizer {
    */
   private Map<Integer, Map<Integer, SemiJoin>> possibleSemiJoins;
 
-  private final Comparator<Integer> factorCostComparator =
-      new FactorCostComparator();
+  private final Ordering<Integer> factorCostOrdering =
+      Ordering.from(new FactorCostComparator());
 
   //~ Constructors -----------------------------------------------------------
 
@@ -528,17 +529,14 @@ public class LoptSemiJoinOptimizer {
     // sort the join factors based on the cost of each factor filtered by
     // semijoins, if semijoins have been chosen
     int nJoinFactors = multiJoin.getNumJoinFactors();
-    Integer [] sortedFactors = new Integer[nJoinFactors];
-    for (int i = 0; i < nJoinFactors; i++) {
-      sortedFactors[i] = i;
-    }
-    Arrays.sort(sortedFactors, factorCostComparator);
+    List<Integer> sortedFactors =
+        factorCostOrdering.immutableSortedCopy(Util.range(nJoinFactors));
 
     // loop through the factors in sort order, treating the factor as
     // a fact table; analyze the possible semijoins associated with
     // that fact table
     for (int i = 0; i < nJoinFactors; i++) {
-      Integer factIdx = sortedFactors[i];
+      Integer factIdx = sortedFactors.get(i);
       RelNode factRel = chosenSemiJoins[factIdx];
       Map<Integer, SemiJoin> possibleDimensions =
           possibleSemiJoins.get(factIdx);

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/core/src/main/java/org/apache/calcite/rex/RexUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
index 5f05652..cbb8985 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
@@ -837,23 +837,23 @@ public class RexUtil {
     final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
     final Set<String> digests = Sets.newHashSet(); // to eliminate duplicates
     for (RexNode node : nodes) {
-      if (node != null && digests.add(node.toString())) {
-        addAnd(builder, node);
+      if (node != null) {
+        addAnd(builder, digests, node);
       }
     }
     return builder.build();
   }
 
   private static void addAnd(ImmutableList.Builder<RexNode> builder,
-      RexNode node) {
+      Set<String> digests, RexNode node) {
     switch (node.getKind()) {
     case AND:
       for (RexNode operand : ((RexCall) node).getOperands()) {
-        addAnd(builder, operand);
+        addAnd(builder, digests, operand);
       }
       return;
     default:
-      if (!node.isAlwaysTrue()) {
+      if (!node.isAlwaysTrue() && digests.add(node.toString())) {
         builder.add(node);
       }
     }
@@ -891,23 +891,21 @@ public class RexUtil {
     final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
     final Set<String> digests = Sets.newHashSet(); // to eliminate duplicates
     for (RexNode node : nodes) {
-      if (digests.add(node.toString())) {
-        addOr(builder, node);
-      }
+      addOr(builder, digests, node);
     }
     return builder.build();
   }
 
   private static void addOr(ImmutableList.Builder<RexNode> builder,
-      RexNode node) {
+      Set<String> digests, RexNode node) {
     switch (node.getKind()) {
     case OR:
       for (RexNode operand : ((RexCall) node).getOperands()) {
-        addOr(builder, operand);
+        addOr(builder, digests, operand);
       }
       return;
     default:
-      if (!node.isAlwaysFalse()) {
+      if (!node.isAlwaysFalse() && digests.add(node.toString())) {
         builder.add(node);
       }
     }
@@ -1446,12 +1444,20 @@ public class RexUtil {
     for (RexNode e : nodes) {
       RelOptUtil.decomposeConjunction(e, terms, notTerms);
     }
+    simplifyList(rexBuilder, terms);
+    simplifyList(rexBuilder, notTerms);
     if (unknownAsFalse) {
       return simplifyAnd2ForUnknownAsFalse(rexBuilder, terms, notTerms);
     }
     return simplifyAnd2(rexBuilder, terms, notTerms);
   }
 
+  private static void simplifyList(RexBuilder rexBuilder, List<RexNode> terms) {
+    for (int i = 0; i < terms.size(); i++) {
+      terms.set(i, simplify(rexBuilder, terms.get(i)));
+    }
+  }
+
   private static RexNode simplifyNot(RexBuilder rexBuilder, RexCall call) {
     final RexNode a = call.getOperands().get(0);
     switch (a.getKind()) {
@@ -1716,6 +1722,8 @@ public class RexUtil {
     final List<RexNode> terms = new ArrayList<>();
     final List<RexNode> notTerms = new ArrayList<>();
     RelOptUtil.decomposeConjunction(e, terms, notTerms);
+    simplifyList(rexBuilder, terms);
+    simplifyList(rexBuilder, notTerms);
     if (unknownAsFalse) {
       return simplifyAnd2ForUnknownAsFalse(rexBuilder, terms, notTerms);
     }
@@ -1976,8 +1984,15 @@ public class RexUtil {
   public static RexNode simplifyOr(RexBuilder rexBuilder, RexCall call) {
     assert call.getKind() == SqlKind.OR;
     final List<RexNode> terms = RelOptUtil.disjunctions(call);
+    return simplifyOrs(rexBuilder, terms);
+  }
+
+  /** Simplifies a list of terms and combines them into an OR.
+   * Modifies the list in place. */
+  public static RexNode simplifyOrs(RexBuilder rexBuilder,
+      List<RexNode> terms) {
     for (int i = 0; i < terms.size(); i++) {
-      final RexNode term = terms.get(i);
+      final RexNode term = simplify(rexBuilder, terms.get(i));
       switch (term.getKind()) {
       case LITERAL:
         if (!RexLiteral.isNullLiteral(term)) {
@@ -1986,9 +2001,11 @@ public class RexUtil {
           } else {
             terms.remove(i);
             --i;
+            continue;
           }
         }
       }
+      terms.set(i, term);
     }
     return composeDisjunction(rexBuilder, terms, false);
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java
index 92c3313..4066238 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java
@@ -357,7 +357,8 @@ public class SqlTypeFactoryImpl extends RelDataTypeFactoryImpl {
             RelDataType type1 = types.get(i + 1);
             if (SqlTypeUtil.isDatetime(type1)) {
               resultType = type1;
-              return resultType;
+              return createTypeWithNullability(resultType,
+                  nullCount > 0 || nullableCount > 0);
             }
           }
           if (!type.equals(resultType)) {
@@ -438,7 +439,8 @@ public class SqlTypeFactoryImpl extends RelDataTypeFactoryImpl {
           RelDataType type1 = types.get(i + 1);
           if (SqlTypeUtil.isDatetime(type1)) {
             resultType = type1;
-            return resultType;
+            return createTypeWithNullability(resultType,
+                nullCount > 0 || nullableCount > 0);
           }
         }
 
@@ -463,7 +465,8 @@ public class SqlTypeFactoryImpl extends RelDataTypeFactoryImpl {
           if (SqlTypeUtil.isInterval(type1)
               || SqlTypeUtil.isIntType(type1)) {
             resultType = type;
-            return resultType;
+            return createTypeWithNullability(resultType,
+                nullCount > 0 || nullableCount > 0);
           }
         }
       } else {

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/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 ed09ffb..b08498f 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(
-            "  return left.join(right, new org.apache.calcite.linq4j.function.Function1()
{\n");
+            " left.join(right, new org.apache.calcite.linq4j.function.Function1() {\n");
   }
 }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/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 0c36aaa..76874f0 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -4614,7 +4614,7 @@ public class JdbcTest {
 
   @Test public void testNotExistsCorrelated() {
     final String plan = "PLAN="
-        + "EnumerableCalc(expr#0..5=[{inputs}], expr#6=[IS NOT NULL($t5)], expr#7=[true],
expr#8=[false], expr#9=[CASE($t6, $t7, $t8)], expr#10=[NOT($t9)], proj#0..4=[{exprs}], $condition=[$t10])\n"
+        + "EnumerableCalc(expr#0..5=[{inputs}], expr#6=[IS NULL($t5)], proj#0..4=[{exprs}],
$condition=[$t6])\n"
         + "  EnumerableCorrelate(correlation=[$cor0], joinType=[LEFT], requiredColumns=[{1}])\n"
         + "    EnumerableTableScan(table=[[hr, emps]])\n"
         + "    EnumerableAggregate(group=[{0}])\n"

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
index 75fc8fd..015ddda 100644
--- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
@@ -103,9 +103,28 @@ public class RexProgramTest {
         equalTo(expected));
   }
 
+  /** Simplifies an expression and checks that the result is as expected. */
   private void checkSimplify(RexNode node, String expected) {
+    checkSimplify2(node, expected, expected);
+  }
+
+  /** Simplifies an expression and checks the result if unknowns remain
+   * unknown, or if unknown becomes false. If the result is the same, use
+   * {@link #checkSimplify(RexNode, String)}.
+   *
+   * @param node Expression to simplify
+   * @param expected Expected simplification
+   * @param expectedFalse Expected simplification, if unknown is to be treated
+   *     as false
+   */
+  private void checkSimplify2(RexNode node, String expected,
+      String expectedFalse) {
     assertThat(RexUtil.simplify(rexBuilder, node).toString(),
         equalTo(expected));
+    if (node.getType().getSqlTypeName() == SqlTypeName.BOOLEAN) {
+      assertThat(RexUtil.simplify(rexBuilder, node, true).toString(),
+          equalTo(expectedFalse));
+    }
   }
 
   private void checkSimplifyFilter(RexNode node, String expected) {
@@ -868,9 +887,10 @@ public class RexProgramTest {
         case_(aRef, literal1, bRef, literal1, cRef, literal1, dRef, literal1, literal1),
"1");
 
     // case: trailing false and null, no simplification
-    checkSimplify(
+    checkSimplify2(
         case_(aRef, trueLiteral, bRef, trueLiteral, cRef, falseLiteral, unknownLiteral),
-            "CASE(?0.a, true, ?0.b, true, ?0.c, false, null)");
+        "CASE(?0.a, true, ?0.b, true, ?0.c, false, null)",
+        "CAST(OR(?0.a, ?0.b)):BOOLEAN");
 
     // case: form an AND of branches that return true
     checkSimplify(
@@ -896,14 +916,35 @@ public class RexProgramTest {
         "true");
 
     // condition, and the inverse - nothing to do due to null values
-    checkSimplify(and(le(aRef, literal1), gt(aRef, literal1)),
-        "AND(<=(?0.a, 1), >(?0.a, 1))");
+    checkSimplify2(and(le(aRef, literal1), gt(aRef, literal1)),
+        "AND(<=(?0.a, 1), >(?0.a, 1))",
+        "false");
 
     checkSimplify(and(le(aRef, literal1), ge(aRef, literal1)),
         "AND(<=(?0.a, 1), >=(?0.a, 1))");
 
-    checkSimplify(and(lt(aRef, literal1), eq(aRef, literal1), ge(aRef, literal1)),
-        "AND(<(?0.a, 1), =(?0.a, 1), >=(?0.a, 1))");
+    checkSimplify2(and(lt(aRef, literal1), eq(aRef, literal1), ge(aRef, literal1)),
+        "AND(<(?0.a, 1), =(?0.a, 1), >=(?0.a, 1))",
+        "false");
+
+    checkSimplify(and(lt(aRef, literal1), or(falseLiteral, falseLiteral)),
+        "false");
+    checkSimplify(and(lt(aRef, literal1), or(falseLiteral, gt(bRef, cRef))),
+        "AND(<(?0.a, 1), >(?0.b, ?0.c))");
+    checkSimplify(or(lt(aRef, literal1), and(trueLiteral, trueLiteral)),
+        "true");
+    checkSimplify(
+        or(lt(aRef, literal1),
+            and(trueLiteral, or(trueLiteral, falseLiteral))),
+        "true");
+    checkSimplify(
+        or(lt(aRef, literal1),
+            and(trueLiteral, and(trueLiteral, falseLiteral))),
+        "<(?0.a, 1)");
+    checkSimplify(
+        or(lt(aRef, literal1),
+            and(trueLiteral, or(falseLiteral, falseLiteral))),
+        "<(?0.a, 1)");
   }
 
   @Test public void testSimplifyFilter() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/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 8828801..e70767f 100644
--- a/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
+++ b/core/src/test/java/org/apache/calcite/tools/PlannerTest.java
@@ -300,13 +300,11 @@ public class PlannerTest {
   }
 
   @Test public void testMetadataUnionPredicates3() throws Exception {
-    // The result is [OR(<($1, 10), AND(<($1, 10), >($0, 1)))]
-    // which can be simplified to [<($1, 10)].
     checkMetadataPredicates(
         "select * from \"emps\" where \"deptno\" < 10\n"
             + "union all\n"
             + "select * from \"emps\" where \"deptno\" < 10 and \"empid\" > 1",
-        "[<($1, 10), OR(true, >($0, 1))]");
+        "[<($1, 10)]");
   }
 
   @Test public void testMetadataUnionPredicates4() throws Exception {
@@ -314,7 +312,7 @@ public class PlannerTest {
         "select * from \"emps\" where \"deptno\" < 10\n"
             + "union all\n"
             + "select * from \"emps\" where \"deptno\" < 10 or \"empid\" > 1",
-        "[OR(<($1, 10), <($1, 10), >($0, 1))]");
+        "[OR(<($1, 10), >($0, 1))]");
   }
 
   @Test public void testMetadataUnionPredicates5() throws Exception {

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/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 27816d4..79d7784 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -4596,7 +4596,7 @@ LogicalProject(EMPNO=[$0], DEPTNO=[$7])
             <![CDATA[
 LogicalProject(EMPNO=[$0])
   LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8])
-    LogicalFilter(condition=[OR(CASE(IS NOT NULL($11), true, false), <($5, 100))])
+    LogicalFilter(condition=[OR(IS NOT NULL($11), <($5, 100))])
       LogicalJoin(condition=[AND(=($0, $9), =($7, $10))], joinType=[left])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalAggregate(group=[{0, 1, 2}])
@@ -4662,7 +4662,7 @@ LogicalProject(DEPTNO=[$7])
             <![CDATA[
 LogicalProject(EMPNO=[$0])
   LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8])
-    LogicalFilter(condition=[OR(CASE(IS NOT NULL($10), true, false), <($5, 100))])
+    LogicalFilter(condition=[OR(IS NOT NULL($10), <($5, 100))])
       LogicalJoin(condition=[=($7, $9)], joinType=[left])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalAggregate(group=[{0, 1}])
@@ -4797,7 +4797,7 @@ LogicalFilter(condition=[<($0, 20)])
             <![CDATA[
 LogicalProject(EMPNO=[$0])
   LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8])
-    LogicalFilter(condition=[OR(CASE(IS NOT NULL($9), true, false), <($5, 100))])
+    LogicalFilter(condition=[OR(IS NOT NULL($9), <($5, 100))])
       LogicalJoin(condition=[true], joinType=[left])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalAggregate(group=[{0}])

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
----------------------------------------------------------------------
diff --git a/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java b/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
index 61cea15..25b39ac 100644
--- a/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
+++ b/mongodb/src/test/java/org/apache/calcite/test/MongoAdapterIT.java
@@ -25,6 +25,7 @@ import com.google.common.base.Function;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
 
 import org.hamcrest.CoreMatchers;
 import org.junit.Ignore;
@@ -32,6 +33,7 @@ import org.junit.Test;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -142,8 +144,8 @@ public class MongoAdapterIT {
     return new Function<ResultSet, Void>() {
       public Void apply(ResultSet resultSet) {
         try {
-          final List<String> expectedList = Lists.newArrayList(lines);
-          Collections.sort(expectedList);
+          final List<String> expectedList =
+              Ordering.natural().immutableSortedCopy(Arrays.asList(lines));
 
           final List<String> actualList = Lists.newArrayList();
           CalciteAssert.toStringList(resultSet, actualList);
@@ -154,7 +156,8 @@ public class MongoAdapterIT {
           }
           Collections.sort(actualList);
 
-          assertThat(actualList, equalTo(expectedList));
+          assertThat(Ordering.natural().immutableSortedCopy(actualList),
+              equalTo(expectedList));
           return null;
         } catch (SQLException e) {
           throw new RuntimeException(e);

http://git-wip-us.apache.org/repos/asf/calcite/blob/8eca1c9f/piglet/src/test/java/org/apache/calcite/test/Fluent.java
----------------------------------------------------------------------
diff --git a/piglet/src/test/java/org/apache/calcite/test/Fluent.java b/piglet/src/test/java/org/apache/calcite/test/Fluent.java
index 021f642..cefdab8 100644
--- a/piglet/src/test/java/org/apache/calcite/test/Fluent.java
+++ b/piglet/src/test/java/org/apache/calcite/test/Fluent.java
@@ -25,12 +25,12 @@ import org.apache.calcite.tools.PigRelBuilder;
 import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
-import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
 
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.List;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -69,8 +69,8 @@ class Fluent {
   }
 
   public Fluent returnsUnordered(String... lines) throws ParseException {
-    final List<String> expectedLines = Lists.newArrayList(lines);
-    Collections.sort(expectedLines);
+    final List<String> expectedLines =
+        Ordering.natural().immutableSortedCopy(Arrays.asList(lines));
     return returns(
         new Function<String, Void>() {
           public Void apply(String s) {
@@ -87,8 +87,8 @@ class Fluent {
                 s = s.substring(i + 1);
               }
             }
-            Collections.sort(actualLines);
-            assertThat(actualLines, is(expectedLines));
+            assertThat(Ordering.natural().sortedCopy(actualLines),
+                is(expectedLines));
             return null;
           }
         });


Mime
View raw message