/** * Returns whether a program contains a multiset. */ public static boolean containsMultiset(RexProgram program) { final boolean deep = true; for (RexNode expr : program.getExprList()) { if (containsMultiset(expr, deep)) { return true; } } return false; }
/** * Returns whether a program contains an OVER clause. */ public static boolean containsOver(RexProgram program) { for (RexNode expr : program.getExprList()) { if (Finder.instance.containsOver(expr)) { return true; } } return false; }
/** * Returns whether a program contains a multiset. */ public static boolean containsMultiset(RexProgram program) { return containsMultiset(program.getExprList(), true); }
@Override protected List<Set<Integer>> getCohorts() { final Set<Integer> cohort = new LinkedHashSet<Integer>(); final List<RexNode> exprList = program.getExprList(); for (int i = 0; i < exprList.size(); i++) { RexNode expr = exprList.get(i); if (expr instanceof RexOver) { cohort.add(i); } } if (cohort.isEmpty()) { return Collections.emptyList(); } else { return Collections.singletonList(cohort); } } }
/** * Returns whether a {@link RexProgram} contains expressions which require * decimal expansion. */ public static boolean requiresDecimalExpansion( RexProgram program, boolean recurse) { final List<RexNode> exprList = program.getExprList(); for (RexNode expr : exprList) { if (requiresDecimalExpansion(expr, recurse)) { return true; } } return false; }
/** * Returns whether a {@link RexProgram} contains expressions which require * decimal expansion. */ public static boolean requiresDecimalExpansion( RexProgram program, boolean recurse) { final List<RexNode> exprList = program.getExprList(); for (RexNode expr : exprList) { if (requiresDecimalExpansion(expr, recurse)) { return true; } } return false; }
public RexNode visitLocalRef(RexLocalRef localRef) { RexNode tree = getExprList().get(localRef.getIndex()); return tree.accept(this); } }
public RexNode visitLocalRef(RexLocalRef localRef) { RexNode tree = getExprList().get(localRef.getIndex()); return tree.accept(this); } }
public void collectVariablesUsed(Set<String> variableSet) { final RelOptUtil.VariableUsedVisitor vuv = new RelOptUtil.VariableUsedVisitor(); for (RexNode expr : program.getExprList()) { expr.accept(vuv); } variableSet.addAll(vuv.variables); }
public void collectVariablesUsed(Set<String> variableSet) { final RelOptUtil.VariableUsedVisitor vuv = new RelOptUtil.VariableUsedVisitor(); for (RexNode expr : program.getExprList()) { expr.accept(vuv); } variableSet.addAll(vuv.variables); }
public static List<RexLiteral> getOutputConstantsLiterals( RexProgram program ) { List<RexNode> exprList = program.getExprList(); List<RexLiteral> literals = new ArrayList<RexLiteral>(); List<RexLocalRef> projectList = program.getProjectList(); for( RexLocalRef ref : projectList ) { if( !program.isConstant( ref ) ) continue; literals.add( (RexLiteral) exprList.get( ref.getIndex() ) ); } return literals; }
/** * Returns whether a program contains an OVER clause. */ public static boolean containsOver(RexProgram program) { try { RexProgram.apply(FINDER, program.getExprList(), null); return false; } catch (OverFound e) { Util.swallow(e, null); return true; } }
/** * Returns true if any expression in a program contains a mixing between * multiset and non-multiset calls. */ public static boolean containsMixing(RexProgram program) { RexCallMultisetOperatorCounter counter = new RexCallMultisetOperatorCounter(); for (RexNode expr : program.getExprList()) { counter.reset(); expr.accept(counter); if ((counter.totalCount != counter.multisetCount) && (0 != counter.multisetCount)) { return true; } } return false; }
/** * Returns true if any expression in a program contains a mixing between * multiset and non-multiset calls. */ public static boolean containsMixing(RexProgram program) { RexCallMultisetOperatorCounter counter = new RexCallMultisetOperatorCounter(); for (RexNode expr : program.getExprList()) { counter.reset(); expr.accept(counter); if ((counter.totalCount != counter.multisetCount) && (0 != counter.multisetCount)) { return true; } } return false; }
/** * 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; }
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; }
/** * 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; } }
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(); }