calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [1/3] calcite git commit: [CALCITE-1063] Flat lists for 4, 5, 6 elements
Date Wed, 24 Feb 2016 21:38:32 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 884f01066 -> d14040c52


[CALCITE-1063] Flat lists for 4, 5, 6 elements


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

Branch: refs/heads/master
Commit: 8cba7fc421488cb27ce0756ecd2d422a71f72650
Parents: 884f010
Author: Julian Hyde <jhyde@apache.org>
Authored: Thu Jan 21 12:58:12 2016 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Tue Feb 23 11:50:07 2016 -0800

----------------------------------------------------------------------
 .../adapter/enumerable/JavaRowFormat.java       |  24 +
 .../adapter/enumerable/PhysTypeImpl.java        |  27 +
 .../org/apache/calcite/runtime/FlatLists.java   | 684 ++++++++++++++++++-
 .../org/apache/calcite/util/BuiltInMethod.java  |   6 +
 .../java/org/apache/calcite/util/UtilTest.java  | 106 +++
 5 files changed, 846 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/8cba7fc4/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
index 316af0d..46a4373 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/JavaRowFormat.java
@@ -141,6 +141,30 @@ public enum JavaRowFormat {
                 BuiltInMethod.LIST3.method,
                 expressions),
             List.class);
