Interface MatchCandidate
-
- All Known Implementing Classes:
PrimaryScanMatchCandidate
,ValueIndexScanMatchCandidate
public interface MatchCandidate
Interface to represent a match candidate. A match candidate on code level is just a name and a data flow graph that can be matched against a query graph. The match candidate does not keep the root to the graph to be matched but rather an instance ofExpressionRefTraversal
to allow for navigation of references within the candidate. Match candidates also allow for creation of scans over the materialized data, e.g. the index for anValueIndexScanMatchCandidate
or the primary range for aPrimaryScanMatchCandidate
, given appropriateComparisonRange
s which usually are the direct result of graph matching.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Map<CorrelationIdentifier,ComparisonRange>
computeBoundParameterPrefixMap(MatchInfo matchInfo)
Computes a map fromCorrelationIdentifier
toComparisonRange
that is physically compatible with a scan over the materialized version of the match candidate, so e.g.static Quantifier.ForEach
createBaseQuantifier(Set<String> allAvailableRecordTypes, Set<String> recordTypesForIndex)
default com.google.common.collect.SetMultimap<ExpressionRef<? extends RelationalExpression>,RelationalExpression>
findReferencingExpressions(com.google.common.collect.ImmutableList<? extends ExpressionRef<? extends RelationalExpression>> references)
static Optional<MatchCandidate>
fromIndexDefinition(RecordMetaData metaData, Index index, boolean isReverse)
static Optional<MatchCandidate>
fromPrimaryDefinition(RecordMetaData metaData, Set<String> recordTypes, KeyExpression commonPrimaryKey, boolean isReverse)
KeyExpression
getAlternativeKeyExpression()
This method returns a key expression that can be used to actually compute the the keys of this candidate for a given record.String
getName()
Returns the name of the match candidate.List<CorrelationIdentifier>
getParameters()
Returns the parameter names for all necessary parameters that need to be bound during matching.ExpressionRefTraversal
getTraversal()
Returns the traversal object for this candidate.default RelationalExpression
toScanExpression(MatchInfo matchInfo)
Creates a logical expression that represents a scan over the materialized candidate data.RelationalExpression
toScanExpression(List<ComparisonRange> comparisonRanges, boolean isReverse)
Creates a logical expression that represents a scan over the materialized candidate data.
-
-
-
Method Detail
-
getName
@Nonnull String getName()
Returns the name of the match candidate. If this candidate represents and index, it will be the name of the index.- Returns:
- the name of this match candidate
-
getTraversal
@Nonnull ExpressionRefTraversal getTraversal()
Returns the traversal object for this candidate. The traversal object can either be computed up-front when the candidate is created or lazily when this method is invoked. It is, however, necessary that the traversal once computed is stable, meaning the object returned by implementors of this method must always return the same object.- Returns:
- the traversal associated for this match candidate
-
getParameters
@Nonnull List<CorrelationIdentifier> getParameters()
Returns the parameter names for all necessary parameters that need to be bound during matching.- Returns:
- a list of
CorrelationIdentifier
s for all the used parameters in this match candidate
-
getAlternativeKeyExpression
@Nonnull KeyExpression getAlternativeKeyExpression()
This method returns a key expression that can be used to actually compute the the keys of this candidate for a given record. The current expression hierarchy cannot be evaluated at runtime (in general). This key expression helps representing compensation or part of compensation if needed.- Returns:
- a key expression that can be evaluated based on a base record
-
computeBoundParameterPrefixMap
default Map<CorrelationIdentifier,ComparisonRange> computeBoundParameterPrefixMap(@Nonnull MatchInfo matchInfo)
Computes a map fromCorrelationIdentifier
toComparisonRange
that is physically compatible with a scan over the materialized version of the match candidate, so e.g. for anValueIndexScanMatchCandidate
that would be the scan over the index. As matching progresses it finds mappings from parameters to corresponding comparison ranges. Matching, however, is not sensitive to whether such a binding could actually be used in an index scan. In fact, in a different maybe future record layer with improved physical operators this method should be revised to account for those improvements. For now, we only consider a prefix of said mappings that consist of n equality-bound mappings and stops either at an inequality bound parameter or before a unbound parameter.- Parameters:
matchInfo
- match info- Returns:
- a map containing parameter to comparison range mappings for a prefix of parameters that is compatible with a physical scan over the materialized view (of the candidate)
-
toScanExpression
default RelationalExpression toScanExpression(@Nonnull MatchInfo matchInfo)
Creates a logical expression that represents a scan over the materialized candidate data.- Parameters:
matchInfo
- the match info to be used- Returns:
- a new
RelationalExpression
-
toScanExpression
@Nonnull RelationalExpression toScanExpression(@Nonnull List<ComparisonRange> comparisonRanges, boolean isReverse)
Creates a logical expression that represents a scan over the materialized candidate data. This method is expected to be implemented by specific implementations ofMatchCandidate
.- Parameters:
comparisonRanges
- aList
ofComparisonRange
s to be appliedisReverse
- an indicator whether this expression should conceptually flow data in an ascending (forward) or descending (backward or reverse) order- Returns:
- a new
RelationalExpression
-
findReferencingExpressions
@Nonnull default com.google.common.collect.SetMultimap<ExpressionRef<? extends RelationalExpression>,RelationalExpression> findReferencingExpressions(@Nonnull com.google.common.collect.ImmutableList<? extends ExpressionRef<? extends RelationalExpression>> references)
-
fromIndexDefinition
@Nonnull static Optional<MatchCandidate> fromIndexDefinition(@Nonnull RecordMetaData metaData, @Nonnull Index index, boolean isReverse)
-
fromPrimaryDefinition
@Nonnull static Optional<MatchCandidate> fromPrimaryDefinition(@Nonnull RecordMetaData metaData, @Nonnull Set<String> recordTypes, @Nullable KeyExpression commonPrimaryKey, boolean isReverse)
-
-