use of org.apache.calcite.sql2rel.RelFieldTrimmer in project calcite by apache.
the class AbstractSqlTester method assertSqlConvertsTo.
private void assertSqlConvertsTo(SqlTestFactory factory, DiffRepository diffRepos, String sql, String plan, boolean trim, boolean decorrelate) {
String sql2 = diffRepos.expand("sql", sql);
final Pair<SqlValidator, RelRoot> pair = convertSqlToRel2(factory, sql2, decorrelate, trim);
final RelRoot root = requireNonNull(pair.right);
final SqlValidator validator = requireNonNull(pair.left);
RelNode rel = root.project();
assertNotNull(rel);
assertThat(rel, relIsValid());
if (trim) {
final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
final RelFieldTrimmer trimmer = createFieldTrimmer(validator, relBuilder);
rel = trimmer.trim(rel);
assertNotNull(rel);
assertThat(rel, relIsValid());
}
// NOTE jvs 28-Mar-2006: insert leading newline so
// that plans come out nicely stacked instead of first
// line immediately after CDATA start
String actual = NL + RelOptUtil.toString(rel);
diffRepos.assertEquals("plan", plan, actual);
}
use of org.apache.calcite.sql2rel.RelFieldTrimmer in project calcite by apache.
the class RelOptMaterializations method trimUnusedfields.
/**
* Trim unused fields in relational expressions.
*/
private static RelNode trimUnusedfields(RelNode relNode) {
final List<RelOptTable> relOptTables = RelOptUtil.findAllTables(relNode);
RelOptSchema relOptSchema = null;
if (relOptTables.size() != 0) {
relOptSchema = relOptTables.get(0).getRelOptSchema();
}
final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(relNode.getCluster(), relOptSchema);
final RelFieldTrimmer relFieldTrimmer = new RelFieldTrimmer(null, relBuilder);
final RelNode rel = relFieldTrimmer.trim(relNode);
return rel;
}
Aggregations