public T orElse(T fallback) { return isPresent() ? value() : fallback; }
private <T, R> Match<R> assertMatch(Pattern<R> pattern, T matchedAgainst, R expectedMatch) { Match<R> match = DefaultMatcher.DEFAULT_MATCHER.match(pattern, matchedAgainst); assertEquals(expectedMatch, match.value()); return match; }
private <T> Rule.Result transform(PlanNode node, Rule<T> rule, Matcher matcher, Context context) { Rule.Result result; Match<T> match = matcher.match(rule.getPattern(), node); if (match.isEmpty()) { return Rule.Result.empty(); } long duration; try { long start = System.nanoTime(); result = rule.apply(match.value(), match.captures(), ruleContext(context)); duration = System.nanoTime() - start; } catch (RuntimeException e) { stats.recordFailure(rule); throw e; } stats.record(rule, duration, !result.isEmpty()); return result; }
private static <T> RuleApplication applyRule(Rule<T> rule, PlanNode planNode, Rule.Context context) { PlanNodeMatcher matcher = new PlanNodeMatcher(context.getLookup()); Match<T> match = matcher.match(rule.getPattern(), planNode); Rule.Result result; if (!rule.isEnabled(context.getSession()) || match.isEmpty()) { result = Rule.Result.empty(); } else { result = rule.apply(match.value(), match.captures(), context); } return new RuleApplication(context.getLookup(), context.getStatsProvider(), context.getSymbolAllocator().getTypes(), result); }
public T orElse(T fallback) { return isPresent() ? value() : fallback; }
private <T, R> Match<R> assertMatch(Pattern<R> pattern, T matchedAgainst, R expectedMatch) { Match<R> match = DefaultMatcher.DEFAULT_MATCHER.match(pattern, matchedAgainst); assertEquals(expectedMatch, match.value()); return match; }