@Override public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) { // keep it for having clause RexBuilder rexBuilder = getCluster().getRexBuilder(); RelDataType inputRowType = getInput().getRowType(); RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder); programBuilder.addIdentity(); programBuilder.addCondition(this.condition); RexProgram program = programBuilder.getProgram(); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // sole(inputs), program); }
public BlockStatement compileToBlock(List<RexNode> nodes, RelDataType inputRowType) { final RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder); for (RexNode node : nodes) { programBuilder.addProject(node, null); } return compileToBlock(programBuilder.getProgram()); }
new RexProgramBuilder(inputRowType, rexBuilder); for (int i = 0; i < projectExprs.size(); i++) { programBuilder.addProject(projectExprs.get(i), fieldNames.get(i)); programBuilder.addCondition(conditionExpr); return programBuilder.getProgram();
new RexProgramBuilder( calc.getRowType(), rexBuilder); for (Pair<RexNode, String> field : project.getNamedProjects()) { progBuilder.addProject(field.left, field.right); RexProgram topProgram = progBuilder.getProgram(); RexProgram bottomProgram = calc.getProgram(); RexProgramBuilder.mergePrograms( topProgram, bottomProgram,
private String compile(RexBuilder rexBuilder, List<RexNode> constExps, RexToLixTranslator.InputGetter getter, RelDataType rowType) { final RexProgramBuilder programBuilder = new RexProgramBuilder(rowType, rexBuilder); for (RexNode node : constExps) { programBuilder.addProject( node, "c" + programBuilder.getProjectList().size()); Expressions.convert_(root0_, DataContext.class))); final SqlConformance conformance = SqlConformanceEnum.DEFAULT; final RexProgram program = programBuilder.getProgram(); final List<Expression> expressions = RexToLixTranslator.translateProjects(program, javaTypeFactory,
RelDataType inputRowType = typeFactory.createStructType(types, names); final RexProgramBuilder builder = new RexProgramBuilder(inputRowType, rexBuilder); final RexLiteral c5 = rexBuilder.makeExactLiteral(BigDecimal.valueOf(5L)); RexLocalRef t2 = builder.addExpr( rexBuilder.makeCall( SqlStdOperatorTable.PLUS, BigDecimal.valueOf(77)); RexLocalRef t3 = builder.addExpr( c77); Util.discard(t3); types.get(1), 1); RexLocalRef t4 = builder.addExpr( rexBuilder.makeCall( SqlStdOperatorTable.PLUS, t5 = builder.addExpr( rexBuilder.makeCall( SqlStdOperatorTable.PLUS, builder.addExpr( rexBuilder.makeCall( SqlStdOperatorTable.PLUS,
Expression predicate(EnumerableRelImplementor implementor, BlockBuilder builder, PhysType leftPhysType, PhysType rightPhysType, RexNode condition) { final ParameterExpression left_ = Expressions.parameter(leftPhysType.getJavaRowType(), "left"); final ParameterExpression right_ = Expressions.parameter(rightPhysType.getJavaRowType(), "right"); final RexProgramBuilder program = new RexProgramBuilder( implementor.getTypeFactory().builder() .addAll(left.getRowType().getFieldList()) .addAll(right.getRowType().getFieldList()) .build(), getCluster().getRexBuilder()); program.addCondition(condition); builder.add( Expressions.return_(null, RexToLixTranslator.translateCondition(program.getProgram(), implementor.getTypeFactory(), builder, new RexToLixTranslator.InputGetterImpl( ImmutableList.of(Pair.of((Expression) left_, leftPhysType), Pair.of((Expression) right_, rightPhysType))), implementor.allCorrelateVariables, implementor.getConformance()))); return Expressions.lambda(Predicate2.class, builder.toBlock(), left_, right_); } }
/** * Converts the state of the program builder to an immutable program, * normalizing in the process. * * <p>It is OK to call this method, modify the program specification (by * adding projections, and so forth), and call this method again. */ public RexProgram getProgram() { return getProgram(true); }
addProject(ref.getIndex(), name); addCondition(ref); boolean normalize, RexSimplify simplify) { return new RexProgramBuilder(rexBuilder, inputRowType, exprList, projectList, condition, outputRowType, normalize, simplify); final boolean updateRefs) { final RexProgramBuilder progBuilder = new RexProgramBuilder(inputRowType, rexBuilder); progBuilder.add( exprList, projectRefList,
assert topProgram.isValid(Litmus.THROW, null); final RexProgramBuilder progBuilder = RexProgramBuilder.forProgram(bottomProgram, rexBuilder, false); progBuilder.registerProjectsAndCondition(topProgram); progBuilder.clearProjects(); final RelDataType outputRowType = topProgram.getOutputRowType(); for (Pair<RexLocalRef, String> pair : Pair.zip(projectRefList, outputRowType.getFieldNames(), true)) { progBuilder.addProject(pair.left, pair.right); RexProgram mergedProg = progBuilder.getProgram(normalize); assert mergedProg.isValid(Litmus.THROW, null); assert mergedProg.getOutputRowType() == topProgram.getOutputRowType();
/** * Creates a simplified/normalized copy of this program. * * @param rexBuilder Rex builder * @param simplify Simplifier to simplify (in addition to normalizing), * or null to not simplify * @return Normalized program */ public RexProgram normalize(RexBuilder rexBuilder, RexSimplify simplify) { // Normalize program by creating program builder from the program, then // converting to a program. getProgram does not need to normalize // because the builder was normalized on creation. assert isValid(Litmus.THROW, null); final RexProgramBuilder builder = RexProgramBuilder.create(rexBuilder, inputRowType, exprs, projects, condition, outputRowType, true, simplify); return builder.getProgram(false); }
generateMissingNames(); RelDataType outputRowType = computeOutputRowType(); return create( rexBuilder, inputRowType, outputRowType, true) .getProgram(false);
@Deprecated // to be removed before 2.0 public static RexProgramBuilder create( RexBuilder rexBuilder, final RelDataType inputRowType, final List<RexNode> exprList, final List<? extends RexNode> projectList, final RexNode condition, final RelDataType outputRowType, boolean normalize, boolean simplify_) { RexSimplify simplify = null; if (simplify_) { simplify = new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, RexUtil.EXECUTOR); } return new RexProgramBuilder(rexBuilder, inputRowType, exprList, projectList, condition, outputRowType, normalize, simplify); }
/** * Adds a projection based upon the <code>index</code>th expression at a * given position. * * @param at Position in project list to add expression * @param ordinal Index of expression to project * @param name Name of field in output row type; if null, a unique name * will be generated when the program is created * @return the ref created */ public RexLocalRef addProject(int at, int ordinal, final String name) { return addProject( at, localRefList.get(ordinal), name); }
/** * Adds a project expression to the program. * * <p>The expression specified in terms of the input fields. If not, call * {@link #registerOutput(RexNode)} first. * * @param expr Expression to add * @param name Name of field in output row type; if null, a unique name will * be generated when the program is created * @return the ref created */ public RexLocalRef addProject(RexNode expr, String name) { final RexLocalRef ref = registerInput(expr); return addProject(ref.getIndex(), name); }
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; }
/** * Merges two programs together, and normalizes the result. * * @param topProgram Top program. Its expressions are in terms of the * outputs of the bottom program. * @param bottomProgram Bottom program. Its expressions are in terms of the * result fields of the relational expression's input * @param rexBuilder Rex builder * @return Merged program * @see #mergePrograms(RexProgram, RexProgram, RexBuilder, boolean) */ public static RexProgram mergePrograms( RexProgram topProgram, RexProgram bottomProgram, RexBuilder rexBuilder) { return mergePrograms(topProgram, bottomProgram, rexBuilder, true); }
addCondition(conditionRef);
new RexProgramBuilder(inputRowType, rexBuilder); for (int i = 0; i < projectExprs.size(); i++) { programBuilder.addProject(projectExprs.get(i), fieldNames.get(i)); programBuilder.addCondition(conditionExpr); return programBuilder.getProgram();