Class UnionDataSource

java.lang.Object
org.apache.druid.query.UnionDataSource
All Implemented Interfaces:
Cacheable, DataSource

public class UnionDataSource extends Object implements DataSource
Reperesents a UNION ALL of two or more datasources.

Native engine can only work with table datasources that are scans or simple mappings (column rename without any expression applied on top). Therefore, it uses methods like getTableNames() and isTableBased() to assert that the children were TableDataSources.

MSQ should be able to plan and work with arbitrary datasources. It also needs to replace the datasource with the InputNumberDataSource while preparing the query plan.

  • Constructor Details

    • UnionDataSource

      public UnionDataSource(List<DataSource> dataSources)
  • Method Details

    • getTableNames

      public Set<String> getTableNames()
      Asserts that the children of the union are all table data sources before returning the table names
      Specified by:
      getTableNames in interface DataSource
    • isTableBased

      public boolean isTableBased()
      Returns true if this datasource can be ran by the native engine, i.e. all the children of the union are table datasource or restricted datasource.
    • getChildren

      public List<DataSource> getChildren()
      Description copied from interface: DataSource
      Returns datasources that this datasource depends on. Will be empty for leaf datasources like 'table'.
      Specified by:
      getChildren in interface DataSource
    • withChildren

      public DataSource withChildren(List<DataSource> children)
      Description copied from interface: DataSource
      Return a new DataSource, identical to this one, with different children. The number of children must be equal to the number of children that this datasource already has.
      Specified by:
      withChildren in interface DataSource
    • isCacheable

      public boolean isCacheable(boolean isBroker)
      Description copied from interface: DataSource
      Returns true if queries on this dataSource are cacheable at both the result level and per-segment level. Currently, dataSources that do not actually reference segments (like 'inline'), are not cacheable since cache keys are always based on segment identifiers.
      Specified by:
      isCacheable in interface DataSource
    • isGlobal

      public boolean isGlobal()
      Description copied from interface: DataSource
      Decides if this datasource can be accessed globally.

      This means that all servers have a full copy of this datasource.

      Examples: inline table, lookup.

      Specified by:
      isGlobal in interface DataSource
    • isProcessable

      public boolean isProcessable()
      Description copied from interface: DataSource
      Communicates that this DataSource can be directly used to run a Query.

      A Processable datasource must pack the necessary logic into the DataSource.createSegmentMapFunction(Query).

      Processable examples are: TableDataSource, InlineDataSource, FilteredDataSource. Non-processable ones are those which need further pre-processing before running them. examples are: QueryDataSource and join which are not supported directly.

      Specified by:
      isProcessable in interface DataSource
    • createSegmentMapFunction

      public SegmentMapFunction createSegmentMapFunction(Query query)
      Description copied from interface: DataSource
      Returns a segment function on to how to segment should be modified.
      Specified by:
      createSegmentMapFunction in interface DataSource
    • getCacheKey

      public byte[] getCacheKey()
      Description copied from interface: DataSource
      Compute a cache key prefix for a data source. This includes the data sources that participate in the RHS of a join as well as any query specific constructs associated with join data source such as base table filter. This key prefix can be used in segment level cache or result level cache. The function can return following - Non-empty byte array - If there is join datasource involved and caching is possible. The result includes join condition expression, join type and cache key returned by joinable factory for each PreJoinableClause - NULL - There is a join but caching is not possible. It may happen if one of the participating datasource in the JOIN is not cacheable.
      Specified by:
      getCacheKey in interface Cacheable
      Specified by:
      getCacheKey in interface DataSource
      Returns:
      the cache key to be used as part of query cache key
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isCompatibleDataSource

      public static boolean isCompatibleDataSource(DataSource dataSource)