[ https://issues.apache.org/jira/browse/CALCITE-4783?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17442070#comment-17442070 ]
xzh_dz commented on CALCITE-4783: --------------------------------- The [PR|https://github.com/apache/calcite/pull/2605] not link with JIRA. > 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 > Labels: pull-request-available > Time Spent: 20m > Remaining Estimate: 0h > > {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.20.1#820001)