# GTree Example 1: Show All Paths from Root Nodes - Teradata Vantage

## Teradata® Vantage Machine Learning Engine Analytic Function Reference

Product
Release Number
1.0
8.00
Published
May 2019
Language
English (United States)
Last Update
2019-11-22
dita:mapPath
blj1506016597986.ditamap
dita:ditavalPath
blj1506016597986.ditaval
dita:id
lmf1502735330121
Product Category

## Input

The vertices (nodes) are bus stops in a small town. The vertices table lists each bus stop and the boarding fare at that stop.

vertices: gtree_vertices
nodeid nodestring value
1 Park St 2.25
2 Main St 2.25
3 Walnut St 2.25
4 Water St 3.5
5 High St 2.25

The edges table represents the bus route. The columns nodeid and nodestring identify the source vertices (where the bus starts) and the columns endnodeid and endnodestring identify the target vertices (where the bus stops).

edges: gtree_edges
nodeid nodestring endnodeid endnodestring
1 Park St 3 Walnut St
2 Main St 3 Walnut St
3 Walnut St 4 Water St
4 Water St 1 Park St
4 Water St 5 High St

The root table defines the set of root vertices from which the function starts traversing the graph.

root: gtree_root
nodeid nodestring value
1 Park St 2.25
2 Main St 2.25

## SQL Call

```SELECT * FROM GTree (
ON gtree_vertices AS vertices PARTITION BY nodeid, nodestring
ON gtree_edges AS edges PARTITION BY nodeid, nodestring
ON gtree_root AS root PARTITION BY nodeid, nodestring
USING
TargetKey ('endnodeid', 'endnodestring')
AllowCycles ('t')
MaxDepth (10)
OutputType ('all')
Results (
'Propagate (nodeid) AS start_vertex',
'Current (nodeid) AS end_vertex',
'Path (nodestring)',
'Sum (value)',
'Cycle()',
'Leaf()'
)
EdgeResults ('PATH(nodestring, endnodestring) AS edgepath')
) AS dt ORDER BY 1,2;```

## Output

The output table has one column for each function that the Results or EdgeResults argument specifies. The edgepath column shows the links that comprise the path, the cycle column shows whether the path is a cycle, and the sum column shows the total fare for the path (the sum of the boarding fares at each node in the path).

start_vertex end_vertex path(node_string) sum(value) cycle() leaf() edgepath
1 1 Park St-> 2.25 false false .-Park StWalnut St->.
1 3 Park St->Walnut St-> 4.5 false false .-Park StWalnut St->.-Walnut StWater St->.
1 4 Park St->Walnut St->Water St-> 8 false false .-Park StWalnut St->.-Walnut StWater St->.-Water StHigh St->.
1 4 Park St->Walnut St->Water St-> 8 true false .-Park StWalnut St->.-Walnut StWater St->.-Water StPark St->
1 5 Park St->Walnut St->Water St->High St 10.25 false true .-Park StWalnut St->.-Walnut StWater St->.-Water StHigh St->.
2 1 Main St->Walnut St->Water St->Park St-> 10.25 true false .-Main StWalnut St->.-Walnut StWater St->.-Water StPark St->.-Park StWalnut St->
2 2 Main St-> 2.25 false false .-Main StWalnut St->.
2 3 Main St->Walnut St-> 4.5 false false .-Main StWalnut St->.-Walnut StWater St->.
2 4 Main St->Walnut St->Water St-> 8 false false .-Main StWalnut St->.-Walnut StWater St->.-Water StHigh St->.
2 4 Main St->Walnut St->Water St-> 8 false false .-Main StWalnut St->.-Walnut StWater St->.-Water StPark St->.
2 5 Main St->Walnut St->Water St->High St 10.25 false true .-Main StWalnut St->.-Walnut StWater St->.-Water StHigh St->.