You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/12/31 21:15:21 UTC

[2/2] incubator-calcite git commit: Fix indeterminacy in a test

Fix indeterminacy in a test


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

Branch: refs/heads/master
Commit: 0fda7afc84af372553e3fd21e666cc683d456f1f
Parents: 1d9e784
Author: julianhyde <jh...@apache.org>
Authored: Wed Dec 31 11:36:24 2014 -0800
Committer: julianhyde <jh...@apache.org>
Committed: Wed Dec 31 11:36:24 2014 -0800

----------------------------------------------------------------------
 .../org/apache/calcite/runtime/EnumerablesTest.java   |  5 +++--
 .../org/apache/calcite/linq4j/function/Functions.java | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/0fda7afc/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java b/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
index bfbf339..33a2593 100644
--- a/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
+++ b/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
@@ -218,8 +218,9 @@ public class EnumerablesTest {
   @Test public void testThetaFullJoinLeftEmpty() {
     assertThat(
         Enumerables.thetaJoin(EMPS.take(0), DEPTS, EQUAL_DEPTNO,
-            EMP_DEPT_TO_STRING, true, true).toList().toString(),
-        equalTo("[{null, null, 20, Sales}, {null, null, 15, Marketing}]"));
+            EMP_DEPT_TO_STRING, true, true)
+            .orderBy(Functions.<String>identitySelector()).toList().toString(),
+        equalTo("[{null, null, 15, Marketing}, {null, null, 20, Sales}]"));
   }
 
   @Test public void testThetaFullJoinRightEmpty() {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/0fda7afc/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java b/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
index 12b0a18..76e6bb8 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
@@ -83,6 +83,13 @@ public abstract class Functions {
         }
       };
 
+  private static final Function1 TO_STRING_FUNCTION1 =
+      new Function1<Object, String>() {
+        public String apply(Object a0) {
+          return a0.toString();
+        }
+      };
+
   @SuppressWarnings("unchecked")
   private static <K, V> Map<K, V> map(K k, V v, Object... rest) {
     final Map<K, V> map = new HashMap<K, V>();
@@ -171,6 +178,13 @@ public abstract class Functions {
     return (Function1) Function1.IDENTITY;
   }
 
+  /** Returns a selector that calls the {@link Object#toString()} method on
+   * each element. */
+  public static <TSource> Function1<TSource, String> toStringSelector() {
+    //noinspection unchecked
+    return TO_STRING_FUNCTION1;
+  }
+
   /**
    * Creates a predicate that returns whether an object is an instance of a
    * particular type or is null.