+      case 4:
+        return Expressions.convert_(
+            Expressions.call(
+                List.class,
+                null,
+                BuiltInMethod.LIST4.method,
+                expressions),
+            List.class);
+      case 5:
+        return Expressions.convert_(
+            Expressions.call(
+                List.class,
+                null,
+                BuiltInMethod.LIST5.method,
+                expressions),
+            List.class);
+      case 6:
+        return Expressions.convert_(
+            Expressions.call(
+                List.class,
+                null,
+                BuiltInMethod.LIST6.method,
+                expressions),
+            List.class);
       default:
         return Expressions.convert_(
             Expressions.call(

http://git-wip-us.apache.org/repos/asf/calcite/blob/8cba7fc4/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 0f83889..f321572 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
@@ -591,6 +591,33 @@ public class PhysTypeImpl implements PhysType {
                 BuiltInMethod.LIST3.method,
                 list),
             v1);
+      case 4:
+        return Expressions.lambda(
+            Function1.class,
+            Expressions.call(
+                List.class,
+                null,
+                BuiltInMethod.LIST4.method,
+                list),
+            v1);
+      case 5:
+        return Expressions.lambda(
+            Function1.class,
+            Expressions.call(
+                List.class,
+                null,
+                BuiltInMethod.LIST5.method,
+                list),
+            v1);
+      case 6:
+        return Expressions.lambda(
+            Function1.class,
+            Expressions.call(
+                List.class,
+                null,
+                BuiltInMethod.LIST6.method,
+                list),
+            v1);
       default:
         return Expressions.lambda(
             Function1.class,

http://git-wip-us.apache.org/repos/asf/calcite/blob/8cba7fc4/core/src/main/java/org/apache/calcite/runtime/FlatLists.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/FlatLists.java b/core/src/main/java/org/apache/calcite/runtime/FlatLists.java
index 64ce699..bf0c4f2 100644
--- a/core/src/main/java/org/apache/calcite/runtime/FlatLists.java
+++ b/core/src/main/java/org/apache/calcite/runtime/FlatLists.java
@@ -38,6 +38,17 @@ public class FlatLists {
   public static final ComparableEmptyList COMPARABLE_EMPTY_LIST =
       new ComparableEmptyList();
 
+  /** Creates a flat list with 0 elements. */
+  public static <T> List<T> of() {
+    //noinspection unchecked
+    return COMPARABLE_EMPTY_LIST;
+  }
+
+  /** Creates a flat list with 1 element. */
+  public static <T> List<T> of(T t0) {
+    return new Flat1List<T>(t0);
+  }
+
   /** Creates a flat list with 2 elements. */
   public static <T> List<T> of(T t0, T t1) {
     return new Flat2List<T>(t0, t1);
@@ -48,6 +59,21 @@ public class FlatLists {
     return new Flat3List<T>(t0, t1, t2);
   }
 
+  /** Creates a flat list with 4 elements. */
+  public static <T> List<T> of(T t0, T t1, T t2, T t3) {
+    return new Flat4List<T>(t0, t1, t2, t3);
+  }
+
+  /** Creates a flat list with 6 elements. */
+  public static <T> List<T> of(T t0, T t1, T t2, T t3, T t4) {
+    return new Flat5List<T>(t0, t1, t2, t3, t4);
+  }
+
+  /** Creates a flat list with 6 elements. */
+  public static <T> List<T> of(T t0, T t1, T t2, T t3, T t4, T t5) {
+    return new Flat6List<T>(t0, t1, t2, t3, t4, t5);
+  }
+
   /**
    * Creates a memory-, CPU- and cache-efficient immutable list.
    *
@@ -122,6 +148,12 @@ public class FlatLists {
       return new Flat2List<T>(t[0], t[1]);
     case 3:
       return new Flat3List<T>(t[0], t[1], t[2]);
+    case 4:
+      return new Flat4List<T>(t[0], t[1], t[2], t[3]);
+    case 5:
+      return new Flat5List<T>(t[0], t[1], t[2], t[3], t[4]);
+    case 6:
+      return new Flat6List<T>(t[0], t[1], t[2], t[3], t[4], t[5]);
     default:
       // REVIEW: AbstractList contains a modCount field; we could
       //   write our own implementation and reduce creation overhead a
@@ -147,11 +179,17 @@ public class FlatLists {
       //noinspection unchecked
       return COMPARABLE_EMPTY_LIST;
     case 1:
-      return Collections.singletonList(t[0]);
+      return new Flat1List<>(t[0]);
     case 2:
       return new Flat2List<>(t[0], t[1]);
     case 3:
       return new Flat3List<>(t[0], t[1], t[2]);
+    case 4:
+      return new Flat4List<>(t[0], t[1], t[2], t[3]);
+    case 5:
+      return new Flat5List<>(t[0], t[1], t[2], t[3], t[4]);
+    case 6:
+      return new Flat6List<>(t[0], t[1], t[2], t[3], t[4], t[5]);
     default:
       return ImmutableNullableList.copyOf(t);
     }
@@ -176,6 +214,13 @@ public class FlatLists {
       return new Flat2List<>(t.get(0), t.get(1));
     case 3:
       return new Flat3List<>(t.get(0), t.get(1), t.get(2));
+    case 4:
+      return new Flat4List<>(t.get(0), t.get(1), t.get(2), t.get(3));
+    case 5:
+      return new Flat5List<>(t.get(0), t.get(1), t.get(2), t.get(3), t.get(4));
+    case 6:
+      return new Flat6List<>(t.get(0), t.get(1), t.get(2), t.get(3), t.get(4),
+          t.get(5));
     default:
       // REVIEW: AbstractList contains a modCount field; we could
       //   write our own implementation and reduce creation overhead a
@@ -268,6 +313,108 @@ public class FlatLists {
   }
 
   /**
+   * List that stores its one elements in the one members of the class.
+   * Unlike {@link java.util.ArrayList} or
+   * {@link java.util.Arrays#asList(Object[])} there is
+   * no array, only one piece of memory allocated, therefore is very compact
+   * and cache and CPU efficient.
+   *
+   * <p>The list is read-only and cannot be modified or re-sized.
+   * The element may be null.
+   *
+   * <p>The list is created via {@link FlatLists#of}.
+   *
+   * @param <T> Element type
+   */
+  protected static class Flat1List<T>
+      extends AbstractFlatList<T>
+      implements ComparableList<T> {
+    private final T t0;
+
+    Flat1List(T t0) {
+      this.t0 = t0;
+    }
+
+    public String toString() {
+      return "[" + t0 + "]";
+    }
+
+    public T get(int index) {
+      switch (index) {
+      case 0:
+        return t0;
+      default:
+        throw new IndexOutOfBoundsException("index " + index);
+      }
+    }
+
+    public int size() {
+      return 1;
+    }
+
+    public Iterator<T> iterator() {
+      return Collections.singletonList(t0).iterator();
+    }
+
+    public boolean equals(Object o) {
+      if (this == o) {
+        return true;
+      }
+      if (o instanceof Flat1List) {
+        Flat1List that = (Flat1List) o;
+        return Objects.equals(this.t0, that.t0);
+      }
+      return Collections.singletonList(t0).equals(o);
+    }
+
+    public int hashCode() {
+      int h = 1;
+      h = h * 31 + Utilities.hash(t0);
+      return h;
+    }
+
+    public int indexOf(Object o) {
+      if (o == null) {
+        if (t0 == null) {
+          return 0;
+        }
+      } else {
+        if (t0.equals(o)) {
+          return 0;
+        }
+      }
+      return -1;
+    }
+
+    public int lastIndexOf(Object o) {
+      if (o == null) {
+        if (t0 == null) {
+          return 0;
+        }
+      } else {
+        if (t0.equals(o)) {
+          return 0;
+        }
+      }
+      return -1;
+    }
+
+    @SuppressWarnings({"unchecked" })
+    public <T2> T2[] toArray(T2[] a) {
+      a[0] = (T2) t0;
+      return a;
+    }
+
+    public Object[] toArray() {
+      return new Object[] {t0};
+    }
+
+    public int compareTo(List o) {
+      return ComparableListImpl.compare((List) this, o);
+    }
+  }
+
+  /**
    * List that stores its two elements in the two members of the class.
    * Unlike {@link java.util.ArrayList} or
    * {@link java.util.Arrays#asList(Object[])} there is
@@ -528,6 +675,541 @@ public class FlatLists {
     }
   }
 
+  /**
+   * List that stores its four elements in the four members of the class.
+   * Unlike {@link java.util.ArrayList} or
+   * {@link java.util.Arrays#asList(Object[])} there is
+   * no array, only one piece of memory allocated, therefore is very compact
+   * and cache and CPU efficient.
+   *
+   * <p>The list is read-only, cannot be modified or re-sized.
+   * The elements may be null.
+   *
+   * <p>The list is created via {@link FlatLists#of(java.util.List)}.
+   *
+   * @param <T> Element type
+   */
+  protected static class Flat4List<T>
+      extends AbstractFlatList<T>
+      implements ComparableList<T> {
+    private final T t0;
+    private final T t1;
+    private final T t2;
+    private final T t3;
+
+    Flat4List(T t0, T t1, T t2, T t3) {
+      this.t0 = t0;
+      this.t1 = t1;
+      this.t2 = t2;
+      this.t3 = t3;
+    }
+
+    public String toString() {
+      return "[" + t0 + ", " + t1 + ", " + t2 + "," + t3 + "]";
+    }
+
+    public T get(int index) {
+      switch (index) {
+      case 0:
+        return t0;
+      case 1:
+        return t1;
+      case 2:
+        return t2;
+      case 3:
+        return t3;
+      default:
+        throw new IndexOutOfBoundsException("index " + index);
+      }
+    }
+
+    public int size() {
+      return 4;
+    }
+
+    public Iterator<T> iterator() {
+      return Arrays.asList(t0, t1, t2, t3).iterator();
+    }
+
+    public boolean equals(Object o) {
+      if (this == o) {
+        return true;
+      }
+      if (o instanceof Flat4List) {
+        Flat4List that = (Flat4List) o;
+        return Objects.equals(this.t0, that.t0)
+            && Objects.equals(this.t1, that.t1)
+            && Objects.equals(this.t2, that.t2)
+            && Objects.equals(this.t3, that.t3);
+      }
+      return o.equals(this);
+    }
+
+    public int hashCode() {
+      int h = 1;
+      h = h * 31 + Utilities.hash(t0);
+      h = h * 31 + Utilities.hash(t1);
+      h = h * 31 + Utilities.hash(t2);
+      h = h * 31 + Utilities.hash(t3);
+      return h;
+    }
+
+    public int indexOf(Object o) {
+      if (o == null) {
+        if (t0 == null) {
+          return 0;
+        }
+        if (t1 == null) {
+          return 1;
+        }
+        if (t2 == null) {
+          return 2;
+        }
+        if (t3 == null) {
+          return 3;
+        }
+      } else {
+        if (t0.equals(o)) {
+          return 0;
+        }
+        if (t1.equals(o)) {
+          return 1;
+        }
+        if (t2.equals(o)) {
+          return 2;
+        }
+        if (t3.equals(o)) {
+          return 3;
+        }
+      }
+      return -1;
+    }
+
+    public int lastIndexOf(Object o) {
+      if (o == null) {
+        if (t3 == null) {
+          return 3;
+        }
+        if (t2 == null) {
+          return 2;
+        }
+        if (t1 == null) {
+          return 1;
+        }
+        if (t0 == null) {
+          return 0;
+        }
+      } else {
+        if (t3.equals(o)) {
+          return 3;
+        }
+        if (t2.equals(o)) {
+          return 2;
+        }
+        if (t1.equals(o)) {
+          return 1;
+        }
+        if (t0.equals(o)) {
+          return 0;
+        }
+      }
+      return -1;
+    }
+
+    @SuppressWarnings({"unchecked" })
+    public <T2> T2[] toArray(T2[] a) {
+      a[0] = (T2) t0;
+      a[1] = (T2) t1;
+      a[2] = (T2) t2;
+      a[3] = (T2) t3;
+      return a;
+    }
+
+    public Object[] toArray() {
+      return new Object[] {t0, t1, t2, t3};
+    }
+
+    public int compareTo(List o) {
+      return ComparableListImpl.compare((List) this, o);
+    }
+  }
+
+  /**
+   * List that stores its five elements in the five members of the class.
+   * Unlike {@link java.util.ArrayList} or
+   * {@link java.util.Arrays#asList(Object[])} there is
+   * no array, only one piece of memory allocated, therefore is very compact
+   * and cache and CPU efficient.
+   *
+   * <p>The list is read-only, cannot be modified or re-sized.
+   * The elements may be null.
+   *
+   * <p>The list is created via {@link FlatLists#of(java.util.List)}.
+   *
+   * @param <T> Element type
+   */
+  protected static class Flat5List<T>
+      extends AbstractFlatList<T>
+      implements ComparableList<T> {
+    private final T t0;
+    private final T t1;
+    private final T t2;
+    private final T t3;
+    private final T t4;
+
+    Flat5List(T t0, T t1, T t2, T t3, T t4) {
+      this.t0 = t0;
+      this.t1 = t1;
+      this.t2 = t2;
+      this.t3 = t3;
+      this.t4 = t4;
+    }
+
+    public String toString() {
+      return "[" + t0 + ", " + t1 + ", " + t2 + "," + t3 + ", " + t4 + "]";
+    }
+
+    public T get(int index) {
+      switch (index) {
+      case 0:
+        return t0;
+      case 1:
+        return t1;
+      case 2:
+        return t2;
+      case 3:
+        return t3;
+      case 4:
+        return t4;
+      default:
+        throw new IndexOutOfBoundsException("index " + index);
+      }
+    }
+
+    public int size() {
+      return 5;
+    }
+
+    public Iterator<T> iterator() {
+      return Arrays.asList(t0, t1, t2, t3, t4).iterator();
+    }
+
+    public boolean equals(Object o) {
+      if (this == o) {
+        return true;
+      }
+      if (o instanceof Flat5List) {
+        Flat5List that = (Flat5List) o;
+        return Objects.equals(this.t0, that.t0)
+            && Objects.equals(this.t1, that.t1)
+            && Objects.equals(this.t2, that.t2)
+            && Objects.equals(this.t3, that.t3)
+            && Objects.equals(this.t4, that.t4);
+      }
+      return o.equals(this);
+    }
+
+    public int hashCode() {
+      int h = 1;
+      h = h * 31 + Utilities.hash(t0);
+      h = h * 31 + Utilities.hash(t1);
+      h = h * 31 + Utilities.hash(t2);
+      h = h * 31 + Utilities.hash(t3);
+      h = h * 31 + Utilities.hash(t4);
+      return h;
+    }
+
+    public int indexOf(Object o) {
+      if (o == null) {
+        if (t0 == null) {
+          return 0;
+        }
+        if (t1 == null) {
+          return 1;
+        }
+        if (t2 == null) {
+          return 2;
+        }
+        if (t3 == null) {
+          return 3;
+        }
+        if (t4 == null) {
+          return 4;
+        }
+      } else {
+        if (t0.equals(o)) {
+          return 0;
+        }
+        if (t1.equals(o)) {
+          return 1;
+        }
+        if (t2.equals(o)) {
+          return 2;
+        }
+        if (t3.equals(o)) {
+          return 3;
+        }
+        if (t4.equals(o)) {
+          return 4;
+        }
+      }
+      return -1;
+    }
+
+    public int lastIndexOf(Object o) {
+      if (o == null) {
+        if (t4 == null) {
+          return 4;
+        }
+        if (t3 == null) {
+          return 3;
+        }
+        if (t2 == null) {
+          return 2;
+        }
+        if (t1 == null) {
+          return 1;
+        }
+        if (t0 == null) {
+          return 0;
+        }
+      } else {
+        if (t4.equals(o)) {
+          return 4;
+        }
+        if (t3.equals(o)) {
+          return 3;
+        }
+        if (t2.equals(o)) {
+          return 2;
+        }
+        if (t1.equals(o)) {
+          return 1;
+        }
+        if (t0.equals(o)) {
+          return 0;
+        }
+      }
+      return -1;
+    }
+
+    @SuppressWarnings({"unchecked" })
+    public <T2> T2[] toArray(T2[] a) {
+      a[0] = (T2) t0;
+      a[1] = (T2) t1;
+      a[2] = (T2) t2;
+      a[3] = (T2) t3;
+      a[4] = (T2) t4;
+      return a;
+    }
+
+    public Object[] toArray() {
+      return new Object[] {t0, t1, t2, t3, t4};
+    }
+
+    public int compareTo(List o) {
+      return ComparableListImpl.compare((List) this, o);
+    }
+  }
+
+  /**
+   * List that stores its six elements in the six members of the class.
+   * Unlike {@link java.util.ArrayList} or
+   * {@link java.util.Arrays#asList(Object[])} there is
+   * no array, only one piece of memory allocated, therefore is very compact
+   * and cache and CPU efficient.
+   *
+   * <p>The list is read-only, cannot be modified or re-sized.
+   * The elements may be null.
+   *
+   * <p>The list is created via {@link FlatLists#of(java.util.List)}.
+   *
+   * @param <T> Element type
+   */
+  protected static class Flat6List<T>
+      extends AbstractFlatList<T>
+      implements ComparableList<T> {
+    private final T t0;
+    private final T t1;
+    private final T t2;
+    private final T t3;
+    private final T t4;
+    private final T t5;
+
+    Flat6List(T t0, T t1, T t2, T t3, T t4, T t5) {
+      this.t0 = t0;
+      this.t1 = t1;
+      this.t2 = t2;
+      this.t3 = t3;
+      this.t4 = t4;
+      this.t5 = t5;
+    }
+
+    public String toString() {
+      return "[" + t0 + ", " + t1 + ", " + t2 + "," + t3 + ", " + t4
+          + ", " + t5 + "]";
+    }
+
+    public T get(int index) {
+      switch (index) {
+      case 0:
+        return t0;
+      case 1:
+        return t1;
+      case 2:
+        return t2;
+      case 3:
+        return t3;
+      case 4:
+        return t4;
+      case 5:
+        return t5;
+      default:
+        throw new IndexOutOfBoundsException("index " + index);
+      }
+    }
+
+    public int size() {
+      return 6;
+    }
+
+    public Iterator<T> iterator() {
+      return Arrays.asList(t0, t1, t2, t3, t4, t5).iterator();
+    }
+
+    public boolean equals(Object o) {
+      if (this == o) {
+        return true;
+      }
+      if (o instanceof Flat6List) {
+        Flat6List that = (Flat6List) o;
+        return Objects.equals(this.t0, that.t0)
+            && Objects.equals(this.t1, that.t1)
+            && Objects.equals(this.t2, that.t2)
+            && Objects.equals(this.t3, that.t3)
+            && Objects.equals(this.t4, that.t4)
+            && Objects.equals(this.t5, that.t5);
+      }
+      return o.equals(this);
+    }
+
+    public int hashCode() {
+      int h = 1;
+      h = h * 31 + Utilities.hash(t0);
+      h = h * 31 + Utilities.hash(t1);
+      h = h * 31 + Utilities.hash(t2);
+      h = h * 31 + Utilities.hash(t3);
+      h = h * 31 + Utilities.hash(t4);
+      h = h * 31 + Utilities.hash(t5);
+      return h;
+    }
+
+    public int indexOf(Object o) {
+      if (o == null) {
+        if (t0 == null) {
+          return 0;
+        }
+        if (t1 == null) {
+          return 1;
+        }
+        if (t2 == null) {
+          return 2;
+        }
+        if (t3 == null) {
+          return 3;
+        }
+        if (t4 == null) {
+          return 4;
+        }
+        if (t5 == null) {
+          return 5;
+        }
+      } else {
+        if (t0.equals(o)) {
+          return 0;
+        }
+        if (t1.equals(o)) {
+          return 1;
+        }
+        if (t2.equals(o)) {
+          return 2;
+        }
+        if (t3.equals(o)) {
+          return 3;
+        }
+        if (t4.equals(o)) {
+          return 4;
+        }
+        if (t5.equals(o)) {
+          return 5;
+        }
+      }
+      return -1;
+    }
+
+    public int lastIndexOf(Object o) {
+      if (o == null) {
+        if (t5 == null) {
+          return 5;
+        }
+        if (t4 == null) {
+          return 4;
+        }
+        if (t3 == null) {
+          return 3;
+        }
+        if (t2 == null) {
+          return 2;
+        }
+        if (t1 == null) {
+          return 1;
+        }
+        if (t0 == null) {
+          return 0;
+        }
+      } else {
+        if (t5.equals(o)) {
+          return 5;
+        }
+        if (t4.equals(o)) {
+          return 4;
+        }
+        if (t3.equals(o)) {
+          return 3;
+        }
+        if (t2.equals(o)) {
+          return 2;
+        }
+        if (t1.equals(o)) {
+          return 1;
+        }
+        if (t0.equals(o)) {
+          return 0;
+        }
+      }
+      return -1;
+    }
+
+    @SuppressWarnings({"unchecked" })
+    public <T2> T2[] toArray(T2[] a) {
+      a[0] = (T2) t0;
+      a[1] = (T2) t1;
+      a[2] = (T2) t2;
+      a[3] = (T2) t3;
+      a[4] = (T2) t4;
+      a[5] = (T2) t5;
+      return a;
+    }
+
+    public Object[] toArray() {
+      return new Object[] {t0, t1, t2, t3, t4, t5};
+    }
+
+    public int compareTo(List o) {
+      return ComparableListImpl.compare((List) this, o);
+    }
+  }
+
   /** Empty list that implements the {@link Comparable} interface. */
   private static class ComparableEmptyList<T>
       extends AbstractList<T>

http://git-wip-us.apache.org/repos/asf/calcite/blob/8cba7fc4/core/src/main/java/org/apache/calcite/util/BuiltInMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/BuiltInMethod.java b/core/src/main/java/org/apache/calcite/util/BuiltInMethod.java
index 9ea40b4..b9924f1 100644
--- a/core/src/main/java/org/apache/calcite/util/BuiltInMethod.java
+++ b/core/src/main/java/org/apache/calcite/util/BuiltInMethod.java
@@ -179,6 +179,12 @@ public enum BuiltInMethod {
   LIST_N(FlatLists.class, "copyOf", Comparable[].class),
   LIST2(FlatLists.class, "of", Object.class, Object.class),
   LIST3(FlatLists.class, "of", Object.class, Object.class, Object.class),
+  LIST4(FlatLists.class, "of", Object.class, Object.class, Object.class,
+      Object.class),
+  LIST5(FlatLists.class, "of", Object.class, Object.class, Object.class,
+      Object.class, Object.class),
+  LIST6(FlatLists.class, "of", Object.class, Object.class, Object.class,
+      Object.class, Object.class, Object.class),
   COMPARABLE_EMPTY_LIST(FlatLists.class, "COMPARABLE_EMPTY_LIST", true),
   IDENTITY_COMPARER(Functions.class, "identityComparer"),
   IDENTITY_SELECTOR(Functions.class, "identitySelector"),

http://git-wip-us.apache.org/repos/asf/calcite/blob/8cba7fc4/core/src/test/java/org/apache/calcite/util/UtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index 42a2d78..5a9d0b7 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -985,6 +985,112 @@ public class UtilTest {
     assertThat(cab.compareTo(anb) > 0, is(true));
   }
 
+  @Test public void testFlatList2() {
+    checkFlatList(0);
+    checkFlatList(1);
+    checkFlatList(2);
+    checkFlatList(3);
+    checkFlatList(4);
+    checkFlatList(5);
+    checkFlatList(6);
+    checkFlatList(7);
+  }
+
+  private void checkFlatList(int n) {
+    final List<String> emp;
+    final List<Object> emp1;
+    final List<String> eNull;
+    switch (n) {
+    case 0:
+      emp = FlatLists.of();
+      emp1 = FlatLists.<Object>copyOf();
+      eNull = null;
+      break;
+    case 1:
+      emp = FlatLists.of("A");
+      emp1 = FlatLists.copyOf((Object) "A");
+      eNull = null;
+      break;
+    case 2:
+      emp = FlatLists.of("A", "B");
+      emp1 = FlatLists.of((Object) "A", "B");
+      eNull = FlatLists.of("A", null);
+      break;
+    case 3:
+      emp = FlatLists.of("A", "B", "C");
+      emp1 = FlatLists.copyOf((Object) "A", "B", "C");
+      eNull = FlatLists.of("A", null, "C");
+      break;
+    case 4:
+      emp = FlatLists.of("A", "B", "C", "D");
+      emp1 = FlatLists.copyOf((Object) "A", "B", "C", "D");
+      eNull = FlatLists.of("A", null, "C", "D");
+      break;
+    case 5:
+      emp = FlatLists.of("A", "B", "C", "D", "E");
+      emp1 = FlatLists.copyOf((Object) "A", "B", "C", "D", "E");
+      eNull = FlatLists.of("A", null, "C", "D", "E");
+      break;
+    case 6:
+      emp = FlatLists.of("A", "B", "C", "D", "E", "F");
+      emp1 = FlatLists.copyOf((Object) "A", "B", "C", "D", "E", "F");
+      eNull = FlatLists.of("A", null, "C", "D", "E", "F");
+      break;
+    case 7:
+      emp = FlatLists.of("A", "B", "C", "D", "E", "F", "G");
+      emp1 = FlatLists.copyOf((Object) "A", "B", "C", "D", "E", "F", "G");
+      eNull = FlatLists.of("A", null, "C", "D", "E", "F", "G");
+      break;
+    default:
+      throw new AssertionError(n);
+    }
+    final List<String> emp0 =
+        Arrays.asList("A", "B", "C", "D", "E", "F", "G").subList(0, n);
+    final List<String> eNull0 =
+        Arrays.asList("A", null, "C", "D", "E", "F", "G").subList(0, n);
+    assertEquals(emp, emp0);
+    assertEquals(emp, emp1);
+    assertEquals(emp0, emp1);
+    assertEquals(emp1, emp0);
+    assertEquals(emp.hashCode(), emp0.hashCode());
+    assertEquals(emp.hashCode(), emp1.hashCode());
+
+    assertThat(emp.size(), is(n));
+    if (eNull != null) {
+      assertThat(eNull.size(), is(n));
+    }
+
+    final List<String> an = FlatLists.of("A", null);
+    final List<String> an0 = Arrays.asList("A", null);
+    assertEquals(an, an0);
+    assertEquals(an.hashCode(), an0.hashCode());
+
+    if (eNull != null) {
+      assertEquals(eNull, eNull0);
+      assertEquals(eNull.hashCode(), eNull0.hashCode());
+    }
+
+    assertThat(emp.toString(), is(emp1.toString()));
+    if (eNull != null) {
+      assertThat(eNull.toString().length(), is(emp1.toString().length() + 3));
+    }
+
+    // Comparisons
+    assertThat(emp, instanceOf(Comparable.class));
+    if (n < 7) {
+      assertThat(emp1, instanceOf(Comparable.class));
+    }
+    if (eNull != null) {
+      assertThat(eNull, instanceOf(Comparable.class));
+    }
+    @SuppressWarnings("unchecked")
+    final Comparable<List> cemp = (Comparable) emp;
+    assertThat(cemp.compareTo(emp), is(0));
+    if (eNull != null) {
+      assertThat(cemp.compareTo(eNull) < 0, is(false));
+    }
+  }
+
   /**
    * Unit test for {@link AvaticaUtils#toCamelCase(String)}.
    */


Mime
View raw message