src/Query/Query.php
/**
   * Apply a reducer function on grouping aggregation. Has no effect if no grouping was used
   * @arg string $alias reducer's alias
   * @arg string $type_readable a readable name of function, e.g. "first value", "tolist"
   * @arg array $arguments an array of arguments for reducer function
   *
   * @param array $reducers
   *
   * @return object this object
   */
Apply a reducer function on grouping aggregation. Has no effect if no grouping was used
@arg string $alias reducer's alias
@arg string $type_readable a readable name of function, e.g. "first value", "tolist"
@arg array $arguments an array of arguments for reducer function

@param array $reducers

@return object this object
Apply a reducer function on grouping aggregation . Has no effect if no grouping was used @arg string $alias reducer ' s alias @arg string $type_readable a readable name of function e . g . " first value " " tolist " @arg array $arguments an array of arguments for reducer function @param array $reducers @return object this object
public function reduce( array $reducers ) {
    $valid_reducers = [
      'COUNT',   'COUNT_DISTINCT',  'COUNT_DISTINCTISH',
      'SUM',     'MIN',             'MAX',
      'AVG',     'STDDEV',          'QUANTILE',
      'TOLIST',  'FIRST_VALUE',     'RANDOM_SAMPLE'
    ];
    $reducers_parsed = [];
    foreach ( $reducers as $alias => $reducer_data ) {
      $type_readable = array_shift($reducer_data);
      $type = mb_strtoupper(str_replace(' ', '_', $type_readable));
      if ( in_array($type, $valid_reducers) ) {
        $reducer_data = array_map(function($a) { return "@$a"; }, $reducer_data);
        array_unshift($reducer_data, count($reducer_data));
        $reducer = "$type " . implode(' ', $reducer_data);
        if (!preg_match('/^[0-9]+^/', $alias)) {
          $reducer .= " AS $alias";
        }
        $reducers_parsed[] = $reducer;
      } else {
        throw new BadMethodCallException("Unknown reducer: $type_readable");
      }
    }
    $this->reduce = 'REDUCE ' . implode(' ', $reducers_parsed);
    return $this;
  }
public function reduce ( array $ reducers ) { $ valid_reducers = [ 'COUNT' , 'COUNT_DISTINCT' , 'COUNT_DISTINCTISH' , 'SUM' , 'MIN' , 'MAX' , 'AVG' , 'STDDEV' , 'QUANTILE' , 'TOLIST' , 'FIRST_VALUE' , 'RANDOM_SAMPLE' ] ; $ reducers_parsed = [ ] ; foreach ( $ reducers as $ alias => $ reducer_data ) { $ type_readable = array_shift ( $ reducer_data ) ; $ type = mb_strtoupper ( str_replace ( ' ' , '_' , $ type_readable ) ) ; if ( in_array ( $ type , $ valid_reducers ) ) { $ reducer_data = array_map ( function ( $ a ) { return " @ $ a " ; } , $ reducer_data ) ; array_unshift ( $ reducer_data , count ( $ reducer_data ) ) ; $ reducer = " $ type " . implode ( ' ' , $ reducer_data ) ; if ( ! preg_match ( '/^[0-9]+^/' , $ alias ) ) { $ reducer .= "  AS  $ alias " ; } $ reducers_parsed [ ] = $ reducer ; } else { throw new BadMethodCallException ( " Unknown reducer:  $ type_readable " ) ; } } $ this -> reduce = 'REDUCE ' . implode ( ' ' , $ reducers_parsed ) ; return $ this ; }
Apply a reducer function on grouping aggregation.
Apply a reducer function on grouping aggregation .
// name supplied must be redis-compatible // only non-numeric keys are aliases // apply joined reducers to object's field