Visitor that looks for an aggregate function inside a tree of SqlNode objects and throws Util.FoundOne when it finds one.
| 32 | * {@link SqlNode} objects and throws {@link Util.FoundOne} when it finds |
| 33 | * one. */ |
| 34 | class AggFinder extends AggVisitor { |
| 35 | /** |
| 36 | * Creates an AggFinder. |
| 37 | * |
| 38 | * @param opTab Operator table |
| 39 | * @param over Whether to find windowed function calls {@code agg(x) OVER |
| 40 | * windowSpec} |
| 41 | * @param aggregate Whether to find non-windowed aggregate calls |
| 42 | * @param group Whether to find group functions (e.g. {@code TUMBLE}) |
| 43 | * @param delegate Finder to which to delegate when processing the arguments |
| 44 | * @param nameMatcher Whether to match the agg function case-sensitively |
| 45 | */ |
| 46 | AggFinder(SqlOperatorTable opTab, boolean over, boolean aggregate, |
| 47 | boolean group, @Nullable AggFinder delegate, SqlNameMatcher nameMatcher) { |
| 48 | super(opTab, over, aggregate, group, delegate, nameMatcher); |
| 49 | } |
| 50 | |
| 51 | //~ Methods ---------------------------------------------------------------- |
| 52 | |
| 53 | /** |
| 54 | * Finds an aggregate. |
| 55 | * |
| 56 | * @param node Parse tree to search |
| 57 | * @return First aggregate function in parse tree, or null if not found |
| 58 | */ |
| 59 | public @Nullable SqlCall findAgg(SqlNode node) { |
| 60 | try { |
| 61 | node.accept(this); |
| 62 | return null; |
| 63 | } catch (Util.FoundOne e) { |
| 64 | Util.swallow(e, null); |
| 65 | return (SqlCall) e.getNode(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // SqlNodeList extends SqlNode and implements List<SqlNode>, so this method |
| 70 | // disambiguates |
| 71 | public @Nullable SqlCall findAgg(SqlNodeList nodes) { |
| 72 | return findAgg((List<SqlNode>) nodes); |
| 73 | } |
| 74 | |
| 75 | public @Nullable SqlCall findAgg(List<SqlNode> nodes) { |
| 76 | try { |
| 77 | for (SqlNode node : nodes) { |
| 78 | node.accept(this); |
| 79 | } |
| 80 | return null; |
| 81 | } catch (Util.FoundOne e) { |
| 82 | Util.swallow(e, null); |
| 83 | return (SqlCall) e.getNode(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | @Override protected Void found(SqlCall call) { |
| 88 | throw new Util.FoundOne(call); |
| 89 | } |
| 90 | |
| 91 | /** Creates a copy of this finder that has the same parameters as this, |
nothing calls this directly
no outgoing calls
no test coverage detected