Class FieldElement

  • All Implemented Interfaces:
    PlanHashable, Correlated<Element>, Element

    @API(EXPERIMENTAL)
    public class FieldElement
    extends Object
    An element that extracts a single, non-repeated field (at an arbitrary nesting depth) from a source.

    Note that while nested fields can be referenced from a single FieldElement, repeated fields cannot because they define their own stream of data values, which must be represented by a RepeatedFieldSource.

    • Method Detail

      • withSourceMappedInto

        @Nonnull
        public FieldElement 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.
        Parameters:
        originalSource - a source to replace all occurrences of the duplicate source with
        duplicateSource - 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
      • 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 given ElementPredicate, under the assumption that this element is already being used to satisfy the given ComparisonRange. 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 support
        predicate - 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 given Element when unused sources are combined with each other. Sources are determined to be used or unused based on their usage in the given ViewExpressionComparisons. 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 given ViewExpressionComparisons with all instances of this element's source replaced with the given element's source.

        This method makes it possible to match ElementPredicates generated by normalizing a QueryComponent with those generated by normalizing a KeyExpression. 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 a KeyExpression can support a predicate.

        Parameters:
        viewExpressionComparisons - view expression comparisons that determine which sources are used and unused
        element - 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
      • 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 a Comparisons.Comparison.
        Parameters:
        sourceEntry - a source entry to use when evaluating this element
        Returns:
        the value of this element on the given source entry
      • 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 objects o1 and o2 and for every AliasMap aliasMap:
         o1.semanticEquals(o1, aliasMap) follows o1.semanticHash() == o2.semanticHash()
         
        If the semantic hash code of two implementing objects is equal and Correlated.semanticEquals(java.lang.Object, com.apple.foundationdb.record.query.plan.temp.AliasMap) returns true for these two objects the plan fragments are considered to produce the same result under the given correlations bindings. The left side o1.semanticEquals(o1, aliasMap) depends on an AliasMap while o1.semanticHash() == o2.semanticHash() does not. Hence, the hash that is computed is identical regardless of possible bindings.
        Returns:
        the semantic hash code
      • planHash

        public int planHash()
        Description copied from interface: PlanHashable
        Return a hash similar to hashCode, but with the additional guarantee that is is stable across JVMs.
        Returns:
        a stable hash code
      • rebase

        @Nonnull
        public FieldElement 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.
        Parameters:
        translationMap - a map defining a translation from CorrelationIdentifiers ids to CorrelationIdentifiers ids'. After the rebase, every correlation to an id contained ids that is contained or referred to directly or indirectly by this must have been transformed to use the mapped counterpart of id id' in ids'. IDs not contained in the translation map must remain unmodified by the rebase operation.
        Returns:
        a new entity that has been rebased
      • getAncestralSources

        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 interface Element
        Returns:
        a set of the sources of all (inclusive) ancestors of this element's sources
      • getCorrelatedTo

        @Nonnull
        public Set<CorrelationIdentifier> getCorrelatedTo()
        Description copied from interface: Correlated
        Returns the set of CorrelationIdentifiers this entity is correlated to. This means that without a process that binds these correlations to values, the RelationalExpression (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 the CorrelationIdentifiers this object is correlated to as well as all children, constituent parts, etc.
        Specified by:
        getCorrelatedTo in interface Correlated<Element>
        Returns:
        the set of CorrelationIdentifiers this entity is correlated to
      • semanticEquals

        public boolean semanticEquals​(@Nullable
                                      Object other,
                                      @Nonnull
                                      AliasMap equivalenceMap)
        Description copied from interface: Correlated
        Determine equality with respect to an equivalence map between CorrelationIdentifiers based on semantic equality: equality of the plan fragments implementing under the given correlation bindings. The contract of this variant of equals() 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 instance q1.x = 5 uses a correlation to q1. That entity representing the filter is said to be correlated to q1. 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 as q2.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 to SELECT * FROM T as q2 WHERE q2.x = 5. It does not matter that q1 and q2 are named differently. It is important, however, that their semantic meaning is the same. In the example both q1 and q2 refer to a record type T 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 between q1.x = 5 and q2.x = 5 if we know that q1 and q2 refer to the same underlying entity. The equivalence map passed in encodes that equality between CorrelationIdentifiers. Note: This method has the same interaction with Object.hashCode() as the regular equals() 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 interface Correlated<Element>
        Parameters:
        other - the other object to establish equality with
        equivalenceMap - a map of CorrelationIdentifiers ids to ids'. A correlation identifier id used in this should be considered equal to another correlation identifier id' used in other if either they are the same by Object.equals(java.lang.Object) of if there is a mapping from id to id'.
        Returns:
        true if both entities are considered equal using the equivalences passed in, false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object