Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
// 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]])
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.
Attachments
Issue Links
- links to