eolivelli commented on a change in pull request #1355: [CALCITE-3228] Error 
while applying rule ProjectScanRule: interpreter
URL: https://github.com/apache/calcite/pull/1355#discussion_r315048360
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
 ##########
 @@ -292,6 +293,43 @@ private void checkTypeSystem(final int expected, 
FrameworkConfig config) {
         });
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-3228";>[CALCITE-3228]
+   * Error while applying rule ProjectScanRule:interpreter</a>
+   *
+   * <p>This bug appears under the following conditions:
+   * 1) have an aggregate with group by and multi aggregate calls.
+   * 2) the aggregate can be removed during optimization.
+   * 3) all aggregate calls are simplified to the same reference.
+   * */
+  @Test public void testPushProjectToScan() throws Exception {
+    Table table = new TableImpl();
+    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+    SchemaPlus schema = rootSchema.add("x", new AbstractSchema());
+    schema.add("MYTABLE", table);
+    List<RelTraitDef> traitDefs = new ArrayList<>();
+    traitDefs.add(ConventionTraitDef.INSTANCE);
+    traitDefs.add(RelDistributionTraitDef.INSTANCE);
+    SqlParser.Config parserConfig =
+            SqlParser.configBuilder(SqlParser.Config.DEFAULT)
+                    .setCaseSensitive(false)
+                    .build();
+
+    final FrameworkConfig config = Frameworks.newConfigBuilder()
+            .parserConfig(parserConfig)
+            .defaultSchema(schema)
+            .traitDefs(traitDefs)
+            // define the rules you want to apply
+            .ruleSets(
+                    
RuleSets.ofList(AbstractConverter.ExpandConversionRule.INSTANCE,
+                            ProjectTableScanRule.INSTANCE))
+            .programs(Programs.ofRules(Programs.RULE_SET))
+            .build();
+
+    executeQuery(config, "select min(id) as mi, max(id) as ma from mytable 
where id=1 group by id",
 
 Review comment:
   Here you are using only the 'id' field, that is the same field you are using 
as filter and for the 'group by'
   
   Real cases are more like:
   Select min(table1.a), max(table1.a), count(*)  from table1
   Join table2 on (...)
   Group by table2.field

----------------------------------------------------------------
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