Class OSQLFunctionAverage

All Implemented Interfaces:
OSQLFunction

public class OSQLFunctionAverage extends OSQLFunctionMathAbstract
Compute the average value for a field. Uses the context to save the last average number. When different Number class are used, take the class with most precision.
Author:
Luca Garulli (l.garulli--(at)--orientdb.com)
  • Field Details

  • Constructor Details

    • OSQLFunctionAverage

      public OSQLFunctionAverage()
  • Method Details

    • execute

      public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, Object[] iParams, OCommandContext iContext)
      Description copied from interface: OSQLFunction
      Process a record.
      iCurrentRecord - : current record
      iCurrentResult - TODO
      iParams - : function parameters, number is ensured to be within minParams and maxParams.
      iContext - : object calling this function
      Returns:
      function result, can be null. Special cases : can be null if function aggregate results, can be null if function filter results : this mean result is excluded
    • sum

      protected void sum(Number value)
    • getSyntax

      public String getSyntax()
      Description copied from interface: OSQLFunction
      Returns a convenient SQL String representation of the function.

      Example :

        myFunction( param1, param2, [optionalParam3])
       

      This text will be used in exception messages.

      Returns:
      String , never null.
    • getResult

      public Object getResult(OCommandContext ctx)
      Description copied from interface: OSQLFunction
      Only called when function aggregates results after all records have been passed to the function.
      Specified by:
      getResult in interface OSQLFunction
      Overrides:
      getResult in class OSQLFunctionAbstract
      Parameters:
      ctx - TODO
      Returns:
      Aggregation result
    • mergeDistributedResult

      public Object mergeDistributedResult(List<Object> resultsToMerge)
      Description copied from interface: OSQLFunction
      This method correspond to distributed query execution
      Specified by:
      mergeDistributedResult in interface OSQLFunction
      Overrides:
      mergeDistributedResult in class OSQLFunctionAbstract
      Parameters:
      resultsToMerge - is the results that comes from different nodes
      Returns:
      is the valid merged result
    • aggregateResults

      public boolean aggregateResults()
      Description copied from interface: OSQLFunction
      A function can make calculation on several records before returning a result.

      Example of such function : sum, count, max, min ...

      The final result of the aggregation is obtain by calling OSQLFunction.getResult(OCommandContext)

      Specified by:
      aggregateResults in interface OSQLFunction
      Overrides:
      aggregateResults in class OSQLFunctionMathAbstract
      Returns:
      true if function aggregate results