Here is a synopsis of the steps you take to develop, compile, install, and use a UDF that implements UDT transform, ordering, or cast functionality:
- Write, test, and debug the C or C++ code for the UDF.
You can use the Teradata C/C++ UDF Debugger, which is a version of GDB (the gnu Source-Level Debugger) that contains extensions for the database. For more information, see C/C++ Command-line Debugging for UDFs.
- Use the CREATE FUNCTION or REPLACE FUNCTION statement to identify the location of the source code or object, and install the item on the server.Teradata recommends against creating UDFs in Teradata system databases such as SYSLIB or SYSUDTLIB. See Installing the Function.
The function is compiled, if the source code is submitted, linked to the dynamic linked library (DLL or SO) associated with the database in which the function resides, and distributed to all database nodes in the system.
- Register the UDF as a transform, ordering, or cast routine.
Functionality UDF Implements Register UDF with This Statement Cast CREATE CAST or REPLACE CAST Ordering CREATE ORDERING or REPLACE ORDERING Transform CREATE TRANSFORM or REPLACE TRANSFORM - Test the UDF in protected run mode until the UDF works correctly.
Protected mode is the default run mode for a UDF. In protected mode, Vantage isolates the data the UDF may access as a separate process in its own local workspace. This makes the function run slower. If any memory violation or other system error occurs, the error is localized to the function and the transaction executing the function.
- Use ALTER FUNCTION to change the UDF to run in nonprotected run mode.If you subsequently use REPLACE FUNCTION to replace the function, the run mode reverts back to protected mode.
- Rerun the tests from Step 4 to test the UDF in nonprotected run mode until the UDF works correctly.
- Use GRANT to grant privileges to users who are authorized to use the UDF and the UDT.