org.apache.calcite.sql2rel.RelFieldTrimmer Java Examples

The following examples show how to use org.apache.calcite.sql2rel.RelFieldTrimmer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 6 votes vote down vote up
public void assertConvertsTo(
    String sql,
    String plan,
    boolean trim) {
  String sql2 = getDiffRepos().expand("sql", sql);
  RelNode rel = convertSqlToRel(sql2).project();

  assertNotNull(rel);
  assertValid(rel);

  if (trim) {
    final RelBuilder relBuilder =
        RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
    final RelFieldTrimmer trimmer = createFieldTrimmer(relBuilder);
    rel = trimmer.trim(rel);
    assertNotNull(rel);
    assertValid(rel);
  }

  // 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);
}
 
Example #2
Source File: Programs.java    From Bats with Apache License 2.0 5 votes vote down vote up
public RelNode run(RelOptPlanner planner, RelNode rel,
    RelTraitSet requiredOutputTraits,
    List<RelOptMaterialization> materializations,
    List<RelOptLattice> lattices) {
  final RelBuilder relBuilder =
      RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
  return new RelFieldTrimmer(null, relBuilder).trim(rel);
}
 
Example #3
Source File: PrelTransformer.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static RelNode trimFields(final RelNode relNode, boolean shouldLog, boolean isRelPlanning) {
  final Stopwatch w = Stopwatch.createStarted();
  final RelFieldTrimmer trimmer = DremioFieldTrimmer.of(relNode.getCluster(), isRelPlanning);
  final RelNode trimmed = trimmer.trim(relNode);
  if(shouldLog) {
    log(PlannerType.HEP, PlannerPhase.FIELD_TRIMMING, trimmed, logger, w);
  }
  return trimmed;
}
 
Example #4
Source File: Programs.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode run(RelOptPlanner planner, RelNode rel,
    RelTraitSet requiredOutputTraits,
    List<RelOptMaterialization> materializations,
    List<RelOptLattice> lattices) {
  final RelBuilder relBuilder =
      RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
  return new RelFieldTrimmer(null, relBuilder).trim(rel);
}
 
Example #5
Source File: RelOptMaterializations.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a RelFieldTrimmer.
 *
 * @param relBuilder Builder
 * @return Field trimmer
 */
public RelFieldTrimmer createFieldTrimmer(RelBuilder relBuilder) {
  return new RelFieldTrimmer(getValidator(), relBuilder);
}