Factory Method with RuntimeContract and Custom Context - Aster Execution Engine

Teradata Aster® Developer Guide

Product
Aster Execution Engine
Release Number
7.00.02
Published
July 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
xnl1494366523182.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
ffu1489104705746
lifecycle
previous
Product Category
Software

An Aster instance uses the factory method, or a "constructor", registered in the module definition, to create instances of the function for contract negotiation in query planning mode or for actual processing of data in vworkers.

In this factory method:

  • You can, and typically you should, check the number and data types of the input parameters through the given RuntimeContract and set the datatype of the output value, and so on.
  • You can also create and initialize a custom context for the internal state of this function instance for its execution.
  • In addition, you should populate the given outPointers with function pointers to the processing methods of your function. If you use a custom context, you should also assign to it:
    • the pointer to the custom context, and
    • a function pointer to the method to free up the context at the end of the lifetime of the function instance

Each user defined function is polymorphic. That is, one function could handle input data of varying data types and even varying number of input parameters and/or arguments. You have full control and responsibility to accept or reject the input given in the RuntimeContract, which corresponds to how the function is invoked in the query.

Whatever the function accepts, its processing methods set in outPointers must be able to handle it properly. For example, if a function accepts numeric input, it may implement one single processing method that handles input of all various numeric data types. Or, it may implement one processing method for each numeric data type and set outPointers according to the specific input data type given in RuntimeContract for that function instance. In the latter case, which likely executes more efficiently, you may use C macros or C++ templates to minimize source code duplication.

The SDK examples under sqlmr-sdk/example/c/udf/ illustrate the various approaches.