Class LiteralElement<T>
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.view.LiteralElement<T>
-
- Type Parameters:
T
- the type of the static value
- All Implemented Interfaces:
PlanHashable
,Correlated<Element>
,Element
public class LiteralElement<T> extends Object implements Element
A value representing a single, static value of typeT
.
-
-
Constructor Summary
Constructors Constructor Description LiteralElement(T value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Object
eval(SourceEntry sourceEntry)
Evaluate this element with respect to the given source entry, producing an object that can be interpreted by aComparisons.Comparison
.Set<Source>
getAncestralSources()
Get the set of all sources for this element, including all ancestors of this element's sources.Set<CorrelationIdentifier>
getCorrelatedTo()
Returns the set ofCorrelationIdentifier
s this entity is correlated to.int
hashCode()
Optional<ViewExpressionComparisons>
matchSourcesWith(ViewExpressionComparisons viewExpressionComparisons, Element element)
Determine whether this element is the same as the givenElement
when unused sources are combined with each other.Optional<ComparisonRange>
matchWith(ComparisonRange existingComparisons, ElementPredicate predicate)
Determine whether this element can be used to satisfy the givenElementPredicate
, under the assumption that this element is already being used to satisfy the givenComparisonRange
.int
planHash()
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.Element
rebase(AliasMap translationMap)
Rebases this and all other objects this objects is composed of using a given translation map.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.Element
withSourceMappedInto(Source originalSource, Source duplicateSource)
Replace the given duplicate source with the given original source everywhere that it occurs in this element, including in ancestor sources of this element's source.
-
-
-
Method Detail
-
getAncestralSources
@Nonnull public Set<Source> getAncestralSources()
Description copied from interface:Element
Get the set of all sources for this element, including all ancestors of this element's sources.- Specified by:
getAncestralSources
in interfaceElement
- Returns:
- a set of the sources of all (inclusive) ancestors of this element's sources
-
matchWith
@Nonnull public Optional<ComparisonRange> matchWith(@Nonnull ComparisonRange existingComparisons, @Nonnull ElementPredicate predicate)
Description copied from interface:Element
Determine whether this element can be used to satisfy the givenElementPredicate
, under the assumption that this element is already being used to satisfy the givenComparisonRange
. Note that this method relies on strict comparisons between elements, i.e., the sources must be reference-equal to each other.- Specified by:
matchWith
in interfaceElement
- Parameters:
existingComparisons
- a range of existing comparisons that the planner is using this element to supportpredicate
- an element predicate to match with this element and the given comparison range- Returns:
- a new comparison range incorporating the predicate's comparison if the match was successful,
Optional.empty()
otherwise
-
matchSourcesWith
@Nonnull public Optional<ViewExpressionComparisons> matchSourcesWith(@Nonnull ViewExpressionComparisons viewExpressionComparisons, @Nonnull Element element)
Description copied from interface:Element
Determine whether this element is the same as the givenElement
when unused sources are combined with each other. Sources are determined to be used or unused based on their usage in the givenViewExpressionComparisons
. A source is used if any element using that source has a comparison already matched to it; otherwise, it is unused. If an available match is found, produce a version of the givenViewExpressionComparisons
with all instances of this element's source replaced with the given element's source.This method makes it possible to match
ElementPredicate
s generated by normalizing aQueryComponent
with those generated by normalizing aKeyExpression
. These normalization processes are decoupled so the sources for each will not match in general; therefore,Element.matchWith(ComparisonRange, ElementPredicate)
will fail to notice when an index defined by aKeyExpression
can support a predicate.- Specified by:
matchSourcesWith
in interfaceElement
- Parameters:
viewExpressionComparisons
- view expression comparisons that determine which sources are used and unusedelement
- an element to compare with this one and look for matches made through combining sources- Returns:
- a new view expression comparisons with instances of this element's source replaced with the given element's
if a match is found,
Optional.empty()
otherwise
-
withSourceMappedInto
@Nonnull public Element withSourceMappedInto(@Nonnull Source originalSource, @Nonnull Source duplicateSource)
Description copied from interface:Element
Replace the given duplicate source with the given original source everywhere that it occurs in this element, including in ancestor sources of this element's source.- Specified by:
withSourceMappedInto
in interfaceElement
- Parameters:
originalSource
- a source to replace all occurrences of the duplicate source withduplicateSource
- a source to replace with the original source- Returns:
- a copy of this element with all occurrences of the duplicate source replaced with the original source
-
eval
@Nullable public Object eval(@Nonnull SourceEntry sourceEntry)
Description copied from interface:Element
Evaluate this element with respect to the given source entry, producing an object that can be interpreted by aComparisons.Comparison
.
-
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<T>
- 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
-
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<T>
- Returns:
- the semantic hash code
-
planHash
public int planHash()
Description copied from interface:PlanHashable
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.- Specified by:
planHash
in interfacePlanHashable
- Returns:
- a stable 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<T>
- Returns:
- the set of
CorrelationIdentifier
s this entity is correlated to
-
rebase
@Nonnull public Element rebase(@Nonnull AliasMap translationMap)
Description copied from interface:Correlated
Rebases this and all other objects this objects is composed of using a given translation map.- Specified by:
rebase
in interfaceCorrelated<T>
- Parameters:
translationMap
- a map defining a translation fromCorrelationIdentifier
sids
toCorrelationIdentifier
sids'
. After the rebase, every correlation to anid
containedids
that is contained or referred to directly or indirectly bythis
must have been transformed to use the mapped counterpart ofid
id'
inids'
. IDs not contained in the translation map must remain unmodified by the rebase operation.- Returns:
- a new entity that has been rebased
-
-