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/18 21:55:50 UTC

incubator-calcite git commit: [CALCITE-542] Support for Aggregate with grouping sets in RelMdColumnOrigins (Jesus Camacho Rodriguez)

Repository: incubator-calcite
Updated Branches:
  refs/heads/master 6f83773a8 -> 4e95a8ca3


[CALCITE-542] Support for Aggregate with grouping sets in RelMdColumnOrigins (Jesus Camacho Rodriguez)

Close apache/incubator-calcite#36


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

Branch: refs/heads/master
Commit: 4e95a8ca3ec412943c87c17c73af97d3db5e37ab
Parents: 6f83773
Author: Jesus Camacho Rodriguez <jc...@hortonworks.com>
Authored: Thu Dec 18 11:48:35 2014 +0100
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Dec 18 11:24:24 2014 -0800

----------------------------------------------------------------------
 .../rel/metadata/RelMdColumnOrigins.java        | 12 ++-
 .../org/apache/calcite/test/CalciteSuite.java   |  1 +
 .../calcite/test/RelMdColumnOriginsTest.java    | 79 ++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/4e95a8ca/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java
index d821744..597bba8 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnOrigins.java
@@ -32,6 +32,8 @@ import org.apache.calcite.rex.RexVisitor;
 import org.apache.calcite.rex.RexVisitorImpl;
 import org.apache.calcite.util.BuiltInMethod;
 
+import com.google.common.collect.ImmutableSet;
+
 import java.util.HashSet;
 import java.util.Set;
 
@@ -60,9 +62,17 @@ public class RelMdColumnOrigins {
           iOutputColumn);
     }
 
+    if (rel.indicator) {
+      if (iOutputColumn < rel.getGroupCount() + rel.getIndicatorCount()) {
+        // The indicator column is originated here.
+        return ImmutableSet.of();
+      }
+    }
+
     // Aggregate columns are derived from input columns
     AggregateCall call =
-        rel.getAggCallList().get(iOutputColumn - rel.getGroupCount());
+        rel.getAggCallList().get(iOutputColumn
+                - rel.getGroupCount() - rel.getIndicatorCount());
 
     Set<RelColumnOrigin> set = new HashSet<RelColumnOrigin>();
     for (Integer iInput : call.getArgList()) {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/4e95a8ca/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteSuite.java b/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
index aeeb360..bedd425 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
@@ -116,6 +116,7 @@ import org.junit.runners.Suite;
 
     // test cases
     TableInRootSchemaTest.class,
+    RelMdColumnOriginsTest.class,
     MultiJdbcSchemaJoinTest.class,
 
     // slow tests that don't break often

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/4e95a8ca/core/src/test/java/org/apache/calcite/test/RelMdColumnOriginsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelMdColumnOriginsTest.java b/core/src/test/java/org/apache/calcite/test/RelMdColumnOriginsTest.java
new file mode 100644
index 0000000..a3f7f10
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/test/RelMdColumnOriginsTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+import org.apache.calcite.jdbc.CalciteConnection;
+
+import com.google.common.collect.ImmutableMultiset;
+
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+/** Test case for CALCITE-542. */
+public class RelMdColumnOriginsTest {
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-542">[CALCITE-542]
+   * Support for Aggregate with grouping sets in RelMdColumnOrigins</a>. */
+  @Test public void testQueryWithAggregateGroupingSets() throws Exception {
+    Connection connection = DriverManager.getConnection("jdbc:calcite:");
+    CalciteConnection calciteConnection =
+        connection.unwrap(CalciteConnection.class);
+
+    calciteConnection.getRootSchema().add("T1",
+        new TableInRootSchemaTest.SimpleTable());
+    Statement statement = calciteConnection.createStatement();
+    ResultSet resultSet =
+        statement.executeQuery("SELECT TABLE1.ID, TABLE2.ID FROM "
+                + "(SELECT GROUPING(A) AS ID FROM T1 "
+                + "GROUP BY ROLLUP(A,B)) TABLE1 "
+                + "JOIN "
+                + "(SELECT GROUPING(A) AS ID FROM T1 "
+                + "GROUP BY ROLLUP(A,B)) TABLE2 "
+                + "ON TABLE1.ID = TABLE2.ID");
+
+    final String result1 = "ID=0; ID=0";
+    final String result2 = "ID=1; ID=1";
+    final ImmutableMultiset<String> expectedResult =
+        ImmutableMultiset.<String>builder()
+            .addCopies(result1, 25)
+            .add(result2)
+            .build();
+    assertThat(CalciteAssert.toSet(resultSet), equalTo(expectedResult));
+
+    final ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+    assertThat(resultSetMetaData.getColumnName(1), equalTo("ID"));
+    assertThat(resultSetMetaData.getTableName(1), nullValue());
+    assertThat(resultSetMetaData.getSchemaName(1), nullValue());
+    assertThat(resultSetMetaData.getColumnName(2), equalTo("ID"));
+    assertThat(resultSetMetaData.getTableName(2), nullValue());
+    assertThat(resultSetMetaData.getSchemaName(2), nullValue());
+    resultSet.close();
+    statement.close();
+    connection.close();
+  }
+}
+
+// End RelMdColumnOriginsTest.java