UDM Source Code Development | External Routine Programming | Teradata Vantage - UDM Source Code Development - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

You develop the body of a UDM using the C or C++ programming language.

Customers using Vantage delivered as-a-service cannot create their own C++ and Java UDFs, UDMs, UDTs, or External Stored Procedures.

Source Code Contents

The topics that follow provide details about the contents of the C or C++ source code for a UDM. In general, the contents of the C or C++ source code must:
  • Define the SQL_TEXT constant
  • Include the sqltypes_td.h header file
  • Define the parameter list in the order that matches the parameter passing convention specified in the METHOD specification in the CREATE TYPE statement

Internal and External Data

All data is local to the UDM. No global data can be retained from method invocation to method invocation, with the exception of GLOP data. For details on using GLOP data, see Global and Persistent Data.

The UDM cannot contain any static variables.

A UDM can contain static constants.

I/O

The following rules apply to I/O.

IF the UDM … THEN the UDM …
runs in nonprotected execution mode cannot do any I/O, including standard I/O and network I/O.
runs in protected execution mode can do I/O or otherwise interface with the operating system such that the operating system retains resources such as file handles or object handles.

The method executes as a separate process under the authorization of the 'tdatuser' operating system user.

The method must release opened resources (close handles) before it completes.

For more information on protected execution mode, see Protected Mode Execution.

specifies the EXTERNAL SECURITY clause in the CREATE METHOD or REPLACE METHOD statement can do I/O or otherwise interface with the operating system such that the operating system retains resources such as file handles or object handles.

The method executes as a separate process under the authorization of a specific native operating system user established by a CREATE AUTHORIZATION or REPLACE AUTHORIZATION statement.

The method must release opened resources (close handles) before it completes.

Signal Handling

UDMs that run on Linux systems cannot use or modify the handling of the signal SIGUSR2, which is reserved by Vantage.

Standard C Library Functions

A UDM that runs in nonprotected mode or protected mode can call standard C library functions that do not do any I/O, such as string library functions.

Restrictions apply to some functions, such as malloc and free.

For more information, see Using Standard C Library Functions.

Teradata Library Functions

Teradata provides functions that you can use for UDM development. For example, you can use the FNC_GetDistinctValue function to get the value of the distinct type that a UDM is associated with.

For more information, see C Library Functions.

Problems Using System V IPC and POSIX IPC

Teradata recommends that UDFs, UDMs, and external stored procedures not use System V IPC or POSIX IPC such as semaphore, mutex, conditional variable, and shared memory. The Teradata C library does not provide FNC functions to allocate and deallocate these IPC resources. When a session aborts or unexpected events cause Teradata to terminate the external routine execution threads or processes, there is a risk that these IPC resources may be left over in the system without being cleaned up. In rare cases, this may cause a system hang or OS resource leak.

Consequences of Using the exit() System Call

Avoid calling exit() from UDMs.

UDMs that call exit() generate the following results:
  • The request that called the UDM is rolled back.
  • The server process is terminated and must be recreated for the next UDM, causing additional overhead.