Class ComputingMatcher<T,M,R>
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.matching.BaseMatcher<T>
-
- com.apple.foundationdb.record.query.plan.temp.matching.ComputingMatcher<T,M,R>
-
- Type Parameters:
T
- the element typeM
- the type that theMatchFunction
producesIterable
s ofR
- the result type
- All Implemented Interfaces:
GenericMatcher<BoundMatch<R>>
public class ComputingMatcher<T,M,R> extends BaseMatcher<T> implements GenericMatcher<BoundMatch<R>>
This class implements aGenericMatcher
which matches two sets of elements of typeT
to compute a result of typeIterable<BoundMatch<R>>
. Individual elements are matched by means of aMatchFunction
which produces an (intermediate)Iterable
of typeM
for each pair of matching elements. In order to match this set against the other set, we need to find matching pairs of elements for each element identified byBaseMatcher.getAliases()
. The intermediate iterables of typeM
produced by the matching function get accumulated across all such matching pairs to produce anIterable
of typeR
using aMatchAccumulator
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterator<BoundMatch<R>>
enumerate(EnumeratingIterator<CorrelationIdentifier> iterator, List<CorrelationIdentifier> otherOrdered)
Method to enumerate the permutations on this side against the permutation of the other side in order to form matches (bijective mappings between the permutations).Iterable<BoundMatch<R>>
match()
static <T,M,R>
GenericMatcher<BoundMatch<R>>onAliasDependencies(AliasMap boundAliasesMap, Collection<? extends T> elements, Function<T,CorrelationIdentifier> elementToAliasFn, Function<T,Set<CorrelationIdentifier>> dependsOnFn, Collection<? extends T> otherElements, Function<T,CorrelationIdentifier> otherElementToAliasFn, Function<T,Set<CorrelationIdentifier>> otherDependsOnFn, MatchFunction<T,M> matchFunction, Supplier<MatchAccumulator<M,R>> matchAccumulatorSupplier)
Static factory method to create a generic matcher using element typeT
.static <M> MatchAccumulator<M,EnumeratingIterable<M>>
productAccumulator()
Method that returns anMatchAccumulator
that accumulatesIterable
s of typeM
and finally produces anEnumeratingIterable
of typeM
that is the cross product of all elements of the respectiveIterable
s.-
Methods inherited from class com.apple.foundationdb.record.query.plan.temp.matching.BaseMatcher
computeAliases, computeAliasToElementMap, computeDependsOnMap, computeDependsOnMapWithAliases, getAliases, getAliasToElementMap, getBoundAliasesMap, getDependsOnMap, getElementToAliasFn, getOtherAliases, getOtherAliasToElementMap, getOtherDependsOnMap, getOtherElementToAliasFn, isIsomorphic, mapDependenciesToOther, match
-
-
-
-
Method Detail
-
match
@Nonnull public Iterable<BoundMatch<R>> match()
Match using the methodenumerate(com.apple.foundationdb.record.query.plan.temp.EnumeratingIterator<com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier>, java.util.List<com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier>)
asEnumerationFunction
.- Specified by:
match
in interfaceGenericMatcher<T>
- Returns:
- an iterable of match results.
-
enumerate
@Nonnull public Iterator<BoundMatch<R>> enumerate(@Nonnull EnumeratingIterator<CorrelationIdentifier> iterator, @Nonnull List<CorrelationIdentifier> otherOrdered)
Method to enumerate the permutations on this side against the permutation of the other side in order to form matches (bijective mappings between the permutations). The match function is called for each pair of elements (for a match attempt). If the match function returns a non-emptyIterable
the pair is recorded as a matching pair. We attempt to find a matching pair (one from this side; one from the other side) for each element identified byBaseMatcher.getAliases()
. For each individual new such pair that is found, the methodMatchAccumulator.accumulate(java.lang.Iterable<M>)
is called. Once a set of bindings is established for all aliases inBaseMatcher.getAliases()
this method then callsMatchAccumulator.finish()
to produce an iterable of typeR
.- Parameters:
iterator
- an enumerating iterable for the permutations on this sideotherOrdered
- one permutation (that is not violating dependencies, constraints, etc.) of the other side- Returns:
- an
Iterator
of match results (of typeBoundMatch<R>
)
-
onAliasDependencies
@Nonnull public static <T,M,R> GenericMatcher<BoundMatch<R>> onAliasDependencies(@Nonnull AliasMap boundAliasesMap, @Nonnull Collection<? extends T> elements, @Nonnull Function<T,CorrelationIdentifier> elementToAliasFn, @Nonnull Function<T,Set<CorrelationIdentifier>> dependsOnFn, @Nonnull Collection<? extends T> otherElements, @Nonnull Function<T,CorrelationIdentifier> otherElementToAliasFn, @Nonnull Function<T,Set<CorrelationIdentifier>> otherDependsOnFn, @Nonnull MatchFunction<T,M> matchFunction, @Nonnull Supplier<MatchAccumulator<M,R>> matchAccumulatorSupplier)
Static factory method to create a generic matcher using element typeT
. This method is optimized to the case when the dependsOn sets are already given by sets ofCorrelationIdentifier
s.- Type Parameters:
T
- the element typeM
- the type that theMatchFunction
producesIterable
s ofR
- r- Parameters:
boundAliasesMap
- a map with previously-bound aliases. Any match that is computed and passed back to the client is an amendment of this map, i.e., every resulting match'sAliasMap
always contains at least the bindings in this mapelements
- a collection of elements of typeT
representing the domain on this sideelementToAliasFn
- a function to map elements of typeT
on this side to correlation identifiersdependsOnFn
- a function from elements to sets of correlation identifiers describing the depends-on relationships between the elements on this sideotherElements
- a collection of other elements representing the domain on the other sideotherElementToAliasFn
- a function to map elements of typeT
on the other side to correlation identifiersotherDependsOnFn
- a function from elements to sets of correlation identifiers describing the depends-on relationships between the other elementsmatchFunction
- a match function that computes anIterable
of typeM
for each matching pair of elementsmatchAccumulatorSupplier
- a supplier to create accumulators to accumulate intermediateIterable
s of typeM
into anIterable
of typeR
- Returns:
- a newly created generic matcher of type
BoundMatch<R>
-
productAccumulator
@Nonnull public static <M> MatchAccumulator<M,EnumeratingIterable<M>> productAccumulator()
Method that returns anMatchAccumulator
that accumulatesIterable
s of typeM
and finally produces anEnumeratingIterable
of typeM
that is the cross product of all elements of the respectiveIterable
s.- Type Parameters:
M
- the type theMatchFunction
producesIterable
s of- Returns:
- a newly created accumulator
-
-