Class ReferenceMatcher<T extends RelationalExpression>
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.matchers.ReferenceMatcher<T>
-
- Type Parameters:
T
- the type of planner expression that this matcher will always bind to
- All Implemented Interfaces:
ExpressionMatcher<ExpressionRef<T>>
@API(EXPERIMENTAL) public class ReferenceMatcher<T extends RelationalExpression> extends Object implements ExpressionMatcher<ExpressionRef<T>>
An expression matcher that matches against any reference at all. It is frequently used by rules that want to capture everything behind a reference without regard for its content. The bindings generated by aReferenceMatcher
do not provide any access to what was matched. However, the references from the binding can be used when constructing new planner expressions to yield to the planner, which is especially efficient when the references are groups. Although theReferenceMatcher
has a type parameter, it cannot statically verify that the type ofRelationalExpression
behind a reference actually matches its type parameter, because of type erasure. It is up to the programmer to verify that the type parameter is general enough to cover every possible type ofPlannerExpression
that might be behind any reference that it could be matched to. In general, the programmer will be certain that a reference would contain a particular type because an expression of a certain type is always found in a particular position of the iterator returned byRelationalExpression.getQuantifiers()
. For example, it would be safe to use aReferenceMatcher<QueryComponent>
to match against the second planner expression child of aRecordQueryFilterPlan
because that child is necessarily aQueryComponent
; note that there is no way for the type system to know that, so the programmer must track such information when writing rules. If the wrong type is used for the type parameter, thePlannerBindings
will throw aClassCastException
.
-
-
Constructor Summary
Constructors Constructor Description ReferenceMatcher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <U extends RelationalExpression>
ReferenceMatcher<U>anyRef()
Return a newReferenceMatcher
instance.ExpressionChildrenMatcher
getChildrenMatcher()
Return the child matchers of this matcher as a list.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(ExpressionRef<? extends RelationalExpression> ref)
Attempt to match this matcher against the given expression reference.Stream<PlannerBindings>
matchWith(Quantifier quantifier)
Attempt to match this matcher against the givenQuantifier
.Stream<PlannerBindings>
matchWith(RelationalExpression expression)
Attempt to match this matcher against the givenExpressionMatcher
.Stream<PlannerBindings>
matchWith(QueryPredicate predicate)
Attempt to match this matcher against the givenQueryPredicate
.
-
-
-
Method Detail
-
getRootClass
@Nonnull public Class<? extends Bindable> getRootClass()
Description copied from interface:ExpressionMatcher
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.- Specified by:
getRootClass
in interfaceExpressionMatcher<T extends RelationalExpression>
- Returns:
- a class object for a class that is a super class of every planner expression this matcher can match
-
getChildrenMatcher
@Nonnull public ExpressionChildrenMatcher getChildrenMatcher()
Description copied from interface:ExpressionMatcher
Return the child matchers of this matcher as a list.- Specified by:
getChildrenMatcher
in interfaceExpressionMatcher<T extends RelationalExpression>
- Returns:
- a list of the child matchers of this matcher
-
matchWith
@Nonnull public Stream<PlannerBindings> matchWith(@Nonnull ExpressionRef<? extends RelationalExpression> ref)
Description copied from interface:ExpressionMatcher
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 and should not call into theExpressionChildrenMatcher
returned byExpressionMatcher.getChildrenMatcher()
or attempt to access the members of the given reference.- Specified by:
matchWith
in interfaceExpressionMatcher<T extends RelationalExpression>
- Parameters:
ref
- a reference to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull public Stream<PlannerBindings> matchWith(@Nonnull RelationalExpression expression)
Description copied from interface:ExpressionMatcher
Attempt to match this matcher against the givenExpressionMatcher
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression and should not call into theExpressionChildrenMatcher
returned byExpressionMatcher.getChildrenMatcher()
or attempt to access children of the given expression.- Specified by:
matchWith
in interfaceExpressionMatcher<T extends RelationalExpression>
- Parameters:
expression
- a planner expression to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull public Stream<PlannerBindings> matchWith(@Nonnull QueryPredicate predicate)
Description copied from interface:ExpressionMatcher
Attempt to match this matcher against the givenQueryPredicate
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression and should not call into theExpressionChildrenMatcher
returned byExpressionMatcher.getChildrenMatcher()
or attempt to access children of the given expression.- Specified by:
matchWith
in interfaceExpressionMatcher<T extends RelationalExpression>
- Parameters:
predicate
- a predicate to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull public Stream<PlannerBindings> matchWith(@Nonnull Quantifier quantifier)
Description copied from interface:ExpressionMatcher
Attempt to match this matcher against the givenQuantifier
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression and should not call into theExpressionChildrenMatcher
returned byExpressionMatcher.getChildrenMatcher()
or attempt to access children of the given expression.- Specified by:
matchWith
in interfaceExpressionMatcher<T extends RelationalExpression>
- Parameters:
quantifier
- a quantifier to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
anyRef
public static <U extends RelationalExpression> ReferenceMatcher<U> anyRef()
Return a newReferenceMatcher
instance. The returned matcher is guaranteed to be distinct (according to pointer comparison) from the matchers returned by other calls toanyRef()
, so that multiple such matchers may be used in a singlePlannerBindings
object.- Type Parameters:
U
- the type ofRelationalExpression
that is guaranteed (by programmer knowledge) to be behind the references that this matcher will bind to- Returns:
- a new, distinct matcher that matches to any reference
-
-