calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [9/9] git commit: [CALCITE-397] "SELECT DISTINCT *" on reflective schema gives ClassCastException at runtime
Date Tue, 28 Oct 2014 17:50:57 GMT
[CALCITE-397] "SELECT DISTINCT *" on reflective schema gives ClassCastException at runtime


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

Branch: refs/heads/master
Commit: 1f91bbf811d45d5c6832f23ba27972f2e304537b
Parents: 41215c2
Author: Julian Hyde <jhyde@apache.org>
Authored: Sat Oct 25 12:08:33 2014 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Sat Oct 25 12:08:33 2014 -0700

----------------------------------------------------------------------
 .../hydromatic/optiq/rules/java/JavaRowFormat.java  |  6 ++----
 .../net/hydromatic/optiq/rules/java/JavaRules.java  | 12 +++++-------
 .../net/hydromatic/optiq/rules/java/PhysType.java   |  4 ++++
 .../hydromatic/optiq/rules/java/PhysTypeImpl.java   | 16 ++++++++++++++--
 .../java/net/hydromatic/optiq/test/JdbcTest.java    |  8 ++++----
 5 files changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/1f91bbf8/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRowFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRowFormat.java b/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRowFormat.java
index 34cb92d..6773ff3 100644
--- a/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRowFormat.java
+++ b/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRowFormat.java
@@ -187,10 +187,8 @@ public enum JavaRowFormat {
           Object.class, stripCasts(expressions));
     }
 
-    @Override
-    public Expression comparer() {
-      return Expressions.call(
-          null, BuiltinMethod.ARRAY_COMPARER.method);
+    @Override public Expression comparer() {
+      return Expressions.call(BuiltinMethod.ARRAY_COMPARER.method);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/1f91bbf8/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRules.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRules.java b/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRules.java
index f6a4f0d..1384e53 100644
--- a/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRules.java
+++ b/core/src/main/java/net/hydromatic/optiq/rules/java/JavaRules.java
@@ -1338,9 +1338,9 @@ public class JavaRules {
         }
       }
       for (final AggImpState agg : aggs) {
-        results.add(agg.implementor.implementResult(
-            agg.context,
-            new AggResultContextImpl(resultBlock, agg.state)));
+        results.add(
+            agg.implementor.implementResult(agg.context,
+                new AggResultContextImpl(resultBlock, agg.state)));
       }
       resultBlock.add(physType.record(results));
       if (keyArity == 0) {
@@ -1369,7 +1369,7 @@ public class JavaRules {
             Expressions.return_(
                 null,
                 Expressions.call(
-                    childExp,
+                    inputPhysType.convertTo(childExp, physType),
                     BuiltinMethod.DISTINCT.method,
                     Expressions.<Expression>list()
                         .appendIfNotNull(physType.comparer()))));
@@ -1998,9 +1998,7 @@ public class JavaRules {
         final JavaTypeFactory typeFactory =
             (JavaTypeFactory) getCluster().getTypeFactory();
         PhysType physType =
-            PhysTypeImpl.of(
-                typeFactory,
-                table.getRowType(),
+            PhysTypeImpl.of(typeFactory, table.getRowType(),
                 JavaRowFormat.CUSTOM);
         List<Expression> expressionList = new ArrayList<Expression>();
         final PhysType childPhysType = result.physType;

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/1f91bbf8/core/src/main/java/net/hydromatic/optiq/rules/java/PhysType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/rules/java/PhysType.java b/core/src/main/java/net/hydromatic/optiq/rules/java/PhysType.java
index bf97532..51e60a0 100644
--- a/core/src/main/java/net/hydromatic/optiq/rules/java/PhysType.java
+++ b/core/src/main/java/net/hydromatic/optiq/rules/java/PhysType.java
@@ -164,6 +164,10 @@ public interface PhysType {
   /** Returns a copy of this type that allows nulls if {@code nullable} is
    * true. */
   PhysType makeNullable(boolean nullable);
+
+  /** Converts an enumerable of this physical type to an enumerable that uses a
+   * given physical type for its rows. */
+  Expression convertTo(Expression expression, PhysType targetPhysType);
 }
 
 // End PhysType.java

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/1f91bbf8/core/src/main/java/net/hydromatic/optiq/rules/java/PhysTypeImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/rules/java/PhysTypeImpl.java b/core/src/main/java/net/hydromatic/optiq/rules/java/PhysTypeImpl.java
index d307299..e30ce21 100644
--- a/core/src/main/java/net/hydromatic/optiq/rules/java/PhysTypeImpl.java
+++ b/core/src/main/java/net/hydromatic/optiq/rules/java/PhysTypeImpl.java
@@ -29,6 +29,7 @@ import org.eigenbase.reltype.RelDataType;
 import org.eigenbase.reltype.RelDataTypeFactory;
 import org.eigenbase.reltype.RelDataTypeField;
 import org.eigenbase.util.Pair;
+import org.eigenbase.util.Util;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
@@ -130,8 +131,7 @@ public class PhysTypeImpl implements PhysType {
       return Expressions.call(BuiltinMethod.IDENTITY_SELECTOR.method);
     default:
       return Expressions.lambda(Function1.class,
-          targetPhysType.record(fieldReferences(parameter, fields)),
-          parameter);
+          targetPhysType.record(fieldReferences(parameter, fields)), parameter);
     }
   }
 
@@ -178,6 +178,18 @@ public class PhysTypeImpl implements PhysType {
         Primitive.box(javaRowClass), format);
   }
 
+  public Expression convertTo(Expression exp, PhysType targetPhysType) {
+    final JavaRowFormat targetFormat = targetPhysType.getFormat();
+    if (format == targetFormat) {
+      return exp;
+    }
+    final ParameterExpression o_ =
+        Expressions.parameter(javaRowClass, "o");
+    final int fieldCount = rowType.getFieldCount();
+    return Expressions.call(exp, BuiltinMethod.SELECT.method,
+        generateSelector(o_, Util.range(fieldCount), targetFormat));
+  }
+
   public Pair<Expression, Expression> generateCollationKey(
       final List<RelFieldCollation> collations) {
     final Expression selector;

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/1f91bbf8/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java b/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
index c2c09cc..2dca18e 100644
--- a/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
+++ b/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
@@ -2932,16 +2932,16 @@ public class JdbcTest {
   }
 
   /** Test case for
-   * <a href="https://issues.apache.org/jira/browse/CALCITE-397">CALCITE-397</a>,
-   * "SELECT DISTINCT *" gives ClassCastException at runtime". */
-  @Ignore("CALCITE-397")
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-397">[CALCITE-397]
+   * "SELECT DISTINCT *" on reflective schema gives ClassCastException at
+   * runtime</a>. */
   @Test public void testSelectDistinctStar() {
     OptiqAssert.that()
         .with(OptiqAssert.Config.REGULAR)
         .query(
             "select distinct *\n"
             + "from \"hr\".\"emps\"\n")
-        .returnsCount(5)
+        .returnsCount(4)
         .planContains(".distinct(");
   }
 


Mime
View raw message