Example: Function Processing with Any Input Table Substitution - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-04-05
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantage™

The function mapping definition usr_AllPairsShortestPath for the function AllPairsShortestPath specifies that vertices can be substituted for any input table that does not correspond to any of the other specified input tables.

CREATE FUNCTION MAPPING syslib.usr_AllPairsShortestPath
FOR AllPairsShortestPath SERVER coprocessor
USING
vertices(ANY) IN TABLE,
edges(edge) IN TABLE,
sources IN TABLE,
targets(dest) OUT TABLE,
TargetKey('col1'),MaxDistance(Distance),EdgeWeight('2'),
GroupCol('Col_'||GroupColumn||'_'||Distance),
Distance(SELECT distnum FROM ssqtbl WHERE username=CURRENT_USER),
Directed;

This SELECT statement specifies vertex and edges as table correlation names.

SELECT * FROM usr_AllPairsShortestPath (
ON callers AS vertex PARTITION BY callerid
ON calls AS edges PARTITION BY callerfrom
USING
TargetKey ('callerto')
EdgeWeight ('calls')
MaxDistance ('-1')
) as dt ORDER BY source, target;

The query is rewritten as follows during function processing. Because the function mapping definition specifies that vertices can be substituted for any table that does not correspond to any of the other specified input tables, vertices is substituted for vertex.

SELECT * FROM AllPairsShortestPath (
ON callers AS vertices PARTITION BY callerid
ON calls AS edges PARTITION BY callerfrom
TargetKey ('callerto')
EdgeWeight ('calls')
MaxDistance ('-1')
) ORDER BY source, target;

This SELECT statement specifies vertices and edges as table correlation names.

SELECT * FROM usr_AllPairsShortestPath (
ON callers AS vertices PARTITION BY callerid
ON calls AS edges PARTITION BY callerfrom
USING
TargetKey ('callerto')
EdgeWeight ('calls')
MaxDistance ('-1')
) as dt ORDER BY source, target;

The query is rewritten as follows during function processing, specifying the vertices and edges input tables.

SELECT * FROM AllPairsShortestPath (
ON callers AS vertices PARTITION BY callerid
ON calls AS edges PARTITION BY callerfrom
TargetKey ('callerto')
EdgeWeight ('calls')
MaxDistance ('-1')
) ORDER BY source, target;

This SELECT statement does not specify a correlation for the table callers and specifies edges as a correlation for calls.

SELECT * FROM usr_AllPairsShortestPath (
ON callers PARTITION BY callerid
ON calls AS edges PARTITION BY callerfrom
USING
TargetKey ('callerto')
EdgeWeight ('calls')
MaxDistance ('-1')
) as dt ORDER BY source, target;

The query is rewritten as follows during function processing. Because the function mapping definition specifies that vertices can be substituted for any table that does not have a correlation, vertices is correlated to callers.

SELECT * FROM AllPairsShortestPath (
ON callers AS vertices PARTITION BY callerid
ON calls AS edges PARTITION BY callerfrom
TargetKey ('callerto')
EdgeWeight ('calls')
MaxDistance ('-1')
) ORDER BY source, target;