calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [1/3] incubator-calcite git commit: [CALCITE-582] EnumerableTableScan broken when table has single column
Date Sun, 01 Feb 2015 00:52:22 GMT
Repository: incubator-calcite
Updated Branches:
  refs/heads/branch-1.0 2e502af94 -> 20506d18f (forced update)


[CALCITE-582] EnumerableTableScan broken when table has single column


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

Branch: refs/heads/branch-1.0
Commit: 6c5dd43113a8695a9fd0c12f564e6c87516ca3b9
Parents: 341bdd8
Author: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Authored: Sat Jan 31 00:02:58 2015 +0300
Committer: Julian Hyde <jhyde@apache.org>
Committed: Sat Jan 31 16:37:50 2015 -0800

----------------------------------------------------------------------
 .../adapter/enumerable/EnumerableTableScan.java | 21 +++++++++++++----
 .../calcite/adapter/generate/RangeTable.java    | 24 ++++++++++++++++----
 .../java/org/apache/calcite/test/JdbcTest.java  | 19 +++++++++++++++-
 3 files changed, 53 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/6c5dd431/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
index 641d9cf..bd11411 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java
@@ -31,6 +31,9 @@ import org.apache.calcite.plan.RelOptTable;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.schema.FilterableTable;
+import org.apache.calcite.schema.ProjectableFilterableTable;
+import org.apache.calcite.schema.ScannableTable;
 import org.apache.calcite.util.BuiltInMethod;
 
 import java.lang.reflect.Type;
@@ -82,6 +85,14 @@ public class EnumerableTableScan
   }
 
   private Expression toRows(PhysType physType, Expression expression) {
+    if (physType.getFormat() == JavaRowFormat.SCALAR
+        && Object[].class.isAssignableFrom(elementType)
+        && getRowType().getFieldCount() == 1
+        && (table.unwrap(ScannableTable.class) != null
+            || table.unwrap(FilterableTable.class) != null
+            || table.unwrap(ProjectableFilterableTable.class) != null)) {
+      return Expressions.call(BuiltInMethod.SLICE0.method, expression);
+    }
     JavaRowFormat oldFormat = format();
     if (physType.getFormat() == oldFormat) {
       return expression;
@@ -101,16 +112,16 @@ public class EnumerableTableScan
   }
 
   private JavaRowFormat format() {
+    int fieldCount = getRowType().getFieldCount();
+    if (fieldCount == 0) {
+      return JavaRowFormat.LIST;
+    }
     if (Object[].class.isAssignableFrom(elementType)) {
-      return JavaRowFormat.ARRAY;
+      return fieldCount == 1 ? JavaRowFormat.SCALAR : JavaRowFormat.ARRAY;
     }
     if (Row.class.isAssignableFrom(elementType)) {
       return JavaRowFormat.ROW;
     }
-    int fieldCount = getRowType().getFieldCount();
-    if (fieldCount == 0) {
-      return JavaRowFormat.LIST;
-    }
     if (fieldCount == 1 && (Object.class == elementType
           || Primitive.is(elementType)
           || Number.class.isAssignableFrom(elementType))) {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/6c5dd431/core/src/test/java/org/apache/calcite/adapter/generate/RangeTable.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/adapter/generate/RangeTable.java b/core/src/test/java/org/apache/calcite/adapter/generate/RangeTable.java
index 16109a1..7140b01 100644
--- a/core/src/test/java/org/apache/calcite/adapter/generate/RangeTable.java
+++ b/core/src/test/java/org/apache/calcite/adapter/generate/RangeTable.java
@@ -38,16 +38,18 @@ public class RangeTable extends AbstractQueryableTable {
   private final int start;
   private final int end;
 
-  protected RangeTable(String columnName, int start, int end) {
-    super(Object.class);
+  protected RangeTable(Class<?> elementType, String columnName, int start,
+      int end) {
+    super(elementType);
     this.columnName = columnName;
     this.start = start;
     this.end = end;
   }
 
   /** Creates a RangeTable. */
-  public static RangeTable create(String columnName, int start, int end) {
-    return new RangeTable(columnName, start, end);
+  public static RangeTable create(Class<?> elementType, String columnName,
+      int start, int end) {
+    return new RangeTable(elementType, columnName, start, end);
   }
 
   public RelDataType getRowType(RelDataTypeFactory typeFactory) {
@@ -104,7 +106,19 @@ public class RangeTable extends AbstractQueryableTable {
       final String columnName = (String) operand.get("column");
       final int start = (Integer) operand.get("start");
       final int end = (Integer) operand.get("end");
-      return RangeTable.create(columnName, start, end);
+      final String elementType = (String) operand.get("elementType");
+      Class<?> type;
+      if ("array".equals(elementType)) {
+        type = Object[].class;
+      } else if ("object".equals(elementType)) {
+        type = Object.class;
+      } else if ("integer".equals(elementType)) {
+        type = Integer.class;
+      } else {
+        throw new IllegalArgumentException(
+            "Illegal 'elementType' value: " + elementType);
+      }
+      return RangeTable.create(type, columnName, start, end);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/6c5dd431/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 7bb566e..89c3b47 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -4666,6 +4666,22 @@ public class JdbcTest {
   /** Tests a JDBC connection that provides a model that contains custom
    * tables. */
   @Test public void testModelCustomTable2() {
+    testRangeTable("object");
+  }
+
+  /** Tests a JDBC connection that provides a model that contains custom
+   * tables. */
+  @Test public void testModelCustomTableArrayRowSingleColumn() {
+    testRangeTable("array");
+  }
+
+  /** Tests a JDBC connection that provides a model that contains custom
+   * tables. */
+  @Test public void testModelCustomTableIntegerRowSingleColumn() {
+    testRangeTable("integer");
+  }
+
+  private void testRangeTable(String elementType) {
     CalciteAssert.model("{\n"
         + "  version: '1.0',\n"
         + "   schemas: [\n"
@@ -4677,7 +4693,8 @@ public class JdbcTest {
         + "           type: 'custom',\n"
         + "           factory: '"
         + RangeTable.Factory.class.getName() + "',\n"
-        + "           operand: {'column': 'N', 'start': 3, 'end': 7 }\n"
+        + "           operand: {'column': 'N', 'start': 3, 'end': 7, "
+        + " 'elementType': '" + elementType + "'}\n"
         + "         }\n"
         + "       ]\n"
         + "     }\n"


Mime
View raw message