Denorm Examples | Vantage Analytics Library - Denorm Examples - Vantage Analytics Library

Vantage Analytics Library User Guide

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Lake
Product
Vantage Analytics Library
Release Number
2.2.0
Published
June 2025
ft:locale
en-US
ft:lastEdition
2025-07-02
dita:mapPath
ibw1595473364329.ditamap
dita:ditavalPath
iup1603985291876.ditaval
dita:id
zyl1473786378775
Product Category
Teradata Vantage

denormalizecolumns

In the following example, CC, CK, and SV are valuestodenorm, and acct_type is the indexremovecolumns that assumes these values. The default prefixes CC_, CK_, and SV_ are used.

Call:
call td_analyze(
	'denormalize','
	database=val_source;
	tablename=accounts;
	indexretaincolumns=cust_id;
	indexremovecolumns=acct_type;
	valuestodenorm=CC,CK,SV;
	denormalizecolumns=ending_balance;
');
SQL:
SELECT
	 "cust_id"
	,MIN(CASE WHEN "acct_type" = 'CC' THEN "ending_balance" ELSE NULL END) AS "CC_ending_balance"
	,MIN(CASE WHEN "acct_type" = 'CK' THEN "ending_balance" ELSE NULL END) AS "CK_ending_balance"
	,MIN(CASE WHEN "acct_type" = 'SV' THEN "ending_balance" ELSE NULL END) AS "SV_ending_balance"

FROM "val_source"." accounts"
GROUP BY "cust_id"
;
Results:
cust_id CC_ending_balance CK_ending_balance SV_ending_balance
1362480 20.00 86.86 1187.97
1362484 369.72 95.32 2122.17
1362485 1100.00 45.49  
1362486   3312.27 116.24
1362487 1548.23 1401.21 12.89
1362488   122.42  
1362489 20.00 125.43 373.65
1362492 2000.00 582.82  
1362496     251.06
1362497     10.86
... ... ... ...
Total results: 747 rows

aggregation

In the following example, the tran_id column (half of a two-part key including cust_id and tran_id) is removed from the denormalized output in order to perform meaningful aggregation. COUNT and AVG are demonstrated in this example.

Call:
call td_analyze(
	'denormalize','
	database=val_source;
	tablename= checking_tran;
	indexretaincolumns=cust_id;
	indexremovecolumns=channel;
	valuestodenorm=A,B,C;
	denormalizecolumns=new_balance;
	aggregation=count;
');
SQL:
SELECT
	 "cust_id"
	,COUNT(CASE WHEN "channel" = 'CC' THEN "new_balance" ELSE NULL END) AS "CC_new_balance"
	,COUNT(CASE WHEN "channel" = 'CK' THEN "new_balance" ELSE NULL END) AS "CK_new_balance"
	,COUNT(CASE WHEN "channel" = 'SV' THEN "new_balance" ELSE NULL END) AS "SV_new_balance"

FROM "val_source"."checking_tran"
GROUP BY "cust_id"
;
Results:
cust_id A_new_balance B_new_balance C_new_balance
1362480 18 7 4
1362484 19 14 2
1362485 13 18 6
1362486 1 1 2
1362487 9 3 0
1362488 16 12 7
1362489 13 9 7
1362492 22 7 8
1362498 6 8 2
1362500 4 1 0
... ... ... ...
Total results: 747 rows
The following table shows the results when the aggregation method is changed from COUNT to AVG:
cust_id A_new_balance B_new_balance C_new_balance
1362480 374.82 729.34 58.09
1362484 798.05 511.99 88.94
1362485 552.52 451.29 58.85
1362486 3839.20 3834.41 3538.89
1362487 1958.20 1818.44  
1362488 2194.33 1288.44 1325.50
1362489 539.27 320.12 292.05
1362492 2024.73 2595.48 2503.87
1362498 177.15 55.60 303.53
1362500 889.66 2276.98  
... ... ... ...
Total results: 747 rows

retaincolumns

In the following example, a retaincolumns column is specified to include the column in the denormalized output table. To demonstrate this, it is first necessary to build a test table from the standard tutorial tables (in this case, the accounts table in the val_results database):
DROP TABLE "val_results"."_val_accounts2";
CREATE SET TABLE "val_results"."_val_accounts2" AS (
SELECT T1.*, 'abc' AS abc
FROM "val_source"."accounts" T1
) WITH DATA PRIMARY INDEX("acct_nbr");
Call:
call td_analyze(
	'denormalize','
	database=val_results;
	tablename=_val_accounts2;
	indexretaincolumns=cust_id;
	indexremovecolumns=acct_type;
	denormalizecolumns=ending_balance;
	retaincolumns=abc;
');
SQL:
SELECT
	 "cust_id"
	,"abc"
	,MIN(CASE WHEN "acct_type" = 'CC' THEN "ending_balance" ELSE NULL END) AS "CC_ending_balance"
	,MIN(CASE WHEN "acct_type" = 'CK' THEN "ending_balance" ELSE NULL END) AS "CK_ending_balance"
	,MIN(CASE WHEN "acct_type" = 'SV' THEN "ending_balance" ELSE NULL END) AS "SV_ending_balance"

FROM "val_results"."_val_accounts2"
GROUP BY "cust_id", "abc"
;
The retaincolumns column abc occurs in the SELECT list and GROUP BY list.
Results:
cust_id CC_ending_balance CK_ending_balance SV_ending_balance
1362480 20.00 86.86 1187.97
1362484 369.72 95.32 2122.17
1362485 1100.00 45.49  
1362486   3312.27 116.24
1362487 1548.23 1401.21 12.89
1362488   122.42  
1362489 20.00 125.43 373.65
1362492 2000.00 582.82  
1362496     251.06
1362497     10.86
... ... ... ...
Total results: 747 rows