jcamachor commented on a change in pull request #1858: [CALCITE-3862] Rewriting 
for materialized view consisting of group by on join keys with aggregate fails 
(Vineet Garg)
URL: https://github.com/apache/calcite/pull/1858#discussion_r393278519
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewAggregateRule.java
 ##########
 @@ -673,15 +673,22 @@ protected 
MaterializedViewAggregateRule(RelOptRuleOperand operand,
       rewritingMapping = rewritingMappingB.build();
       final ImmutableMultimap<Integer, Integer> inverseMapping = 
rewritingMapping.inverse();
       final List<RexNode> projects = new ArrayList<>();
+
+      final ImmutableBitSet.Builder addedProjects = ImmutableBitSet.builder();
       for (int i = 0; i < queryAggregate.getGroupCount(); i++) {
+        int pos = groupSet.indexOf(inverseMapping.get(i).iterator().next());
+        addedProjects.set(pos);
         projects.add(
             rexBuilder.makeInputRef(result,
                 groupSet.indexOf(inverseMapping.get(i).iterator().next())));
       }
+
+      ImmutableBitSet projs = addedProjects.build();
       // We add aggregate functions that are present in result to projection 
list
-      for (int i = queryAggregate.getGroupCount(); i < 
result.getRowType().getFieldCount(); i++) {
-        projects.add(
-            rexBuilder.makeInputRef(result, i));
+      for (int i = 0; i < result.getRowType().getFieldCount(); i++) {
+        if (projs.indexOf(i) == -1) {
 
 Review comment:
   `projs.indexOf(i) == -1` -> `!projs.get(i)`?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to