[ 
https://issues.apache.org/jira/browse/CALCITE-4783?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17418536#comment-17418536
 ] 

Xurenhe commented on CALCITE-4783:
----------------------------------

It seems a bug.

Aggregate of empty group-set drop Filter's condition, when executing 
`RelFieldTrimmer`.
[~xzh_dz] Could you make a pr to fix it? And could ping me to review this pr, 
thanks.

> RelFieldTrimmer incorrectly drops filter condition
> --------------------------------------------------
>
>                 Key: CALCITE-4783
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4783
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: xzh_dz
>            Priority: Major
>
> {code:java}
> // code placeholder
> org.apache.calcite.test.SqlToRelConverterTest
> @Test void testTrim() {
>   final String sql = "select count(*) from emp where ename = '1'";
>   final RelNode rel = tester.convertSqlToRel(sql).rel;
>   final HepProgramBuilder programBuilder = HepProgram.builder();
>   programBuilder.addRuleInstance(CoreRules.FILTER_TO_CALC);
>   final HepPlanner planner = new HepPlanner(programBuilder.build());
>   planner.setRoot(rel);
>   final RelNode calc = planner.findBestExp();
>   final List<RelOptTable> relOptTables = RelOptUtil.findAllTables(calc);
>   RelOptSchema relOptSchema = null;
>   if (relOptTables.size() != 0) {
>     relOptSchema = relOptTables.get(0).getRelOptSchema();
>   }
>   final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(
>       calc.getCluster(), relOptSchema);
>   final RelFieldTrimmer fieldTrimmer = new RelFieldTrimmer(null, relBuilder);
>   final RelNode trimmed = fieldTrimmer.trim(calc);
>   System.out.println(RelOptUtil.toString(trimmed));
> }
> rel:
> LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
>   LogicalProject($f0=[0])
>     LogicalFilter(condition=[=($1, '1')])
>       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> trimmed:
> LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
>   LogicalTableScan(table=[[CATALOG, SALES, EMP]]){code}
>  In this case,RelFieldTrimmer incorrectly drops filter 
> condition.`RelNode(trimmed)` is incorrect,there is no predicate condition 
> `ename = '1'` in final `RelNode(trimmed)`.During Calc operator trim, 
> predicates should not be lost. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to