Interface Element
-
- All Superinterfaces:
Correlated<Element>
,PlanHashable
- All Known Implementing Classes:
FieldElement
,LiteralElement
,RecordTypeElement
,ValueElement
,VersionElement
@API(EXPERIMENTAL) public interface Element extends PlanHashable, Correlated<Element>
A value in theViewExpression
language that can be represented as an element of FoundationDB tuple.An element is the atom of a FoundationDB tuple, and therefore has a representation as a byte string with a defined total order (i.e., an order where
a <= b
andb <= a
implies thata == b
, and where eithera <= b
orb <= a
). Elements generate the values that can be used to define the projection, predicate, sort order, or grouping of a view expression. Since elements must be usable in FoundationDB tuples, they are also the fundamental unit of key planning operations such as incremental index selection. Many, but not all, elements reference aSource
which identifies what streams of data will generate them.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description 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.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
.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.-
Methods inherited from interface com.apple.foundationdb.record.query.plan.temp.Correlated
getCorrelatedTo, rebase, semanticEquals, semanticHashCode
-
Methods inherited from interface com.apple.foundationdb.record.PlanHashable
planHash
-
-
-
-
Method Detail
-
matchWith
@Nonnull Optional<ComparisonRange> matchWith(@Nonnull ComparisonRange existingComparisons, @Nonnull 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
. Note that this method relies on strict comparisons between elements, i.e., the sources must be reference-equal to each other.- 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 Optional<ViewExpressionComparisons> matchSourcesWith(@Nonnull ViewExpressionComparisons viewExpressionComparisons, @Nonnull Element 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,matchWith(ComparisonRange, ElementPredicate)
will fail to notice when an index defined by aKeyExpression
can support a predicate.- 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
-
getAncestralSources
@Nonnull Set<Source> getAncestralSources()
Get the set of all sources for this element, including all ancestors of this element's sources.- Returns:
- a set of the sources of all (inclusive) ancestors of this element's sources
-
withSourceMappedInto
@Nonnull Element withSourceMappedInto(@Nonnull Source originalSource, @Nonnull 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.- 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 Object eval(@Nonnull SourceEntry sourceEntry)
Evaluate this element with respect to the given source entry, producing an object that can be interpreted by aComparisons.Comparison
.- Parameters:
sourceEntry
- a source entry to use when evaluating this element- Returns:
- the value of this element on the given source entry
-
-