Accessing Path Variables by Creating a View on Foreign Table | NOS teradataml - 17.00 - Accessing Path Variables by Creating a View on Foreign Table in Vantage - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Release Date
November 2021
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)

User can access actual columns and path variables by creating a view on a SELECT query with each required column and path variable selected from a foreign table. Each path variable must be typecast to a valid type and then aliased to the appropriate column name. This allows user to access path variables along with Parquet data. It is up to the user on what must be selected in SELECT query passed to "DataFrame.from_query()": columns, attributes, keys from foreign table and path variables.

Example

Create a view.

# While creating a view select each column is type casted to a valid type and 
# then aliased to the required column name. Notice, we are selecting each attribute including path variables.

# Following is the VIEW created at the backend:
"""
REPLACE VIEW t1lview AS (
SELECT CAST($path.$var1 AS CHAR(10)) Var1,
       CAST($path.$var2 AS CHAR(4)) Var2,
       CAST($path.$var3 AS CHAR(2)) var3,
       CAST($path.$var4 AS CHAR(2)) Var4,
       a, b, c, d, e, f, g, h, i, j
FROM t1l);
"""

Create a DataFrame on the view and display the head of the DataFrame.

# Create a DataFrame on a view.
>>> wrk2dfview = DataFrame("t1lview")
>>> wrk2dfview.head().to_pandas()
Var1	Var2	var3	Var4	a	b	c	d	e	f	g	h	i	j
0	csoj_files	t1l.	None	None	10	100	110	1	CScs	1963-02-03	100.333	19.0	4	10
1	csoj_files	t1l.	None	None	8	80	108	1	CScs	1963-02-03	200.333	19.0	4	10
2	csoj_files	t1l.	None	None	2	20	102	1	CScs	1961-06-05	200.333	19.0	4	10
3	csoj_files	t1l.	None	None	1	10	101	1	CScs	1961-06-05	100.333	19.0	4	10
4	csoj_files	t1l.	None	None	9	90	109	1	CScs	1963-02-03	300.333	19.0	4	10
5	csoj_files	t1l.	None	None	5	50	105	1	CScs	1961-06-05	200.333	19.0	4	10
6	csoj_files	t1l.	None	None	6	60	106	1	CScs	1963-02-03	300.333	19.0	4	10
7	csoj_files	t1l.	None	None	4	40	104	1	CScs	1961-06-05	100.333	19.0	4	10
8	csoj_files	t1l.	None	None	3	30	103	1	CScs	1961-06-05	300.333	19.0	4	10
9	csoj_files	t1l.	None	None	7	70	107	1	CScs	1963-02-03	100.333	19.0	4	10