@Override
  public void onMatch(RelOptRuleCall call) {
    TableScan scan = call.rel(0);
    String tableName = scan.getTable().getQualifiedName().toString();
    for (RelOptMaterialization cte : call.getPlanner().getMaterializations()) {
      if (tableName.equals(cte.qualifiedTableName.toString())) {
        call.transformTo(cte.queryRel);
      }
    }
  }
Rule that removes CTEs from the plan by expanding the respective TableScans.
<p>The rule assumes that all materializations registered in the planner refer to CTEs.</p>
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/RemoveInfrequentCteRule.java