Class Quantifier
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.Quantifier
-
- All Implemented Interfaces:
Bindable
,Correlated<Quantifier>
- Direct Known Subclasses:
Quantifier.Existential
,Quantifier.ForEach
,Quantifier.Physical
@API(EXPERIMENTAL) public abstract class Quantifier extends Object implements Bindable, Correlated<Quantifier>
Models the concept of quantification.A quantifier describes the data flow between the output of one
RelationalExpression
R
and the consumption of that data by anotherRelationalExpression
S
.S
is said to own the quantifier, while the quantifier is said to range overR
. Quantifiers come in very few but very distinct flavors. All flavors are implemented by static inner final classes in order to emulate a sealed trait.Quantifiers separate what it means to be producing versus consuming items. The expression a quantifier ranges over produces records, the quantifier flows information (in a manner determined by the flavor) that is consumed by the expression containing or owning the quantifier. That expression can consume the data in a way independent of how the data was produced in the first place.
A quantifier works closely with the expression that owns it. Depending on the semantics of the owning expression it becomes possible to model correlations. For example, in a logical join expression the quantifier can provide a binding of the item being currently consumed by the join's outer to other (inner) parts of the data flow that are also rooted at the owning (join) expression.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Quantifier.Builder<Q extends Quantifier,B extends Quantifier.Builder<Q,B>>
Builder class for quantifiers.static class
Quantifier.Existential
A quantifier that conceptually flows exactly one item containing a boolean to the owning expression indicating whether the sub-graph that the quantifier ranges over produced a non-empty or an empty result.static class
Quantifier.ForEach
A quantifier that conceptually flows one item at a time from the expression it ranges over to the owning expression.static class
Quantifier.Physical
Physical quantifier.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Quantifier(CorrelationIdentifier alias)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <U> U
acceptPropertyVisitor(PlannerProperty<U> visitor)
Allow the computation ofPlannerProperty
s across the quantifiers in the data flow graph.Stream<PlannerBindings>
bindTo(ExpressionMatcher<? extends Bindable> matcher)
Attempt to match the matcher to this bindable object.boolean
equals(Object other)
boolean
equalsOnKind(Object o)
static Quantifier.Existential
existential(ExpressionRef<? extends RelationalExpression> reference)
Shorthand to create an existential quantifier ranging over a reference.static Quantifier.Existential
existential(ExpressionRef<? extends RelationalExpression> reference, CorrelationIdentifier alias)
Shorthand to create an existential quantifier ranging over a reference using a given alias.static Quantifier.Existential.ExistentialBuilder
existentialBuilder()
Create a builder for an existential quantifier containing relational expressions.static Quantifier.ForEach
forEach(ExpressionRef<? extends RelationalExpression> reference)
Shorthand to create a for-each quantifier ranging over a reference.static Quantifier.ForEach
forEach(ExpressionRef<? extends RelationalExpression> reference, CorrelationIdentifier alias)
Shorthand to create a for-each quantifier ranging over a reference using a given alias.static Quantifier.ForEach.ForEachBuilder
forEachBuilder()
Create a builder for a for-each quantifier containing relational expressions.CorrelationIdentifier
getAlias()
Set<CorrelationIdentifier>
getCorrelatedTo()
Returns the set ofCorrelationIdentifier
s this entity is correlated to.abstract ExpressionRef<? extends RelationalExpression>
getRangesOver()
Return the reference that the quantifier ranges over.abstract String
getShorthand()
Return a short hand string for the quantifier.int
hashCode()
<Q extends Quantifier>
Qnarrow(Class<Q> narrowedClass)
protected boolean
needsRebase(AliasMap translationMap)
Helper to determine if anything that this quantifier ranges over is correlated to something that needs to be rebased.static Quantifier.Physical
physical(ExpressionRef<? extends RecordQueryPlan> reference)
static Quantifier.Physical
physical(ExpressionRef<? extends RecordQueryPlan> reference, CorrelationIdentifier alias)
static Quantifier.Physical.PhysicalBuilder
physicalBuilder()
Create a builder for a physical quantifier containing record query plans.boolean
semanticEquals(Object other, AliasMap equivalenceMap)
Determine equality with respect to an equivalence map betweenCorrelationIdentifier
s based on semantic equality: equality of the plan fragments implementing under the given correlation bindings.int
semanticHashCode()
Return a semantic hash code for this object.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.apple.foundationdb.record.query.plan.temp.Correlated
rebase
-
-
-
-
Constructor Detail
-
Quantifier
protected Quantifier(@Nonnull CorrelationIdentifier alias)
-
-
Method Detail
-
forEachBuilder
@Nonnull public static Quantifier.ForEach.ForEachBuilder forEachBuilder()
Create a builder for a for-each quantifier containing relational expressions.- Returns:
- a for-each quantifier builder
-
forEach
@Nonnull public static Quantifier.ForEach forEach(@Nonnull ExpressionRef<? extends RelationalExpression> reference)
Shorthand to create a for-each quantifier ranging over a reference.- Parameters:
reference
- the reference- Returns:
- a new for-each quantifier ranging over
reference
-
forEach
@Nonnull public static Quantifier.ForEach forEach(@Nonnull ExpressionRef<? extends RelationalExpression> reference, @Nonnull CorrelationIdentifier alias)
Shorthand to create a for-each quantifier ranging over a reference using a given alias.- Parameters:
reference
- the referencealias
- the alias to be used- Returns:
- a new for-each quantifier ranging over
reference
-
existentialBuilder
@Nonnull public static Quantifier.Existential.ExistentialBuilder existentialBuilder()
Create a builder for an existential quantifier containing relational expressions.- Returns:
- an existential quantifier builder
-
existential
@Nonnull public static Quantifier.Existential existential(@Nonnull ExpressionRef<? extends RelationalExpression> reference)
Shorthand to create an existential quantifier ranging over a reference.- Parameters:
reference
- the reference- Returns:
- a new existential quantifier ranging over
reference
-
existential
@Nonnull public static Quantifier.Existential existential(@Nonnull ExpressionRef<? extends RelationalExpression> reference, @Nonnull CorrelationIdentifier alias)
Shorthand to create an existential quantifier ranging over a reference using a given alias.- Parameters:
reference
- the referencealias
- the alias to be used- Returns:
- a new existential quantifier ranging over
reference
-
physicalBuilder
public static Quantifier.Physical.PhysicalBuilder physicalBuilder()
Create a builder for a physical quantifier containing record query plans.- Returns:
- a physical quantifier builder
-
physical
public static Quantifier.Physical physical(@Nonnull ExpressionRef<? extends RecordQueryPlan> reference)
-
physical
@Nonnull public static Quantifier.Physical physical(@Nonnull ExpressionRef<? extends RecordQueryPlan> reference, @Nonnull CorrelationIdentifier alias)
-
getAlias
@Nonnull public CorrelationIdentifier getAlias()
-
getRangesOver
@Nonnull public abstract ExpressionRef<? extends RelationalExpression> getRangesOver()
Return the reference that the quantifier ranges over.- Returns:
ExpressionRef
this quantifier ranges over
-
getShorthand
@Nonnull public abstract String getShorthand()
Return a short hand string for the quantifier. As a quantifier's semantics is usually quite subtle and should not distract from expressions. For example, when a data flow is visualized the returned string should be short.- Returns:
- a short string representing the quantifier.
-
bindTo
@Nonnull public Stream<PlannerBindings> bindTo(@Nonnull ExpressionMatcher<? extends Bindable> matcher)
Description copied from interface:Bindable
Attempt to match the matcher to this bindable object.
-
acceptPropertyVisitor
@Nullable public <U> U acceptPropertyVisitor(@Nonnull PlannerProperty<U> visitor)
Allow the computation ofPlannerProperty
s across the quantifiers in the data flow graph.- Type Parameters:
U
- the type of the property being computed- Parameters:
visitor
- the planner property that is being computed- Returns:
- the property
-
semanticEquals
public boolean semanticEquals(@Nullable Object other, @Nonnull AliasMap equivalenceMap)
Description copied from interface:Correlated
Determine equality with respect to an equivalence map betweenCorrelationIdentifier
s based on semantic equality: equality of the plan fragments implementing under the given correlation bindings. The contract of this variant ofequals()
differs from its regular Java counterpart. A correlation is mostly just one part inside of composition of objects that expresses a more complicated (correlated) structure such as a filter. For instanceq1.x = 5
uses a correlation toq1
. That entity representing the filter is said to be correlated toq1
. Similarly,q1.x = 6
is a different filter and is not equal under any correlation mapping. In contrast, consider a predicate where everything except the correlation is the same, such asq2.x = 5
. Without a binding, these two filters are not the same. However, the filters may be a part of some other entity that can express correlations:SELECT * FROM T as q1 WHERE q1.x = 5
is equal toSELECT * FROM T as q2 WHERE q2.x = 5
. It does not matter thatq1
andq2
are named differently. It is important, however, that their semantic meaning is the same. In the example bothq1
andq2
refer to a record typeT
which presumably is the same record type. Therefore, these two query blocks are the same, even though they are labelled differently. In the context of this method, we can establish equality betweenq1.x = 5
andq2.x = 5
if we know thatq1
andq2
refer to the same underlying entity. The equivalence map passed in encodes that equality betweenCorrelationIdentifier
s. Note: This method has the same interaction withObject.hashCode()
as the regularequals()
method. As we can only ever establish true equality using equivalence maps,hashCode()
implementations in implementors of this interface must not be dependent on any correlation identifiers used in the structure of the entity. Doing so might violate the fundamental property of hash codes:e1.equals(e2, ...) => e1.hashCode() == e2.hashCode()
- Specified by:
semanticEquals
in interfaceCorrelated<Quantifier>
- Parameters:
other
- the other object to establish equality withequivalenceMap
- a map ofCorrelationIdentifier
sids
toids'
. A correlation identifierid
used inthis
should be considered equal to another correlation identifierid'
used inother
if either they are the same byObject.equals(java.lang.Object)
of if there is a mapping fromid
toid'
.- Returns:
true
if both entities are considered equal using the equivalences passed in,false
otherwise
-
equalsOnKind
public boolean equalsOnKind(Object o)
-
semanticHashCode
public int semanticHashCode()
Description copied from interface:Correlated
Return a semantic hash code for this object. The hash code must obey the convention that for any two objectso1
ando2
and for everyAliasMap
aliasMap
:o1.semanticEquals(o1, aliasMap)
followso1.semanticHash() == o2.semanticHash()
Correlated.semanticEquals(java.lang.Object, com.apple.foundationdb.record.query.plan.temp.AliasMap)
returnstrue
for these two objects the plan fragments are considered to produce the same result under the given correlations bindings. The left sideo1.semanticEquals(o1, aliasMap)
depends on anAliasMap
whileo1.semanticHash() == o2.semanticHash()
does not. Hence, the hash that is computed is identical regardless of possible bindings.- Specified by:
semanticHashCode
in interfaceCorrelated<Quantifier>
- Returns:
- the semantic hash code
-
getCorrelatedTo
@Nonnull public Set<CorrelationIdentifier> getCorrelatedTo()
Description copied from interface:Correlated
Returns the set ofCorrelationIdentifier
s this entity is correlated to. This means that without a process that binds these correlations to values, theRelationalExpression
(or others that implement this interface) cannot even in principle produce a meaningful result. As often times entities that implement this interface use composition and effectively describe trees or DAGs, this method should be the set union of theCorrelationIdentifier
s this object is correlated to as well as all children, constituent parts, etc.- Specified by:
getCorrelatedTo
in interfaceCorrelated<Quantifier>
- Returns:
- the set of
CorrelationIdentifier
s this entity is correlated to
-
needsRebase
protected boolean needsRebase(@Nonnull AliasMap translationMap)
Helper to determine if anything that this quantifier ranges over is correlated to something that needs to be rebased.- Parameters:
translationMap
- a map that expresses translations from correlations identifiers to correlation identifiers.- Returns:
true
if the graph this quantifier ranges over needs to be rebased given the translation map passed in,false
otherwise
-
narrow
@Nonnull public <Q extends Quantifier> Q narrow(@Nonnull Class<Q> narrowedClass)
-
-