Class Quantifiers
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.Quantifiers
-
public class Quantifiers extends Object
Auxiliary class containing factory methods and helpers forQuantifier
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Quantifiers.MatchingPredicate
An predicate that tests for a match between quantifiers also taking into account an equivalence maps betweenCorrelationIdentifier
s.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E extends RelationalExpression>
List<Quantifier.Existential>existentialQuantifiers(Iterable<? extends ExpressionRef<E>> rangesOverPlans)
Create a list of existential quantifiers from a list of expression references these quantifiers should range over.static <E extends RelationalExpression>
List<Quantifier.ForEach>forEachQuantifiers(Iterable<ExpressionRef<E>> rangesOverExpressions)
Create a list of for-each quantifiers from a list of references to range over.static <E extends RelationalExpression,Q extends Quantifier>
List<Q>fromExpressions(Iterable<? extends ExpressionRef<E>> rangesOverExpressions, Function<ExpressionRef<E>,Q> creator)
Create a list of quantifiers given a list of references these quantifiers should range over.static <E extends RecordQueryPlan>
List<Quantifier.Physical>fromPlans(Iterable<? extends ExpressionRef<E>> rangesOverPlans)
Create a list of physical quantifiers given a list of references these quantifiers should range over.static Iterable<AliasMap>
match(Collection<? extends Quantifier> quantifiers, Collection<? extends Quantifier> otherQuantifiers, boolean canCorrelate, AliasMap equivalencesMap, Quantifiers.MatchingPredicate predicate)
Method to match up the quantifiers this expression owns with the given set of other quantifiers using an equivalence map.static <Q extends Quantifier>
List<Q>narrow(Class<Q> narrowedClass, List<? extends Quantifier> quantifiers)
static <Q extends Quantifier>
Set<Q>narrow(Class<Q> narrowedClass, Set<? extends Quantifier> quantifiers)
static com.google.common.collect.ImmutableMap<CorrelationIdentifier,? extends Quantifier>
toAliasToQuantifierMap(Collection<? extends Quantifier> quantifiers)
static AliasMap
toIDMap(com.google.common.collect.BiMap<Quantifier,Quantifier> map)
Convenience helper to create an alias translation map based on a translation map using quantifiers.static AliasMap
translate(Quantifier from, Quantifier to)
Convenience helper to create a single ID translation map from the alias of one quantifier to the alias of another quantifier.
-
-
-
Method Detail
-
forEachQuantifiers
@Nonnull public static <E extends RelationalExpression> List<Quantifier.ForEach> forEachQuantifiers(@Nonnull Iterable<ExpressionRef<E>> rangesOverExpressions)
Create a list of for-each quantifiers from a list of references to range over.- Type Parameters:
E
- type parameter to constrain expressions toRelationalExpression
- Parameters:
rangesOverExpressions
- iterableExpressionRef
s ofRelationalExpression
s- Returns:
- a list of for-each quantifiers where each quantifier ranges over one of the given references
-
existentialQuantifiers
@Nonnull public static <E extends RelationalExpression> List<Quantifier.Existential> existentialQuantifiers(@Nonnull Iterable<? extends ExpressionRef<E>> rangesOverPlans)
Create a list of existential quantifiers from a list of expression references these quantifiers should range over.- Type Parameters:
E
- type parameter to constrain expressions toRelationalExpression
- Parameters:
rangesOverPlans
- iterableExpressionRef
s of ofRelationalExpression
s.- Returns:
- a list of physical quantifiers where each quantifier ranges over one of the given references
-
fromPlans
@Nonnull public static <E extends RecordQueryPlan> List<Quantifier.Physical> fromPlans(@Nonnull Iterable<? extends ExpressionRef<E>> rangesOverPlans)
Create a list of physical quantifiers given a list of references these quantifiers should range over.- Type Parameters:
E
- type parameter to constrain expressions toRecordQueryPlan
- Parameters:
rangesOverPlans
- iterableExpressionRef
s ofRecordQueryPlan
- Returns:
- a list of physical quantifiers where each quantifier ranges over a reference contained in the given iterable
-
fromExpressions
@Nonnull public static <E extends RelationalExpression,Q extends Quantifier> List<Q> fromExpressions(@Nonnull Iterable<? extends ExpressionRef<E>> rangesOverExpressions, @Nonnull Function<ExpressionRef<E>,Q> creator)
Create a list of quantifiers given a list of references these quantifiers should range over.- Type Parameters:
E
- type parameter to constrain expressions toRelationalExpression
Q
- the type of the quantifier to be created- Parameters:
rangesOverExpressions
- iterable ofExpressionRef
s the quantifiers will be created to range overcreator
- lambda to to be called for each expression reference contained inrangesOverExpression
s to create the actual quantifier. This allows for callers to create different kinds of quantifier based on needs.- Returns:
- a list of quantifiers where each quantifier ranges over an reference contained in the given iterable
-
translate
@Nonnull public static AliasMap translate(@Nonnull Quantifier from, @Nonnull Quantifier to)
Convenience helper to create a single ID translation map from the alias of one quantifier to the alias of another quantifier.- Parameters:
from
- quantifierto
- quantifier- Returns:
- a new translation map mapping from
from.getAlias()
toto.getAlias()
-
toIDMap
@Nonnull public static AliasMap toIDMap(@Nonnull com.google.common.collect.BiMap<Quantifier,Quantifier> map)
Convenience helper to create an alias translation map based on a translation map using quantifiers. of another quantifier.- Parameters:
map
- quantifier to quantifier bi-map- Returns:
- a new
AliasMap
mapping fromfrom.getAlias()
toto.getAlias()
-
toAliasToQuantifierMap
@Nonnull public static com.google.common.collect.ImmutableMap<CorrelationIdentifier,? extends Quantifier> toAliasToQuantifierMap(@Nonnull Collection<? extends Quantifier> quantifiers)
-
narrow
@Nonnull public static <Q extends Quantifier> List<Q> narrow(@Nonnull Class<Q> narrowedClass, @Nonnull List<? extends Quantifier> quantifiers)
-
narrow
@Nonnull public static <Q extends Quantifier> Set<Q> narrow(@Nonnull Class<Q> narrowedClass, @Nonnull Set<? extends Quantifier> quantifiers)
-
match
@Nonnull public static Iterable<AliasMap> match(@Nonnull Collection<? extends Quantifier> quantifiers, @Nonnull Collection<? extends Quantifier> otherQuantifiers, boolean canCorrelate, @Nonnull AliasMap equivalencesMap, @Nonnull Quantifiers.MatchingPredicate predicate)
Method to match up the quantifiers this expression owns with the given set of other quantifiers using an equivalence map. Two quantifiers can be considered a match if the given predicate returnstrue
. This method attempts to match up each quantifier from the set of quantifiers this expression owns to the given other set of quantifiers such that the given predicate returnstrue
for each mapping. Note that there may be multiple distinct matches between the quantifier sets. This method returns anIterable
of such matches where each match is only computed when it is requested by an iterator'sIterator.hasNext()
. Thus it can be assumed that this method never pre-computes all possible matches. This method returns an empty mapping if e.g. the number quantifiers in the respective sets doesn't match. For expressions that cannot introduce correlations, this method is simplyO(n!)
where is the number of quantifiers (which is equal for both sets). This path is taken by UNIONs and other set operations. For expressions that introduce correlations, the matching process is more complicated. First, we determine one topologically correct ordering. Then we iterate through all topologically correct orderings of the set of quantifiers this expression owns. For each element in the permutation of quantifiers that is returned by theTopologicalSort.TopologicalOrderPermutationIterator
we try to math the quantifiers between the sets topologically from left to right (usingpredicate
). For each match we find we add an equivalence between the alias of this and the other quantifier that matched in an equivalence map that extends the given equivalence map.- Parameters:
quantifiers
- collection of quantifiersotherQuantifiers
- collection of _other_ quantifierscanCorrelate
- indicator if the expression containing these quantifiers can actively introduce correlationsequivalencesMap
- equivalence mappredicate
- that tests if two quantifiers and their graph they range over can be considered equivalent- Returns:
- An
AliasMap
containing a mapping from the quantifiers this expression owns to the quantifiers inotherQuantifiers
. Note that the mapping is bijective and can therefore be inverted.
-
-