Class Source

  • Direct Known Subclasses:
    RecordTypeSource, RepeatedFieldSource

    @API(EXPERIMENTAL)
    public abstract class Source
    extends Object
    A source represents a stream of entities that can be used to generate Elements, such as records or field values.

    Sources can stand alone or be derived from other sources. By combining sources, complex streams of values derived from stored information can be described and manipulated. For example:

    • A RecordTypeSource represents the stream of all records of a particular record type.
    • A RepeatedFieldSource represents the stream of all (nested) values in a repeated field of a record.

    Generally, a query or ViewExpression has a "root" source. This root source is not derived from another source and defines a stream of entries from which all other sources are derived.

    A source encapsulates the logic for generating and combining streams of data. For example, if there are two RepeatedFieldSources derived from the same RecordTypeSource, the source encapsulates the implicit Cartesian product between the two. Similarly, it encapsulates the logic for checking whether or not a particular source has already been "used up" by the query planner.

    See Also:
    Element, ViewExpression
    • Constructor Detail

      • Source

        public Source()
    • Method Detail

      • getSources

        public abstract Set<Source> getSources()
        Get the set of all sources of ancestor's of this source, include this source itself.
        Returns:
        a set of the sources of all (inclusive) ancestors of this source
      • addDependentSource

        public void addDependentSource​(@Nonnull
                                       Source source)
      • supportsSourceIn

        public abstract boolean supportsSourceIn​(@Nonnull
                                                 ViewExpressionComparisons comparisons,
                                                 @Nonnull
                                                 Source other)
        Check whether this source can be replaced by the given source in the given ViewExpressionComparisons. In general, this source can be replaced by the given source if and only if:
        • The sources match each other "structurally" (i.e., differ only in a pointer-equality sense).
        • The elements with comparisons in the ViewExpressionComparisons do not use this source.
        Parameters:
        comparisons - a view expression comparisons that specifies which sources are used and unused
        other - a candidate replacement for this source
        Returns:
        whether this source can be replaced by other
        See Also:
        withSourceMappedInto(Source, Source), Element.matchSourcesWith(ViewExpressionComparisons, Element)
      • withSourceMappedInto

        @Nonnull
        public abstract Source withSourceMappedInto​(@Nonnull
                                                    Source originalSource,
                                                    @Nonnull
                                                    Source duplicateSource)
        Replace the given duplicate source with the given original source everywhere that it occurs in this source, including in ancestor sources.
        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 source with all occurrences of the duplicate source replaced with the original source
      • evalSourceEntriesFor

        @Nonnull
        protected abstract Stream<SourceEntry> evalSourceEntriesFor​(@Nonnull
                                                                    SourceEntry entry)
        Produce the stream of source entries that this source represents, drawing the values for dependent sources from the given source entry if needed.
        Parameters:
        entry - a source entry to draw the input for this source from
        Returns:
        a stream of source entries, each of which has a value associated with this source
      • evalSourceEntriesFor

        public final Stream<SourceEntry> evalSourceEntriesFor​(@Nonnull
                                                              MessageOrBuilder message)
        Produce the stream of source entries that this source represents, drawing the value for the input of this source from the given MessageOrBuilder.
        Parameters:
        message - a message to use when evaluating this source
        Returns:
        a stream of source entries, each of which has a value associated with this source
      • equals

        public final boolean equals​(Object other)
        Override of equality to ensure that sources are compared using reference equality.
        Overrides:
        equals in class Object
        Parameters:
        other - the other object
        Returns:
        whether the two objects are the same object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object