Interface ExpressionMatcher<T extends Bindable>
-
- Type Parameters:
T
- the bindable type that this matcher binds to
- All Known Implementing Classes:
ExpressionMatcher.DefaultMatcher
,MatchPartitionMatcher
,PartialMatchMatcher
,QuantifierMatcher
,ReferenceMatcher
,TypeMatcher
,TypeWithPredicateMatcher
@API(EXPERIMENTAL) public interface ExpressionMatcher<T extends Bindable>
AExpressionMatcher
is an expression that can be matched against aRelationalExpression
tree, while binding certain expressions/references in the tree to expression matcher objects. The bindings can be retrieved from the rule call once the binding is matched.An
ExpressionMatcher
interacts with aPlannerExpression
tree using itsmatchWith(PlannerBindings, RelationalExpression, List)
andmatchWith(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings, com.apple.foundationdb.record.query.plan.temp.ExpressionRef<? extends com.apple.foundationdb.record.query.plan.temp.RelationalExpression>, java.util.List<? extends com.apple.foundationdb.record.query.plan.temp.Bindable>)
methods. At a high level, thematchWith()
methods are responsible for determining whether this matcher matches the root expression or reference passed tomatchWith()
. AlthoughExpressionMatcher
s are themselves hierarchical structures, anExpressionMatcher
must not try to match into the contents (in the case of matching a reference) or children (in the case of matching an expression) of the given root. Depending on the specific implementation of the root structure, matching against children/members can be quite complicated, so this behavior is implemented by theBindable.bindTo(PlannerBindings, ExpressionMatcher)
method instead. AnExpressionMatcher
holds anExpressionChildrenMatcher
which describes how the children should be matched.Extreme care should be taken when implementing
ExpressionMatcher
, since it can be very delicate. In particular, expression matchers may (or may not) be reused between successive rule calls and should be stateless. Additionally, implementors ofExpressionMatcher
must use the (default) reference equals.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ExpressionMatcher.DefaultMatcher<T extends Bindable>
A default matcher.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Class<? extends Bindable>
getRootClass()
Get a class or interface extendingRelationalExpression
that is a super class of every planner expression that this matcher can match.Stream<PlannerBindings>
matchWith(PlannerBindings outerBindings, ExpressionRef<? extends RelationalExpression> ref, List<? extends Bindable> children)
Attempt to match this matcher against the given expression reference.Stream<PlannerBindings>
matchWith(PlannerBindings outerBindings, MatchPartition matchPartition, List<? extends Bindable> children)
Attempt to match this matcher against the givenMatchPartition
.Stream<PlannerBindings>
matchWith(PlannerBindings outerBindings, PartialMatch partialMatch, List<? extends Bindable> children)
Attempt to match this matcher against the givenPartialMatch
.Stream<PlannerBindings>
matchWith(PlannerBindings outerBindings, Quantifier quantifier, List<? extends Bindable> children)
Attempt to match this matcher against the givenQuantifier
.Stream<PlannerBindings>
matchWith(PlannerBindings outerBindings, RelationalExpression expression, List<? extends Bindable> children)
Attempt to match this matcher against the givenExpressionMatcher
.Stream<PlannerBindings>
matchWith(PlannerBindings outerBindings, QueryPredicate predicate, List<? extends Bindable> children)
Attempt to match this matcher against the givenQueryPredicate
.static <T extends Bindable>
ExpressionMatcher<T>uniqueBindingKey()
-
-
-
Method Detail
-
getRootClass
@Nonnull Class<? extends Bindable> getRootClass()
Get a class or interface extendingRelationalExpression
that is a super class of every planner expression that this matcher can match. Ideally, it should be the lowest such class but it may not be. A planner will generally use this method to quickly determine a set of rules that could match an expression, without considering each rule and trying to apply it. A good implementation of this method helps the planner match rules efficiently.- Returns:
- a class object for a class that is a super class of every planner expression this matcher can match
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull PlannerBindings outerBindings, @Nonnull ExpressionRef<? extends RelationalExpression> ref, @Nonnull List<? extends Bindable> children)
Attempt to match this matcher against the given expression reference. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression or attempt to access the members of the given reference.- Parameters:
outerBindings
- preexisting bindings to be used by the matcherref
- a reference to match withchildren
- the conceptual children ofref
, i.e. the memmbers of the group reference.- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull PlannerBindings outerBindings, @Nonnull RelationalExpression expression, @Nonnull List<? extends Bindable> children)
Attempt to match this matcher against the givenExpressionMatcher
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression.- Parameters:
outerBindings
- preexisting bindings to be used by the matcherexpression
- a planner expression to match withchildren
- the conceptual children ofexpression
- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull PlannerBindings outerBindings, @Nonnull QueryPredicate predicate, @Nonnull List<? extends Bindable> children)
Attempt to match this matcher against the givenQueryPredicate
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression.- Parameters:
outerBindings
- preexisting bindings to be used by the matcherpredicate
- a predicate to match withchildren
- the conceptual children ofpredicate
- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull PlannerBindings outerBindings, @Nonnull Quantifier quantifier, @Nonnull List<? extends Bindable> children)
Attempt to match this matcher against the givenQuantifier
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression.- Parameters:
outerBindings
- preexisting bindings to be used by the matcherquantifier
- a quantifier to match withchildren
- the conceptual children ofquantifier
- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull PlannerBindings outerBindings, @Nonnull PartialMatch partialMatch, @Nonnull List<? extends Bindable> children)
Attempt to match this matcher against the givenPartialMatch
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression.- Parameters:
outerBindings
- preexisting bindings to be used by the matcherpartialMatch
- a partial match to match withchildren
- the conceptual children ofpredicate
- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull PlannerBindings outerBindings, @Nonnull MatchPartition matchPartition, @Nonnull List<? extends Bindable> children)
Attempt to match this matcher against the givenMatchPartition
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression.- Parameters:
outerBindings
- preexisting bindings to be used by the matchermatchPartition
- to match withchildren
- the conceptual children ofpredicate
- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
uniqueBindingKey
@Nonnull static <T extends Bindable> ExpressionMatcher<T> uniqueBindingKey()
-
-