List<RexLocalRef> projectList = program.getProjectList(); if (projectList != null && !projectList.isEmpty()) { List<RexNode> expandedNodes = new ArrayList<>();
public static boolean isStar(RexProgram program) { int i = 0; for (RexLocalRef ref : program.getProjectList()) { if (ref.getIndex() != i++) { return false; } } return i == program.getInputRowType().getFieldCount(); }
public static boolean isStar(RexProgram program) { int i = 0; for (RexLocalRef ref : program.getProjectList()) { if (ref.getIndex() != i++) { return false; } } return i == program.getInputRowType().getFieldCount(); }
private static boolean isStar(RexProgram program) { int i = 0; for (RexLocalRef ref : program.getProjectList()) { if (ref.getIndex() != i++) { return false; } } return i == program.getInputRowType().getFieldCount(); } }
private static boolean isStar(RexProgram program) { int i = 0; for (RexLocalRef ref : program.getProjectList()) { if (ref.getIndex() != i++) { return false; } } return i == program.getInputRowType().getFieldCount(); }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<>(); final RexShuttle shuttle = new RegisterOutputShuttle(exprList); // For each project, lookup the expr and expand it so it is in terms of // bottomCalc's input fields for (RexLocalRef topProject : program.getProjectList()) { final RexNode topExpr = exprList.get(topProject.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); // Remember the expr, but don't add to the project list yet. projectRefList.add(expanded); } // Similarly for the condition. final RexLocalRef topCondition = program.getCondition(); if (topCondition != null) { final RexNode topExpr = exprList.get(topCondition.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); addCondition(registerInput(expanded)); } return projectRefList; }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<>(); final RexShuttle shuttle = new RegisterOutputShuttle(exprList); // For each project, lookup the expr and expand it so it is in terms of // bottomCalc's input fields for (RexLocalRef topProject : program.getProjectList()) { final RexNode topExpr = exprList.get(topProject.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); // Remember the expr, but don't add to the project list yet. projectRefList.add(expanded); } // Similarly for the condition. final RexLocalRef topCondition = program.getCondition(); if (topCondition != null) { final RexNode topExpr = exprList.get(topCondition.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); addCondition(registerInput(expanded)); } return projectRefList; }
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final Calc calc = call.rel(1); final RexProgram program = calc.getProgram(); final List<RexNode> projects = new ArrayList<>(); for (RexLocalRef localRef : program.getProjectList()) { projects.add(program.expandLocalRef(localRef)); } final Project project = LogicalProject.create(calc.getInput(), projects, calc.getRowType()); RelNode x = AggregateProjectMergeRule.apply(call, aggregate, project); if (x != null) { call.transformTo(x); } } }
public RexProgram copyOf(RexProgram program) { return new RexProgram( copyOf(program.getInputRowType()), copyRexNodes(program.getExprList()), Lists.transform(program.getProjectList(), COPY_REX_LOCAL_REF), (RexLocalRef) copyOf(program.getCondition()), copyOf(program.getOutputRowType()) ); }
null, null) .setCorrelates(correlates) .translateList(program.getProjectList(), storageTypes);
assert program.isValid(Litmus.THROW, null); final RelDataType inputRowType = program.getInputRowType(); final List<RexLocalRef> projectRefs = program.getProjectList(); final RexLocalRef conditionRef = program.getCondition(); final List<RexNode> exprs = program.getExprList();
@Override protected RelNode handle(RelNode rel) { if (!(rel instanceof LogicalCalc)) { return rel; } final LogicalCalc calc = (LogicalCalc) rel; final RexProgram program = calc.getProgram(); relBuilder.push(calc.getInput()); if (program.getCondition() != null) { relBuilder.filter( program.expandLocalRef(program.getCondition())); } if (!program.projectsOnlyIdentity()) { relBuilder.project( Lists.transform(program.getProjectList(), program::expandLocalRef), calc.getRowType().getFieldNames()); } return relBuilder.build(); } };
@Override protected RelNode handle(RelNode rel) { if (!(rel instanceof LogicalCalc)) { return rel; } final LogicalCalc calc = (LogicalCalc) rel; final RexProgram program = calc.getProgram(); relBuilder.push(calc.getInput()); if (program.getCondition() != null) { relBuilder.filter( program.expandLocalRef(program.getCondition())); } if (!program.projectsOnlyIdentity()) { relBuilder.project( Lists.transform(program.getProjectList(), program::expandLocalRef), calc.getRowType().getFieldNames()); } return relBuilder.build(); } };
public RelNode accept(RexShuttle shuttle) { List<RexNode> oldExprs = program.getExprList(); List<RexNode> exprs = shuttle.apply(oldExprs); List<RexLocalRef> oldProjects = program.getProjectList(); List<RexLocalRef> projects = shuttle.apply(oldProjects); RexLocalRef oldCondition = program.getCondition(); RexNode condition; if (oldCondition != null) { condition = shuttle.apply(oldCondition); assert condition instanceof RexLocalRef : "Invalid condition after rewrite. Expected RexLocalRef, got " + condition; } else { condition = null; } if (exprs == oldExprs && projects == oldProjects && condition == oldCondition) { return this; } return copy(traitSet, getInput(), new RexProgram(program.getInputRowType(), exprs, projects, (RexLocalRef) condition, program.getOutputRowType())); } }
public RelNode accept(RexShuttle shuttle) { List<RexNode> oldExprs = program.getExprList(); List<RexNode> exprs = shuttle.apply(oldExprs); List<RexLocalRef> oldProjects = program.getProjectList(); List<RexLocalRef> projects = shuttle.apply(oldProjects); RexLocalRef oldCondition = program.getCondition(); RexNode condition; if (oldCondition != null) { condition = shuttle.apply(oldCondition); assert condition instanceof RexLocalRef : "Invalid condition after rewrite. Expected RexLocalRef, got " + condition; } else { condition = null; } if (exprs == oldExprs && projects == oldProjects && condition == oldCondition) { return this; } return copy(traitSet, getInput(), new RexProgram(program.getInputRowType(), exprs, projects, (RexLocalRef) condition, program.getOutputRowType())); } }
public Result visitCalc(Calc e) { Result x = visitChild(0, e.getInput()); final RexProgram program = e.getProgram(); Builder builder = program.getCondition() != null ? x.builder(e, Clause.WHERE) : x.builder(e); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, e.getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); }
/** @see #dispatch */ public Result visit(Calc e) { Result x = visitChild(0, e.getInput()); parseCorrelTable(e, x); final RexProgram program = e.getProgram(); Builder builder = program.getCondition() != null ? x.builder(e, Clause.WHERE) : x.builder(e); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, e.getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); }
/** @see #dispatch */ public Result visit(Calc e) { Result x = visitChild(0, e.getInput()); parseCorrelTable(e, x); final RexProgram program = e.getProgram(); Builder builder = program.getCondition() != null ? x.builder(e, Clause.WHERE) : x.builder(e); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, e.getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); }
public void onMatch(RelOptRuleCall call) { LogicalCalc calc = call.rel(0); // Expand decimals in every expression in this program. If no // expression changes, don't apply the rule. final RexProgram program = calc.getProgram(); if (!RexUtil.requiresDecimalExpansion(program, true)) { return; } final RexBuilder rexBuilder = calc.getCluster().getRexBuilder(); final RexShuttle shuttle = new DecimalShuttle(rexBuilder); RexProgramBuilder programBuilder = RexProgramBuilder.create( rexBuilder, calc.getInput().getRowType(), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(), shuttle, true); final RexProgram newProgram = programBuilder.getProgram(); LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram); call.transformTo(newCalc); }
public void onMatch(RelOptRuleCall call) { LogicalCalc calc = call.rel(0); // Expand decimals in every expression in this program. If no // expression changes, don't apply the rule. final RexProgram program = calc.getProgram(); if (!RexUtil.requiresDecimalExpansion(program, true)) { return; } final RexBuilder rexBuilder = calc.getCluster().getRexBuilder(); final RexShuttle shuttle = new DecimalShuttle(rexBuilder); RexProgramBuilder programBuilder = RexProgramBuilder.create( rexBuilder, calc.getInput().getRowType(), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(), shuttle, true); final RexProgram newProgram = programBuilder.getProgram(); LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram); call.transformTo(newCalc); }