FNC_TblControl Function | C Library Functions | Teradata Vantage - FNC_TblControl - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

Purpose

Designates a table function as the controlling copy of all other copies of the table function running on other AMP vprocs.

Syntax

int
FNC_TblControl(void)

Return Value

IF the call is … THEN FNC_TblControl returns …
successful and the copy of table function can take the control role of the table function 1.
not successful and the copy of the table function should not assume the role of the control copy 0.

Valid Invocation Mode

Use this library function when the return value of FNC_GetPhase is TBL_MODE_CONST, indicating that the SELECT statement invoked the table function with constant expression input arguments.

For example:

SELECT *
FROM TABLE (table_function_1('STRING_CONSTANT'))
AS table_1;

Usage Notes

Setting up a controlling copy of a table function is useful when there is a need to distribute certain external control data among various copies of the table function that run on different AMP vprocs, but the external control data is on a particular node that only one copy of the table function can access.

Only one copy of the table function can successfully call FNC_TblControl.

After calling FNC_TblControl, the controlling copy of a table function can distribute control data to other table function copies by calling FNC_TblAllocCtrlCtx to allocate a control scratchpad.

Restrictions

This function can only be called from within a table function. Calling this function from a scalar function, aggregate function, UDM, or external stored procedure results in an exception on the transaction.

This function can only be called once.

A table function that calls FNC_TblControl cannot also call FNC_TblFirstParticipant.

Calling this function is valid only when the table function calls FNC_GetPhase and gets the following return values:
  • TBL_MODE_CONST for the FNC_Mode result
  • TBL_PRE_INIT for the FNC_Phase output argument

Example Using FNC_TblControl

typedef struct {
   unsigned short cntrl_fnc_AMP
   int            qfd;
   ...
} ctrl_ctx;

ctrl_ctx     *options;
AMP_Info_t   *LocalConfig;
FNC_Phase    Phase;

if (FNC_GetPhase(&Phase) == TBL_MODE_CONST)
{
   switch(Phase)
   {
      case TBL_PRE_INIT:
      {
         LocalConfig = FNC_AMPInfo();
         if ( FNC_TblControl() )             {
                options = FNC_TblAllocCtrlCtx(sizeof(ctrl_ctx));
            options->ctrl_fnc_AMP = LocalConfig->AMPId;
            ...
         }
      }
      ...
   }
}
...