As written at the bottom in this page http://orientdb.com/docs/2.0/orientdb.wiki/SQL-Functions.html , we can build our custom function in OrientDB. However, this example just shows a custom function to perform an inline operation. Is there any way to write an OrientDB function that performs an aggregation operation? Something like sum(fieldName) . So the question is more towards how we can access the 'current' record value for that field inside our custom function so that we can perform an aggregation operation.
I suggest you to take a look at this: OSQLFunctionSum
The code is quite simple, but the important concepts are following:
aggregateResults()
has to return true
to let OrientDB know that it's an aggregate functionprivate Number sum;
in the example)execute()
method is invoked for every record, during querygetResult()
must return the aggregate result