17.10 - SQL Definition - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

The default parameter mapping convention for mapping SQL data types to Java data types is simple mapping, where SQL data types map to Java primitives. In this example, the EXTERNAL NAME string does not specify the parameter types, so simple mapping is assumed. The corresponding Java function should also use simple mapping as shown in the subsequent Java Method Implementation section.

DATABASE JUDF;
REPLACE FUNCTION MYSUM(x INTEGER)
        RETURNS INTEGER
        LANGUAGE JAVA
        NO SQL
        CLASS AGGREGATE(200)
        PARAMETER STYLE JAVA
        EXTERNAL NAME 'Sum_JAR:UDFExample.simpleSum';

For object mapping, the EXTERNAL NAME string must specify the phase and context along with the object type. For example:

DATABASE JUDF;
REPLACE FUNCTION MYSUM(x INTEGER)
        RETURNS INTEGER
        LANGUAGE JAVA
        NO SQL
        CLASS AGGREGATE(200)
        PARAMETER STYLE JAVA
        EXTERNAL NAME 'Sum_JAR:UDFExample.simpleSum(com.teradata.fnc.Phase,
com.teradata.fnc.Context[],java.lang.Integer) returns java.lang.Integer';

The corresponding Java UDF definition is:

public static java.lang.Integer simpleSum(com.teradata.fnc.Phase phase
,com.teradata.fnc.Context[] context,java.lang.Integer x)
{
   ...
}

For details about simple mapping and object mapping, see Java Data Types.