Class ReferenceMatcher<T extends RelationalExpression>

  • Type Parameters:
    T - type parameter indicating the type of the expression the reference is a container for
    All Implemented Interfaces:
    ExpressionMatcher<ExpressionRef<T>>

    @API(EXPERIMENTAL)
    public abstract class ReferenceMatcher<T extends RelationalExpression>
    extends ExpressionMatcher.DefaultMatcher<ExpressionRef<T>>
    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 a 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 RelationalExpression 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 RelationalExpression.getQuantifiers(). 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 Detail

      • ReferenceMatcher

        public ReferenceMatcher()
    • Method Detail

      • anyRef

        public static ReferenceMatcher<? extends RelationalExpression> anyRef()
        Return a new 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.
        Returns:
        a new, distinct matcher that matches to any reference
      • anyOf

        public static <T extends RelationalExpressionReferenceMatcher<T> anyOf​(@Nonnull
                                                                                 ExpressionMatcher<T> membersMatcher)
        Return a new 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.
        Type Parameters:
        T - type parameter indicating the type of the expression the reference is a container for
        Parameters:
        membersMatcher - a matcher that is applied to the members of this reference
        Returns:
        a new, distinct matcher that matches to the cross product of references and their respective members matching the membersMatcher.
      • allOf

        public static <T extends RelationalExpressionReferenceMatcher<T> allOf​(@Nonnull
                                                                                 ExpressionMatcher<T> membersMatcher)
        Return a new ReferenceMatcher instance. The returned matcher is guaranteed to be distinct (according to pointer comparison) from the matchers returned by other calls. Moreover, the matcher is strongly typed to the same type T of the membersMatcher that is passed in.
        Type Parameters:
        T - type parameter indicating the type of the expression the reference is a container for
        Parameters:
        membersMatcher - a matcher that is applied to the members of this reference
        Returns:
        a new, distinct matcher that matches to the cross product of references and their respective members matching the membersMatcher.