SimbaEngine X SDK version 9.3 introduced support for the creation of custom scalar and aggregate functions. To enable this functionality, the following changes were made to the SDK:
PS_NT_SCALAR_FNhas been renamed to
PS_NT_CUSTOM_AGGRhas been added.
PS_NT_CUSTOM_AGGRis used when the parser knows unambiguously that a function is an aggregate function (i.e. a set quantifier ALL or DISTINCT has been specified).
Custom aggregate functions are not supported in Java.
To implement a custom scalar function in the C++ or Java SDK:
CustomerDSIExtScalarFunctionclass which subclasses
DSIExtScalarFunctionand represents your custom scalar function.
Or, for the Java SDK, subclass
CustomScalarFunction, in particular the following:
Takes in a collection of input values and performs the execution of the scalar function.
Used to retrieve the output from Execute().
If you use Simba’s execution engine,
Execute() will be called with the input arguments, and then
RetrieveData()will be called to get the result. This happens at least once per row. If you do not plan to use Simba’s execution engine, then the implementation of both methods should throw an exception to avoid the cases where
Function is never passed down and the engine tries to call the unimplemented
Called once during prepare and should compute preliminary metadata for the input arguments and return value of the scalar function. Note that this metadata could be inaccurate (e.g. due to parameters in the query), so the method should not throw any exceptions related to invalid argument types. The method will be called again at execution time, so you can update the metadata to the final input and output metadata, and throw an exception if the given input metadata is not valid for your scalar function.
The SQLEngine will attempt to convert any inputs into the specified argument types, so an exact match of types is not required.
DSIExtSqlDataEnginederived class for C++, or
SqlDataEnginederived class for Java. This method takes in the name of the scalar function to execute along with the arguments, and returns your
CustomerDSIExtScalarFunctionclass. An exception can be thrown if the number of parameters doesn’t match that required by the scalar function.
To implement a custom aggregate function:
CustomerDSIExtAggregateFunctionclass which subclasses
DSIExtAggregateFunctionand represents your custom aggregate function.
There are no
Execute()/RetrieveData() functions since we currently do not support using custom aggregate functions in our execution engine. This means that if you use our execution engine, your DSII MUST handle the custom aggregate function during CQE. This limitation may be lifted in a future version of the SDK.
CustomerDSIIDataEngine) to return an instance of
CustomerDSIExtAggregateFunctionwhen provided with the aggregate function's name and correct number of arguments (currently only one parameter is supported).
Custom aggregate functions currently only support one parameter and are also not supported in the execution engine; they must be handled via CQE.
The Codebase sample driver contains examples of custom scalar and aggregate functions. See
CBScalarFnConcat. Note that the custom aggregate functions in this driver are only for illustration and cannot be executed as CQE handling has not been implemented for aggregate functions.