use of org.apache.calcite.rex.RexProgramBuilder in project calcite by apache.
the class RelStructuredTypeFlattener method rewriteRel.
public void rewriteRel(LogicalCalc rel) {
// Translate the child.
final RelNode newInput = getNewForOldRel(rel.getInput());
final RelOptCluster cluster = rel.getCluster();
RexProgramBuilder programBuilder = new RexProgramBuilder(newInput.getRowType(), cluster.getRexBuilder());
// Convert the common expressions.
final RexProgram program = rel.getProgram();
final RewriteRexShuttle shuttle = new RewriteRexShuttle();
for (RexNode expr : program.getExprList()) {
programBuilder.registerInput(expr.accept(shuttle));
}
// Convert the projections.
final List<Pair<RexNode, String>> flattenedExpList = Lists.newArrayList();
List<String> fieldNames = rel.getRowType().getFieldNames();
flattenProjections(new RewriteRexShuttle(), program.getProjectList(), fieldNames, "", flattenedExpList);
// Register each of the new projections.
for (Pair<RexNode, String> flattenedExp : flattenedExpList) {
programBuilder.addProject(flattenedExp.left, flattenedExp.right);
}
// Translate the condition.
final RexLocalRef conditionRef = program.getCondition();
if (conditionRef != null) {
programBuilder.addCondition(new RexLocalRef(getNewForOldInput(conditionRef.getIndex()), conditionRef.getType()));
}
RexProgram newProgram = programBuilder.getProgram();
// Create a new calc relational expression.
LogicalCalc newRel = LogicalCalc.create(newInput, newProgram);
setNewForOldRel(rel, newRel);
}
use of org.apache.calcite.rex.RexProgramBuilder in project drill by apache.
the class DrillMergeFilterRule method createProgram.
/**
* Creates a RexProgram corresponding to a LogicalFilter
*
* @param filterRel the LogicalFilter
* @return created RexProgram
*/
private RexProgram createProgram(Filter filterRel) {
RexProgramBuilder programBuilder = new RexProgramBuilder(filterRel.getRowType(), filterRel.getCluster().getRexBuilder());
programBuilder.addIdentity();
programBuilder.addCondition(filterRel.getCondition());
return programBuilder.getProgram();
}
Aggregations