T
- the type of planner expression that this matcher will always bind to@API(value=EXPERIMENTAL) public class ReferenceMatcher<T extends PlannerExpression> extends Object implements ExpressionMatcher<ExpressionRef<T>>
ReferenceMatcher
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 the ReferenceMatcher
has a type parameter, it cannot statically verify that the type of PlannerExpression
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 of PlannerExpression
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 by PlannerExpression.getPlannerExpressionChildren()
. For example, it would be safe to use a
ReferenceMatcher<QueryComponent>
to match against the second planner expression child of a
RecordQueryFilterPlan
because that child is necessarily a
QueryComponent
; 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, the PlannerBindings
will throw a ClassCastException
.Constructor and Description |
---|
ReferenceMatcher() |
Modifier and Type | Method and Description |
---|---|
static <U extends PlannerExpression> |
anyRef()
Return a new
ReferenceMatcher instance. |
ExpressionChildrenMatcher |
getChildrenMatcher()
Return the child matchers of this matcher as a list.
|
Class<? extends PlannerExpression> |
getRootClass()
Get a class or interface extending
PlannerExpression that is a super class of every planner expression
that this matcher can match. |
Stream<PlannerBindings> |
matchWith(ExpressionRef<? extends PlannerExpression> ref)
Attempt to match this matcher against the given expression reference.
|
Stream<PlannerBindings> |
matchWith(PlannerExpression expression)
Attempt to match this matcher against the given expression reference.
|
@Nonnull public Class<? extends PlannerExpression> getRootClass()
ExpressionMatcher
PlannerExpression
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.getRootClass
in interface ExpressionMatcher<ExpressionRef<T extends PlannerExpression>>
@Nonnull public ExpressionChildrenMatcher getChildrenMatcher()
ExpressionMatcher
getChildrenMatcher
in interface ExpressionMatcher<ExpressionRef<T extends PlannerExpression>>
@Nonnull public Stream<PlannerBindings> matchWith(@Nonnull ExpressionRef<? extends PlannerExpression> ref)
ExpressionMatcher
matchWith()
should only attempt to match the given root with this planner
expression and should not call into the ExpressionChildrenMatcher
returned by ExpressionMatcher.getChildrenMatcher()
or attempt to access the members of the given reference.matchWith
in interface ExpressionMatcher<ExpressionRef<T extends PlannerExpression>>
ref
- a reference to match withPlannerBindings
containing the matched bindings, or an empty stream is no match was found@Nonnull public Stream<PlannerBindings> matchWith(@Nonnull PlannerExpression expression)
ExpressionMatcher
matchWith()
should only attempt to match the given root with this planner
expression and should not call into the ExpressionChildrenMatcher
returned by ExpressionMatcher.getChildrenMatcher()
or attempt to access children of the given expression.matchWith
in interface ExpressionMatcher<ExpressionRef<T extends PlannerExpression>>
expression
- a planner expression to match withPlannerBindings
containing the matched bindings, or an empty stream is no match was foundpublic static <U extends PlannerExpression> ReferenceMatcher<U> anyRef()
ReferenceMatcher
instance. The returned matcher is guaranteed to be distinct (according to
pointer comparison) from the matchers returned by other calls to anyRef()
, so that multiple such matchers
may be used in a single PlannerBindings
object.U
- the type of PlannerExpression
that is guaranteed (by programmer knowledge) to be behind the references that this matcher will bind to