Class DistinctIterable<T,F>

java.lang.Object
com.datastax.astra.client.model.PageableIterable<T>
com.datastax.astra.client.model.DistinctIterable<T,F>
Type Parameters:
T - type of the document used in the associated collection.
F - type of the field we are looping on.
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<F>

public class DistinctIterable<T,F> extends PageableIterable<T> implements Iterable<F>
Iterator to get all distinct value for a particular field.
  • Field Details

    • currentPageIterator

      protected DistinctIterator<T,F> currentPageIterator
      Iterator on fields.
  • Constructor Details

    • DistinctIterable

      public DistinctIterable(Collection<T> collection, String fieldName, Filter filter, Class<F> fieldClass)
      Constructs an iterable that provides distinct elements from a specified collection, optionally filtered by a given criterion. This iterable allows for iterating over unique values of a specific field within the collection's documents, which can be particularly useful for data analysis, reporting, or implementing specific business logic that requires uniqueness in the dataset.

      The distinct elements are determined based on the fieldName parameter, ensuring that each value provided during iteration is unique with respect to this field across all documents in the collection. The filter parameter allows for narrowing down the documents considered by this iterable, offering the capability to perform more targeted queries.

      Parameters:
      collection - The source collection client, used to fetch documents and, if necessary, subsequent pages of results. This collection should be capable of executing queries and returning filtered results.
      fieldName - The name of the field for which unique values are to be iterated over. This field's values are used to determine the distinctness of elements provided by this iterable.
      filter - The original filter used to limit the documents considered for finding distinct values. This filter allows for the specification of criteria that documents must meet to be included in the iteration.
      fieldClass - The class of the field values being iterated over. This parameter is used to ensure type safety and proper casting of the field values extracted from the documents in the collection.
  • Method Details

    • iterator

      @NonNull public @NonNull DistinctIterator<T,F> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • all

      public List<F> all()
      Will exhaust the list and put all value in memory.
      Returns:
      all values of the iterable