Class AggregationSet

java.lang.Object
com.gigaspaces.query.aggregators.AggregationSet
All Implemented Interfaces:
SmartExternalizable, Externalizable, Serializable

public class AggregationSet extends Object implements SmartExternalizable
The set of aggregations to run for matches entries of the aggregate operation.
Since:
10.0
Author:
Niv Ingberg
See Also:
  • Constructor Details

    • AggregationSet

      public AggregationSet()
  • Method Details

    • withExecutionTimeout

      public AggregationSet withExecutionTimeout(long timeout, TimeUnit unit)
      Limits how long the aggregation may run. A partition that is still scanning when the timeout expires stops and fails the aggregation with an AggregationTimeoutException; the caller stops waiting shortly after the timeout even if a partition does not answer. Without this setting the space's default applies ("com.gs.aggregation.default-timeout-ms"), which is no limit unless configured. A value set here replaces the default, whether it is shorter or longer.

      This bounds the execution of the aggregation. It is unrelated to the timeout of read and take operations, which is how long to wait for a matching entry to appear.

      A partition checks the timeout between the entries it scans or the index entries it walks. What it hands to tiered storage as one SQL statement, and a single call to a custom aggregator's aggregate(), are checked when they return: until then they keep their partition busy. The caller is still released on time, except from a space it reaches directly in its own JVM, where the aggregation runs on the caller's thread.

      Unless it runs on the caller's thread, the aggregation runs on copies of the aggregators, so that a partition that answers after the caller stopped waiting does not write into the caller's ones. The copies are made with SpaceEntriesAggregator.clone(), which copies an aggregator's fields but not the objects they refer to: a custom aggregator therefore creates its mutable state lazily, in aggregate() and aggregateIntermediateResult() as the built-in ones do, or overrides clone() to copy it. State it creates up front, such as a list assigned where the field is declared, is shared with the copies.

      The caller's wait covers the aggregation, not finding a partition to send it to. When the proxy knows no active member of a partition - for instance when it reaches the space for the first time while that partition is down - the call first waits for one, as any space operation does, for up to the proxy's space-config.proxy.router.active-server-lookup-timeout, 20 seconds by default.

      Parameters:
      timeout - the maximum execution time, greater than zero
      unit - the unit of timeout
      Returns:
      this aggregation set
      Since:
      18.0.1
    • getExecutionTimeout

      public long getExecutionTimeout()
      Returns:
      the execution timeout set by withExecutionTimeout(long, TimeUnit), in milliseconds, or 0 if none was set
      Since:
      18.0.1
    • add

      public AggregationSet add(SpaceEntriesAggregator aggregator)
    • count

      public AggregationSet count()
      Counts matching entries.
    • count

      public AggregationSet count(String path)
      Counts matching entries whose path is not null.
      Parameters:
      path - Path to inspect
    • sum

      public AggregationSet sum(String path)
      Sums values of paths of matching entries, infers the return type of the path.
      Parameters:
      path - Path to sum (must be a numeric type)
    • average

      public AggregationSet average(String path)
      Calculates average of path values of matching entries, infers the return type of the path.
      Parameters:
      path - Path to average (must be a numeric type)
    • maxValue

      public AggregationSet maxValue(String path)
      Returns maximum value of path of matching entries.
      Parameters:
      path - Path to inspect (must be a comparable type)
      See Also:
    • maxEntry

      public AggregationSet maxEntry(String path)
      Returns entry with maximum value of path of matching entries.
      Parameters:
      path - Path to inspect (must be a comparable type)
      See Also:
    • minValue

      public AggregationSet minValue(String path)
      Returns minimum value of path of matching entries.
      Parameters:
      path - Path to inspect (must be a comparable type)
      See Also:
    • minEntry

      public AggregationSet minEntry(String path)
      Returns entry with minimum value of path of matching entries.
      Parameters:
      path - Path to inspect (must be a comparable type)
      See Also:
    • groupBy

      public AggregationSet groupBy(GroupByAggregator aggregator)
    • orderBy

      public AggregationSet orderBy(OrderByAggregator aggregator)
    • distinct

      public AggregationSet distinct(DistinctAggregator aggregator)
    • getAggregators

      public List<SpaceEntriesAggregator> getAggregators()
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • containsOrderByAggregator

      public boolean containsOrderByAggregator()