public boolean isFilter() { return program.getCondition() != null; }
/** * Returns whether this program returns its input exactly. * * <p>This is a stronger condition than {@link #projectsIdentity(boolean)}. */ public boolean isTrivial() { return getCondition() == null && projectsOnlyIdentity(); }
public static Expression translateCondition( RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter) { if (program.getCondition() == null) { return RexImpTable.TRUE_EXPR; } final RexToLixTranslator translator = new RexToLixTranslator(program, typeFactory, inputGetter, list); return translator.translate( program.getCondition(), RexImpTable.NullAs.FALSE); }
public static Expression translateCondition( RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter) { if (program.getCondition() == null) { return RexImpTable.TRUE_EXPR; } final RexToLixTranslator translator = new RexToLixTranslator(program, typeFactory, inputGetter, list); return translator.translate( program.getCondition(), RexImpTable.NullAs.FALSE); }
/** * Returns whether this program returns its input exactly. * * <p>This is a stronger condition than {@link #projectsIdentity(boolean)}. */ public boolean isTrivial() { if (getCondition() != null) { return false; } if (projects.size() != inputRowType.getFieldCount()) { return false; } for (int i = 0; i < projects.size(); i++) { RexLocalRef project = projects.get(i); if (project.index != i) { return false; } } return true; }
public static double estimateFilteredRows(RelNode child, RexProgram program) { // convert the program's RexLocalRef condition to an expanded RexNode RexLocalRef programCondition = program.getCondition(); RexNode condition; if (programCondition == null) { condition = null; } else { condition = program.expandLocalRef(programCondition); } return estimateFilteredRows( child, condition); }
protected RelNode makeRel( RelOptCluster cluster, RelTraitSet traits, RelDataType rowType, RelNode child, RexProgram program) { Util.permAssert( program.getCondition() == null, "WindowedAggregateRel cannot accept a condition"); return WindowRel.create( cluster, traits, child, program, rowType); } }
protected RelNode makeRel( RelOptCluster cluster, RelTraitSet traits, RelDataType rowType, RelNode child, RexProgram program) { Util.permAssert( program.getCondition() == null, "WindowedAggregateRel cannot accept a condition"); return WindowRel.create( cluster, traits, child, program, rowType); } }
/** * Returns whether this tester's <code>RelType</code> can implement a * given program. * * @param program Program * * @return Whether this tester's <code>RelType</code> can implement a * given program. */ public boolean canImplement(RexProgram program) { if ((program.getCondition() != null) && !canImplement(program.getCondition(), true)) { return false; } for (RexNode expr : program.getExprList()) { if (!canImplement(expr, false)) { return false; } } return true; } }
/** * Returns whether this tester's <code>RelType</code> can implement a * given program. * * @param program Program * @return Whether this tester's <code>RelType</code> can implement a * given program. */ public boolean canImplement(RexProgram program) { if ((program.getCondition() != null) && !canImplement(program.getCondition(), true)) { return false; } for (RexNode expr : program.getExprList()) { if (!canImplement(expr, false)) { return false; } } return true; } }
public static double estimateFilteredRows(RelNode child, RexProgram program) { // convert the program's RexLocalRef condition to an expanded RexNode RexLocalRef programCondition = program.getCondition(); RexNode condition; if (programCondition == null) { condition = null; } else { condition = program.expandLocalRef(programCondition); } return estimateFilteredRows( child, condition); }
public boolean isIdentity() { if( program.getCondition() != null || !program.getInputRowType().equals( program.getOutputRowType() ) ) return false; for( int i = 0; i < program.getProjectList().size(); i++ ) { RexLocalRef ref = program.getProjectList().get( i ); if( ref.getIndex() != i ) return false; } return true; } }
/** * Returns whether a program returns a subset of its input fields. Fields * are in the same order, and no input field is output more than once. * There is no condition or non-trivial expressions. */ private static boolean isRetain( RexProgram program, boolean allowRename ) { if( program.getCondition() != null ) return false; if( program.getExprList().size() > program.getInputRowType().getFieldCount() ) return false; final HashSet<Integer> used = new HashSet<Integer>(); for( Pair<RexLocalRef, String> pair : program.getNamedProjects() ) { final int index = pair.left.getIndex(); if( !used.add( index ) ) return false; // field used more than once if( !allowRename && !program.getInputRowType().getFieldNames().get( index ).equals( pair.right ) ) return false; // field projected with different name } return true; }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<RexLocalRef>(); 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 JdbcImplementor.Result implement(JdbcImplementor implementor) { JdbcImplementor.Result x = implementor.visitChild(0, getChild()); final JdbcImplementor.Builder builder = program.getCondition() != null ? x.builder(this, JdbcImplementor.Clause.FROM, JdbcImplementor.Clause.WHERE) : x.builder(this, JdbcImplementor.Clause.FROM); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<SqlNode>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); } }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<RexLocalRef>(); 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 JdbcImplementor.Result implement(JdbcImplementor implementor) { JdbcImplementor.Result x = implementor.visitChild(0, getChild()); final JdbcImplementor.Builder builder = program.getCondition() != null ? x.builder(this, JdbcImplementor.Clause.FROM, JdbcImplementor.Clause.WHERE) : x.builder(this, JdbcImplementor.Clause.FROM); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<SqlNode>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); }
private static RexProgram renameInputs( RexProgram program, RexBuilder rexBuilder, List<String> names ) { final RelDataType inputRowType = program.getInputRowType(); if( inputRowType.getFieldNames().equals( names ) ) return program; final RexProgramBuilder builder = RexProgramBuilder.create( rexBuilder, rexBuilder.getTypeFactory().createStructType( Pair.zip( names, RelOptUtil.getFieldTypeList( inputRowType ) ) ), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(), false ); return builder.getProgram(); }
public void onMatch(RelOptRuleCall call) { FilterRel topFilter = call.rel(0); FilterRel bottomFilter = call.rel(1); // use RexPrograms to merge the two FilterRels into a single program // so we can convert the two FilterRel conditions to directly // reference the bottom FilterRel's child RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder(); RexProgram bottomProgram = createProgram(bottomFilter); RexProgram topProgram = createProgram(topFilter); RexProgram mergedProgram = RexProgramBuilder.mergePrograms( topProgram, bottomProgram, rexBuilder); RexNode newCondition = mergedProgram.expandLocalRef( mergedProgram.getCondition()); FilterRel newFilterRel = new FilterRel( topFilter.getCluster(), bottomFilter.getChild(), newCondition); call.transformTo(newFilterRel); }
public void onMatch(RelOptRuleCall call) { FilterRel topFilter = call.rel(0); FilterRel bottomFilter = call.rel(1); // use RexPrograms to merge the two FilterRels into a single program // so we can convert the two FilterRel conditions to directly // reference the bottom FilterRel's child RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder(); RexProgram bottomProgram = createProgram(bottomFilter); RexProgram topProgram = createProgram(topFilter); RexProgram mergedProgram = RexProgramBuilder.mergePrograms( topProgram, bottomProgram, rexBuilder); RexNode newCondition = mergedProgram.expandLocalRef( mergedProgram.getCondition()); FilterRel newFilterRel = new FilterRel( topFilter.getCluster(), bottomFilter.getChild(), newCondition); call.transformTo(newFilterRel); }