A typical module definition is as follows:
/* * SQL-MR function module definition */ SQLMR_FUNCTION_MODULE_BEGIN() { SQLMR_FUNCTION_ENTRY("average") { entry->newAggregatorFunction = &average_newAggregator; } } SQLMR_FUNCTION_MODULE_END()
The string given to SQLMR_FUNCTION_ENTRY is the name of the function. Within the module definition block, assign the function pointer of the factory method (for example, &average_newAggregator in the example above) to the respective one of the following members of SqlmrFunctionEntry according to the type of your function.
- For a scalar function:
SqlmrErrorH (*newScalarFunction)( SqlmrTaskContextH taskContext, SqlmrRuntimeContractH contract, UdfScalarFunctionPointers* outPointers ) SQLMR_ERROR_RESULT;
- For an aggregate function:
SqlmrErrorH (*newAggregatorFunction)( SqlmrTaskContextH taskContext, SqlmrRuntimeContractH contract, UdfAggregatorFunctionPointers* outPointers ) SQLMR_ERROR_RESULT;
- For a decomposable aggregate function:
SqlmrErrorH (*newDecomposableAggregatorFunction)( SqlmrTaskContextH taskContext, SqlmrRuntimeContractH contract, UdfDecomposableAggregatorFunctionPointers* outPointers ) SQLMR_ERROR_RESULT;
It is good practice to also provide HelpInfo in the module definition. See HelpInfo for User Defined Functions.