DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | List of all members
Deveel.Data.Routines.AggregateFunction Class Referenceabstract
Inheritance diagram for Deveel.Data.Routines.AggregateFunction:
Deveel.Data.Routines.Function Deveel.Data.Routines.IFunction Deveel.Data.Routines.IRoutine Deveel.Data.Sql.IDbObject

Public Member Functions

override InvokeResult Execute (InvokeContext context)
 Executes the function and provides a result. More...
 
- Public Member Functions inherited from Deveel.Data.Routines.Function
SqlType ReturnType ()
 Gets the function static return type More...
 
virtual SqlType ReturnType (InvokeContext context)
 Resolves the function return type against the given context. More...
 

Protected Member Functions

 AggregateFunction (ObjectName name, RoutineParameter[] parameters, SqlType returnType)
 
abstract DataObject Evaluate (DataObject value1, DataObject value2, IRequest query, IGroupResolver group)
 
virtual DataObject PostEvaluate (DataObject result, IRequest query, IGroupResolver group)
 
- Protected Member Functions inherited from Deveel.Data.Routines.Function
 Function (FunctionInfo functionInfo)
 
 Function (ObjectName name, RoutineParameter[] parameters, FunctionType functionType)
 
 Function (ObjectName name, RoutineParameter[] parameters, SqlType returnType)
 
 Function (ObjectName name, RoutineParameter[] parameters, SqlType returnType, FunctionType functionType)
 

Additional Inherited Members

- Static Public Attributes inherited from Deveel.Data.Routines.Function
static readonly SqlType DynamicType = new DynamicSqlType()
 A special SqlType that is used to mark an argument of a function as dynamic. More...
 
- Properties inherited from Deveel.Data.Routines.Function
FunctionType FunctionType [get]
 
FunctionInfo FunctionInfo [get, private set]
 
ObjectName FunctionName [get]
 
RoutineInfo IRoutine. RoutineInfo [get]
 
RoutineType IRoutine. Type [get]
 
DbObjectType IDbObject. ObjectType [get]
 
ObjectName IDbObject. FullName [get]
 
- Properties inherited from Deveel.Data.Routines.IFunction
FunctionType FunctionType [get]
 Gets the type of function. More...
 
- Properties inherited from Deveel.Data.Routines.IRoutine
RoutineType Type [get]
 Gets the type of routine that will be executed. More...
 
RoutineInfo RoutineInfo [get]
 
- Properties inherited from Deveel.Data.Sql.IDbObject
ObjectName FullName [get]
 Gets the fully qualified name of the object used to resolve it uniquely within the database. More...
 
DbObjectType ObjectType [get]
 Gets the type of database object that the implementation is for More...
 

Detailed Description

Definition at line 25 of file AggregateFunction.cs.

Constructor & Destructor Documentation

Deveel.Data.Routines.AggregateFunction.AggregateFunction ( ObjectName  name,
RoutineParameter[]  parameters,
SqlType  returnType 
)
inlineprotected

Definition at line 26 of file AggregateFunction.cs.

27  : base(name, parameters, returnType, FunctionType.Aggregate) {
28  }

Member Function Documentation

abstract DataObject Deveel.Data.Routines.AggregateFunction.Evaluate ( DataObject  value1,
DataObject  value2,
IRequest  query,
IGroupResolver  group 
)
protectedpure virtual
override InvokeResult Deveel.Data.Routines.AggregateFunction.Execute ( InvokeContext  context)
inlinevirtual

Executes the function and provides a result.

Parameters
contextThe context of the execution.
Returns
Returns a InvokeResult instance that encapsulates the returned value of the function.
See also
InvokeResult.ReturnValue

Implements Deveel.Data.Routines.Function.

Definition at line 37 of file AggregateFunction.cs.

37  {
38  if (context == null)
39  throw new ArgumentNullException("context");
40 
41  var group = context.GroupResolver;
42 
43  if (group == null)
44  throw new Exception(String.Format("'{0}' can only be used as an aggregate function.", FunctionName));
45 
46  DataObject result = null;
47  // All aggregates functions return 'null' if group size is 0
48  int size = group.Count;
49  if (size == 0) {
50  // Return a NULL of the return type
51  return context.Result(DataObject.Null(ReturnType(context)));
52  }
53 
54  DataObject val;
55  ObjectName v = context.Arguments[0].AsReferenceName();
56  // If the aggregate parameter is a simple variable, then use optimal
57  // routine,
58  if (v != null) {
59  for (int i = 0; i < size; ++i) {
60  val = group.Resolve(v, i);
61  result = Evaluate(result, val, context.Request, group);
62  }
63  } else {
64  // Otherwise we must resolve the expression for each entry in group,
65  // This allows for expressions such as 'sum(quantity * price)' to
66  // work for a group.
67  var exp = context.Arguments[0];
68  for (int i = 0; i < size; ++i) {
69  val = exp.EvaluateToConstant(context.Request, group.GetVariableResolver(i));
70  result = Evaluate(result, val, context.Request, group);
71  }
72  }
73 
74  // Post method.
75  result = PostEvaluate(result, context.Request, group);
76 
77  return context.Result(result);
78  }
A long string in the system.
static DataObject Null(SqlType type)
Definition: DataObject.cs:630
Describes the name of an object within a database.
Definition: ObjectName.cs:44
virtual DataObject PostEvaluate(DataObject result, IRequest query, IGroupResolver group)
abstract DataObject Evaluate(DataObject value1, DataObject value2, IRequest query, IGroupResolver group)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
SqlType ReturnType()
Gets the function static return type
Definition: Function.cs:104
virtual DataObject Deveel.Data.Routines.AggregateFunction.PostEvaluate ( DataObject  result,
IRequest  query,
IGroupResolver  group 
)
inlineprotectedvirtual

Definition at line 32 of file AggregateFunction.cs.

32  {
33  // By default, do nothing....
34  return result;
35  }

The documentation for this class was generated from the following file: