17.10 - Processing Phase - 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 processing phases that FNC_GetPhase can return depend on the mode.

IF the value of FNC_Mode is … THEN this value for Phase … Means that the table function …
TBL_MODE_VARY TBL_PRE_INIT is being called for the first time for all the rows that it will be called for. The input arguments to the function contain the first set of data.

During this phase, the function has an opportunity to establish overall global context, but should not build any result row.

The function continues to the TBL_INIT phase.

TBL_INIT should open any connections to external objects, such as files, if there is a need to do so. The input arguments to the function contain the first set of data.

During this phase, the function should not build any result row.

The function continues to the TBL_BUILD phase.

TBL_BUILD should fill out the result arguments to build a row.

The function remains in the TBL_BUILD phase until it sets the sqlstate argument to "02000" to indicate no data, whereupon it continues to the TBL_FINI phase.

TBL_FINI should close any connections, such as file handles, that were opened during the TBL_INIT phase.

If there is more variable input data, the function returns to the TBL_INIT phase. Otherwise, the function continues to the TBL_END phase.

TBL_END should close all external connections and release any scratch memory it might have allocated. The table function is not called again after this phase.
TBL_ABORT is being aborted and should close all external connections and release any previously-allocated memory. A function can be called at any time with this phase, which is only entered when one of the table functions calls the library function FNC_TblAbort. It is not entered when the function is aborted for an external reason, such as a user abort.
TBL_MODE_CONST TBL_PRE_INIT may decide whether it should be the controlling copy of all table functions running on other AMP vprocs.

If the function wants to provide control context to all other copies of the table function, the function must call FNC_TblControl.

If the function does not want to be the controlling copy of the table function, or if the function is designed without the need for a controlling function, the function can simply return and do nothing during this phase.

All copies of the table function must complete this phase before any copy continues to the TBL_INIT phase.

TBL_INIT should open any connections to external objects, such as files, if there is a need to do so.

Any copy of the function that does not want to participate further must call FNC_TblOptOut. After the function returns, it will not be called again.

All copies of the table function must complete this phase before any copy continues to the TBL_BUILD phase.

TBL_BUILD should fill out the result arguments to build a row.

The function remains in the TBL_BUILD phase until it sets the sqlstate argument to "02000" to indicate no data, whereupon it continues to the TBL_END phase.

TBL_END should close all external connections and release any scratch memory it might have allocated. The table function is not called again after it returns from this phase.

The controlling copy of the table function, if one exists, is called with this phase after all other copies of the table function have completed this phase, which allows the controlling function to do any final cleanup or notification to the external world.

TBL_ABORT is being aborted and should close all external connections and release any previously-allocated memory. A function can be called at any time with this phase, which is only entered when one of the table functions calls the library function FNC_TblAbort. It is not entered when the function is aborted for an external reason, such as a user abort.