/** * Applies this visitor to an array of expressions and an optional * single expression. */ public void apply(List<RexNode> exprs, RexNode expr) { RexProgram.apply(this, exprs, expr); }
/** * Returns the set of correlation variables used (read) by this program. * * @return set of correlation variable names */ public HashSet<String> getCorrelVariableNames() { final HashSet<String> paramIdSet = new HashSet<String>(); apply( new RexVisitorImpl<Void>(true) { public Void visitCorrelVariable( RexCorrelVariable correlVariable) { paramIdSet.add(correlVariable.getName()); return null; } }, exprs, null); return paramIdSet; }
/** * Returns the set of correlation variables used (read) by this program. * * @return set of correlation variable names */ public HashSet<String> getCorrelVariableNames() { final HashSet<String> paramIdSet = new HashSet<String>(); apply( new RexVisitorImpl<Void>(true) { public Void visitCorrelVariable( RexCorrelVariable correlVariable) { paramIdSet.add(correlVariable.getName()); return null; } }, exprs, null); return paramIdSet; }
/** Returns a bit set describing the inputs used by a collection of * project expressions and an optional condition. */ public static BitSet bits(List<RexNode> exprs, RexNode expr) { final BitSet inputBitSet = new BitSet(); RexProgram.apply(new InputFinder(inputBitSet), exprs, expr); return inputBitSet; }
/** * Returns whether an expression list contains an OVER clause. */ public static boolean containsOver(List<RexNode> exprs, RexNode condition) { try { RexProgram.apply(FINDER, exprs, condition); return false; } catch (OverFound e) { Util.swallow(e, null); return true; } }
/** * Returns a bit set describing the inputs used by a collection of * project expressions and an optional condition. */ public static BitSet bits(List<RexNode> exprs, RexNode expr) { final BitSet inputBitSet = new BitSet(); RexProgram.apply(new InputFinder(inputBitSet), exprs, expr); return inputBitSet; }
/** * 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; } }
/** * Gets reference counts for each expression in the program, where the * references are detected from later expressions in the same program, as * well as the project list and condition. Expressions with references * counts greater than 1 are true common sub-expressions. * * @return array of reference counts; the ith element in the returned array * is the number of references to getExprList()[i] */ public int [] getReferenceCounts() { if (refCounts != null) { return refCounts; } refCounts = new int[exprs.size()]; ReferenceCounter refCounter = new ReferenceCounter(); apply(refCounter, exprs, null); if (condition != null) { refCounter.visitLocalRef(condition); } for (RexLocalRef project : projects) { refCounter.visitLocalRef(project); } return refCounts; }
/** * Gets reference counts for each expression in the program, where the * references are detected from later expressions in the same program, as * well as the project list and condition. Expressions with references * counts greater than 1 are true common sub-expressions. * * @return array of reference counts; the ith element in the returned array * is the number of references to getExprList()[i] */ public int[] getReferenceCounts() { if (refCounts != null) { return refCounts; } refCounts = new int[exprs.size()]; ReferenceCounter refCounter = new ReferenceCounter(); apply(refCounter, exprs, null); if (condition != null) { refCounter.visitLocalRef(condition); } for (RexLocalRef project : projects) { refCounter.visitLocalRef(project); } return refCounts; }