Class ReduceFlux

All Implemented Interfaces:
Expression, HasImports

public final class ReduceFlux extends AbstractParametrizedFlux
Reduce aggregates records in each table according to the reducer. See SPEC.

Options

  • fn - Function to apply to each record with a reducer object of type 'a. [(r: record, accumulator: 'a) -> 'a]
  • identity - an initial value to use when creating a reducer ['a]

Example

 Restrictions restriction = Restrictions.and(
     Restrictions.measurement().equal("cpu"),
     Restrictions.field().equal("usage_system"),
     Restrictions.tag("service").equal("app-server")
 );

 Flux flux = Flux
     .from("telegraf")
     .filter(restriction)
     .range(-12L, ChronoUnit.HOURS)
     .reduce("{ sum: r._value + accumulator.sum }", "{sum: 0.0}");

 Flux flux = Flux
     .from("telegraf")
     .filter(restriction)
     .range(-12L, ChronoUnit.HOURS)
     .reduce()
         .withFunction("{sum: r._value + accumulator.sum,\ncount: accumulator.count + 1.0}")
         .withIdentity("{sum: 0.0, count: 0.0}");
 
Author:
Jakub Bednar (24/02/2020 13:02)
  • Constructor Details

    • ReduceFlux

      public ReduceFlux(@Nonnull Flux source)
  • Method Details

    • operatorName

      @Nonnull protected String operatorName()
      Specified by:
      operatorName in class AbstractParametrizedFlux
      Returns:
      name of function
    • withFunction

      @Nonnull public ReduceFlux withFunction(@Nonnull String function)
      Parameters:
      function - Function to apply to each record. Example: "{sum: r._value + accumulator.sum}".
      Returns:
      this
    • withIdentity

      @Nonnull public ReduceFlux withIdentity(@Nonnull String identity)
      Parameters:
      identity - An initial value to use when creating a reducer. Example: "{sum: 0.0}".
      Returns:
      this
    • collectImports

      public void collectImports(@Nonnull Set<String> collectedImports)
      Description copied from class: Flux
      Collects all imports of the flux.
      Overrides:
      collectImports in class Flux
      Parameters:
      collectedImports - a set to be filled by the used imports