Class FeatureStream

All Implemented Interfaces:
AutoCloseable, BaseStream<AbstractFeature,Stream<AbstractFeature>>, Stream<AbstractFeature>

final class FeatureStream extends DeferredStream<AbstractFeature>
A stream of Feature instances from a table. This implementation intercepts some Stream method calls such as count(), distinct(), skip(long) and limit(long) in order to delegate the operation to the underlying SQL database.

Optimization strategies are also propagated to streams obtained using map(Function) and StreamWrapper.mapToDouble(ToDoubleFunction). However, for result consistency, no optimization is stacked anymore after either filter(Predicate) or StreamWrapper.flatMap(Function) operations are called, because they modify volumetry (the count of stream elements is not bound 1 to 1 to query result rows).

Since:
1.1
Version:
1.1
  • Field Details

    • table

      private final Table table
      The table which is the source of features.
    • filterToSQL

      private SelectionClauseWriter filterToSQL
      The visitor to use for converting filters/expressions to SQL statements. This is used for writing the content of the SelectionClause. It is usually a singleton instance shared by all databases. It is fetched when first needed.
    • selection

      private SelectionClause selection
      The SQL fragment on the right side of the WHERE keyword. This buffer does not including the WHERE keyword. It is created when first needed and discarded after the iterator is created.
    • hasPredicates

      private boolean hasPredicates
      true if at least one predicate given to filter(Predicate) is implemented using Java code instead of using SQL statements.
    • hasComparator

      private boolean hasComparator
      true if at least one comparator given to sorted(Comparator) is implemented using Java code instead of using SQL statements.
    • distinct

      private boolean distinct
      Whether all returned feature instances should be unique.
    • sort

      private SortBy<? super AbstractFeature> sort
      The ORDER BY clauses, or null if none.
    • offset

      private long offset
      Number of rows to skip in underlying SQL query, or 0 for none.
      See Also:
    • count

      private long count
      Maximum number of rows to return, or 0 for no limit. Note that 0 is a valid value for the limit, but when this value is reached the empty() stream should be immediately returned.
      See Also:
  • Constructor Details

    • FeatureStream

      FeatureStream(Table table, boolean parallel)
      Creates a new stream of features.
      Parameters:
      table - the source table.
      parallel - whether the stream should be initially parallel.
  • Method Details