Class QueryToKeyMatcher
- java.lang.Object
-
- com.apple.foundationdb.record.query.QueryToKeyMatcher
-
@API(INTERNAL) public class QueryToKeyMatcher extends Object
Match a query filter, represented by aQueryComponent
, to aKeyExpression
. In particular, this will find a sequence of comparisons that can be applied to the elements of a key expression in order to satisfy some (or all) of the query. For example, if the query filter isWHERE x = 1 AND y = 2
and this is matched againstconcat(x, y)
, then this will return[EQUALS 1, EQUALS 2]
. This indicates that if one, for example, had an index onconcat(x, y)
, then scanning over all index entries beginning with(1, 2)
would satisfy the query.There are two methods that attempt to match the query to a key expression. The first is the
matchesSatisfyingQuery()
method. This should be used if one wants to make sure that one can use the given key expression to retrieve all records that match the given query (i.e., the whether the fields included in the key expression contain enough information to satisfy the entire query). If there are unsatisfied components in the filter, this will return a match with typeNO_MATCH
. The other mode is thematchesCoveringKey()
method. This attempts to find a list of comparisons such that every column of the key expression has been set by some component of the filter. However, there may be components of the filter that are unsatisfied.By way of example, if the filter is
WHERE x = 1 AND y = 2
and the expression is just on fieldx
, then if one calls thematchesSatisfyingQuery
method, the matcher will returnNO_MATCH
, but it will return[EQUALS 1]
if thematchesCoveringKey
method is called. By contrast, if the filter isWHERE x = 1 AND y = 2
and the expression isconcat(x, y, z)
, then callingmatchesSatisfyingQuery
will return[EQUALS 1, EQUALS 2]
, but callingmatchesCoveringKey
will returnNO_MATCH
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueryToKeyMatcher.Match
The result of matching a particularKeyExpression
.static class
QueryToKeyMatcher.MatchType
Whether a match was a successful, and if it was, whether the resulting keys have a single value.
-
Constructor Summary
Constructors Constructor Description QueryToKeyMatcher(QueryComponent rootQuery)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description QueryToKeyMatcher.Match
matches(KeyExpression expression)
Deprecated.usematchesSatisfyingQuery(KeyExpression)
insteadQueryToKeyMatcher.Match
matchesCoveringKey(KeyExpression expression)
Attempt to match the expression to this matcher's root query and use every column in the key.QueryToKeyMatcher.Match
matchesCoveringKey(KeyExpression expression, FilterSatisfiedMask filterMask)
Attempt to match the expression to this matcher's root query and use every column in the key.QueryToKeyMatcher.Match
matchesSatisfyingQuery(KeyExpression expression)
Attempt to match the expression to this matcher's root query and satisfy every filter.QueryToKeyMatcher.Match
matchesSatisfyingQuery(KeyExpression expression, FilterSatisfiedMask filterMask)
Attempt to match the expression to this matcher's root query and satisfy every filter.
-
-
-
Constructor Detail
-
QueryToKeyMatcher
public QueryToKeyMatcher(@Nonnull QueryComponent rootQuery)
-
-
Method Detail
-
matchesCoveringKey
@Nonnull public QueryToKeyMatcher.Match matchesCoveringKey(@Nonnull KeyExpression expression)
Attempt to match the expression to this matcher's root query and use every column in the key. This will not track which components of the query are used when covering the given expression. To do that, callmatchesCoveringKey(KeyExpression, FilterSatisfiedMask)
and provide a non-null
value for thefilterMask
parameter.- Parameters:
expression
- the key expression to match the root query to- Returns:
- a match if the entire expression is covered by the root query
-
matchesCoveringKey
@Nonnull public QueryToKeyMatcher.Match matchesCoveringKey(@Nonnull KeyExpression expression, @Nullable FilterSatisfiedMask filterMask)
Attempt to match the expression to this matcher's root query and use every column in the key. This will track which components of the query were used when covering the given expression iffilterMask
is non-null
.- Parameters:
expression
- the key expression to match the root query tofilterMask
- a mask over this matcher's root query to track which filters have been satisfied- Returns:
- a match if the entire expression is covered by the root query
-
matchesSatisfyingQuery
@Nonnull public QueryToKeyMatcher.Match matchesSatisfyingQuery(@Nonnull KeyExpression expression)
Attempt to match the expression to this matcher's root query and satisfy every filter. Most of the time when calling this method, tracking which filters have been satisfied should be unnecessary as either they will be satisfied or this function will return a match withNO_MATCH
as its match type. However, if this is needed, one can callmatchesSatisfyingQuery(KeyExpression, FilterSatisfiedMask)
and provide a non-null
value for thefilterMask
parameter.- Parameters:
expression
- the key expression to match the root query to- Returns:
- a match if the entire expression is satisfied by this expression
-
matchesSatisfyingQuery
@Nonnull public QueryToKeyMatcher.Match matchesSatisfyingQuery(@Nonnull KeyExpression expression, @Nullable FilterSatisfiedMask filterMask)
Attempt to match the expression to this matcher's root query and satisfy every filter. Most of the time when calling this method, tracking which filters have been satisfied should be unnecessary as either they will be satisfied or this function will return a match withNO_MATCH
as its match type. However, if this is needed, one can provide a non-null
value for thefilterMask
parameter.- Parameters:
expression
- the key expression to match the root query tofilterMask
- a mask over this matcher's root query to track which filters have been satisfied- Returns:
- a match if the entire expression is satisfied by this expression
-
matches
@Nonnull @Deprecated public QueryToKeyMatcher.Match matches(@Nonnull KeyExpression expression)
Deprecated.usematchesSatisfyingQuery(KeyExpression)
insteadAttempt to match the expression to this matcher's root query and satisfy every filter. This has been deprecated in favor ofmatchesSatisfyingQuery(KeyExpression)
.- Parameters:
expression
- the key expression to match the root query to- Returns:
- a match if the entire expression is satisfied by this expression
-
-