Package com.mckoi.database
Interface Function
-
- All Known Implementing Classes:
AbstractAggregateFunction
,AbstractFunction
public interface Function
Represents a function that is part of an expression to be evaluated. A function evaluates to a resultant Object. If the parameters of a function are not constant values, then the evaluation will require a lookup via a VariableResolver or GroupResolver. The GroupResolver helps evaluate an aggregate function.- Author:
- Tobias Downer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.List
allElements()
Returns the list of all element objects that this function uses as its parameters.java.util.List
allVariables()
Returns the list of Variable objects that this function uses as its parameters.TObject
evaluate(GroupResolver group, VariableResolver resolver, QueryContext context)
Evaluates the function and returns a TObject that represents the result of the function.java.lang.String
getName()
Returns the name of the function.boolean
isAggregate(QueryContext context)
Returns true if this function is an aggregate function.void
prepareParameters(ExpressionPreparer preparer)
Prepares the exressions that are the parameters of this function.TType
returnTType(VariableResolver resolver, QueryContext context)
The type of object this function returns.
-
-
-
Method Detail
-
getName
java.lang.String getName()
Returns the name of the function. The name is a unique identifier that can be used to recreate this function. This identifier can be used to easily serialize the function when grouped with its parameters.
-
allVariables
java.util.List allVariables()
Returns the list of Variable objects that this function uses as its parameters. If this returns an empty list, then the function must only have constant parameters. This information can be used to optimize evaluation because if all the parameters of a function are constant then we only need to evaluate the function once.
-
allElements
java.util.List allElements()
Returns the list of all element objects that this function uses as its parameters. If this returns an empty list, then the function has no input elements at all. ( something like: upper(user()) )
-
isAggregate
boolean isAggregate(QueryContext context)
Returns true if this function is an aggregate function. An aggregate function requires that the GroupResolver is not null when the evaluate method is called.
-
prepareParameters
void prepareParameters(ExpressionPreparer preparer) throws DatabaseException
Prepares the exressions that are the parameters of this function. This is intended to be used if we need to resolve aspects such as Variable references. For example, a variable reference to 'number' may become 'APP.Table.NUMBER'.- Throws:
DatabaseException
-
evaluate
TObject evaluate(GroupResolver group, VariableResolver resolver, QueryContext context)
Evaluates the function and returns a TObject that represents the result of the function. The VariableResolver object should be used to look up variables in the parameter of the function. The 'FunctionTable' object should only be used when the function is a grouping function. For example, 'avg(value_of)'.
-
returnTType
TType returnTType(VariableResolver resolver, QueryContext context)
The type of object this function returns. eg. TStringType, TBooleanType, etc. The VariableResolver points to a dummy row that can be used to dynamically determine the return type. For example, an implementation of SQL 'GREATEST' would return the same type as the list elements.
-
-