Accessing Path Variables using DataFrame.from_query | NOS teradataml - 17.00 - Accessing Path Variables using DataFrame.from_query() - 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 column and path variables using DataFrame.from_query() that pass a SELECT query with each required column and path variable selected from 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

SELECT query with each column and path variable selected.

# Select query with each column from PARQUET file selected. 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.
query = """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 DataFrame from the query and display the head of the DataFrame.

>>> wrk1df = DataFrame.from_query(query)
>>> wrk1df.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