Function overloading or Generic Functions in UDFs

General
Enthusiast

Function overloading or Generic Functions in UDFs

Hi everybody,

I wished to know if Generic Functions or function overloading is supported in teradata UDFs written in C or not..I wished to have a function which takes input as VARCHAR or INTEGER and then have different functionality for VARCHAR and INTEGERS...I was thinking about doing it via function overloading and creating different functions for VARCHAR and INTEGER having same function name or using generic function something like <typename a> void FUNCTION_NAME ( A *arg, A* result, char sqlstate[])...Is that supported in Teradata UDFs???? And if yes how to write the SQL to create these UDFs in Teradata...

Thanks

Tags (1)
5 REPLIES
Enthusiast

Re: Function overloading or Generic Functions in UDFs

Teradata Employee

Re: Function overloading or Generic Functions in UDFs

Yes, function overloading is supported for UDFs written in C.

Enthusiast

Re: Function overloading or Generic Functions in UDFs

Hi...Thanks for your replies....I had one more doubt....I have a C file whose structure is as

#define SQL_TEXT Latin_Text
#include "sqltypes_td.h"
void func1(INTEGER *arg, VARCHAR *result, char sqlstate[])
{
.................................
........................................
........................................
}
void func2(VARCHAR *arg, VARCHAR *result, char sqlstate[])
{
..........................................
...........................................
.........................................
}

now i saved this file using the name FUNCTIONS.c

To create the first function I used the query like

CREATE FUNCTION foo (arg INTEGER)
RETURNS CHAR(40) CHARACTER SET LATIN
SPECIFIC func1
LANGUAGE C
NO SQL
PARAMETER STYLE TD_GENERAL
NOT DETERMINISTIC
CALLED ON NULL INPUT
EXTERNAL NAME 'CS!FUNCTIONS1!D:\FUNCTIONS.C';

this query runs as normal

for the second overloaded function ran the sql query as

CREATE FUNCTION foo (arg VARCHAR(10) CHARACTER SET LATIN)
RETURNS CHAR(40) CHARACTER SET LATIN
SPECIFIC func2
LANGUAGE C
NO SQL
PARAMETER STYLE TD_GENERAL
NOT DETERMINISTIC
CALLED ON NULL INPUT
EXTERNAL NAME 'CS!FUNCTIONS2!D:\FUNCTIONS.C';

on running this query I get the error that func1 and func2 are already defined in FUNCTIONS1.o
Can anyone please tell me what m I doing wrong here??? Do I have to give the same object name in both the queries under EXTERNAL NAME part...or will I have to create two different files for both the functions and then only can I implement overloading??? Thing is I really wanted to keep the function definitions together in a single file..So is that possible???
Teradata Employee

Re: Function overloading or Generic Functions in UDFs

With the CS option in the EXTERNAL NAME clause, the source file is transmitted from client to server, and compiled on the server. The server manages the object file that was output from the compiler. If you want to use the CS option, you will need to separate the C function definitions into two separate .c source files. The CS option is convenient and easy to use, because it does not require a compiler on the client, and does not require Linux OS login access to the Teradata Database nodes. The drawbacks are that you must separate your C functions into separate source files, and that your source code is visible to other people.

If you have compelling reason to keep the C function definitions together in the same .c source file, then you will need to take responsibility for compiling them yourself on the client side, and providing the .o object file, or the library file, to the Teradata Database. Some of those "compelling reasons" might be: If you need more control over how your C functions are organized into source files, if you need more control over the compiler settings that are used during compilation, or if you have proprietary source code that you want to protect. There is an O option for specifying a .o object file, and there is a L option for specifying a library file. Because the source code is not visible, there may be a perceived security risk, and the database administrator or security administrator may need to audit your functions before permitting them to be installed. Organizations needing this level of control also typically distribute the object files and/or library files to all the Teradata Database nodes ahead of time (which requires Linux OS login access to the Teradata Database nodes), and use the S server-side option in the EXTERNAL NAME clause.

Enthusiast

Re: Function overloading or Generic Functions in UDFs

Thanks...that was a great help..really appreciate it :) :)