You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/07/27 02:25:26 UTC

[GitHub] [calcite] NobiGo commented on a change in pull request #2458: [CALCITE-4665] When group key contains unused bits RelNode generate wrong SQL(NobiGo)

NobiGo commented on a change in pull request #2458:
URL: https://github.com/apache/calcite/pull/2458#discussion_r677069953



##########
File path: core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
##########
@@ -504,12 +518,16 @@ protected Builder buildAggregate(Aggregate e, Builder builder,
           SqlStdOperatorTable.ROLLUP.createCall(SqlParserPos.ZERO, groupKeys));
     default:
     case OTHER:
+      List<SqlNode> groupingSetsList = aggregate.getGroupSets().stream()
+          .map(groupSet -> groupItem(groupKeys, groupSet, aggregate.getGroupSet()))
+          .collect(Collectors.toList());
+      if (ImmutableBitSet.union(aggregate.getGroupSets()).cardinality()
+          != aggregate.getGroupSet().cardinality()) {
+        groupingSetsList.add(

Review comment:
       done

##########
File path: core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
##########
@@ -1692,6 +1692,40 @@ private RelNode buildRelWithDuplicateAggregates(
     assertThat(root, hasTree(expected));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4665">[CALCITE-4665]
+   * groupKeys contain unused column.</a>. */
+  @Test void testGroupingSetWithGroupKeysContainUnusedColumn() {

Review comment:
       done

##########
File path: core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
##########
@@ -504,12 +518,16 @@ protected Builder buildAggregate(Aggregate e, Builder builder,
           SqlStdOperatorTable.ROLLUP.createCall(SqlParserPos.ZERO, groupKeys));
     default:
     case OTHER:
+      List<SqlNode> groupingSetsList = aggregate.getGroupSets().stream()
+          .map(groupSet -> groupItem(groupKeys, groupSet, aggregate.getGroupSet()))
+          .collect(Collectors.toList());
+      if (ImmutableBitSet.union(aggregate.getGroupSets()).cardinality()
+          != aggregate.getGroupSet().cardinality()) {

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org