Call td_analyze ( 'denormalize', 'database = val_source; tablename = accounts; indexretaincolumns = cust_id; indexremovecolumns = acct_type; denormalizecolumns = ending_balance; Optional Parameters;' );
The following example of generated SQL and denormalized DATA are referred to later in this section.
Generated 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" ;
Denormalized DATA
| cust_id | CC_ending_balance | CK_ending_balance | SV_ending_blance |
|---|---|---|---|
| 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 |
Required Parameters
- database
- The database name containing the table to analyze.
- denormalize
- The denormalize parameter must meet the following conditions:
- Is required
- Is the first parameter
- Is always enclosed in single quotes
- denormalizecolumns
- A list of columns to denormalize (such as, duplicating the values from removed index columns).
- indexremovecolumns
- A list of index columns to remove (denormalize by the values of these columns). You can remove up to three index columns that correspond to valuestodenorm, valuestodenorm2, and valuestodenorm3 (described later in this section).
- indexretaincolumns
- Index columns to retain (not remove) in the resulting denormalized table.
- tablename
- The table containing the data to denormalize. It must reside in the database indicated by the database parameter.
Optional Parameters
- aggregation
- Specify an aggregation method when new columns have multiple values to choose from. Setting an aggregation method is useful only when there are non-unique index values or when a part of a multi-part index is being ignored (for example, neither retained nor removed. In other cases, the result is the same no matter what aggregation method is being employed.)
- compress
- Used to compress undefined denormalize column values in the output table. Requests data compression of either NULL or 0 values depending on the value of the nullvalues parameter.
- fallback
- When true, a mirrored copy of the output table in the Database Engine 20 is requested when outputstyle=table. (See the note about fallback in Welcome to Vantage Analytics Library.)
- gensqlonly
- When true, the SQL for the requested function is returned as a result set but not run. When not specified or set to false, the SQL is run but not returned.
- lockingclause
- Requests that the generated SQL contain the specified locking clause. The following is an example of a locking clause when the output style defaults to select:
LOCKING mydb.mytable FOR ACCESS;
- nullvalues
- Used to specify 0 instead of NULL (default) for undefined denormalized column values. If a DATE column is specified as a Denormalize column and 0 is selected, an error occurs.
- outputdatabase
- The database containing the output table, used only if the outputstyle is table, view, or volatile.
- outputstyle
- The following output styles are allowed:
- Select
- Table
- View
- Volatile
- outputtablename
- The output table containing the denormalized data, used only if the outputstyle is table, view, or volatile. If used, the table must reside in the database indicated by the outputdatabase parameter.
- overwrite
- When overwrite is set to true or not set, the output table is dropped before creating a new one.
- prefixes
- Specify the prefixes for newly created columns, otherwise, the system generates the prefixes by default using one of the three valuestodenorm parameters, as applicable.
- retaincolumns
- List of already denormalized columns to retain. For example, having a constant value over the selected values of removed key columns. Refer to the retaincolumns example in the Denorm Examples section.If the column or columns listed here are not already denormalized, a larger-than-expected output table can result.
- valuestodenorm
- The first column values in indexremovecolumns. Each value listed here, in whole or in combination with the other values parameters, results in a denormalized column.
- valuestodenorm2
- The second column values in indexremovecolumns. Each value listed here, in whole or in combination with the other values parameters, results in a denormalized column.
The valuestodenorm2 parameter is linked with the parameters valuestodenorm and valuestodenorm3. Considering these three parameters in order, you can use the first by itself, the first two together, or all three. No other combinations are allowed.
In the following example, CC, CK, and SV are valuestodenorm while Y and N are valuestodenorm2, and acct_type and account_active are the indexremovecolumns that assume these values. The default prefixes are used, such as CC_Y_ and SV_N_.
Call:call td_analyze( 'denormalize',' database=val_source; tablename=accounts; indexretaincolumns=cust_id; indexremovecolumns=acct_type,account_active; valuestodenorm=CC,CK,SV; valuestodenorm2=Y,N; denormalizecolumns=ending_balance; ');
SQL:SELECT "cust_id" ,MIN(CASE WHEN "acct_type" = 'CC' AND "account_active" = 'Y' THEN "ending_balance" ELSE NULL END) AS "CC_Y_ending_balance" ,MIN(CASE WHEN "acct_type" = 'CK' AND "account_active" = 'Y' THEN "ending_balance" ELSE NULL END) AS "CK_Y_ending_balance" ,MIN(CASE WHEN "acct_type" = 'SV' AND "account_active" = 'Y' THEN "ending_balance" ELSE NULL END) AS "SV_Y_ending_balance" ,MIN(CASE WHEN "acct_type" = 'CC' AND "account_active" = 'N' THEN "ending_balance" ELSE NULL END) AS "CC_N_ending_balance" ,MIN(CASE WHEN "acct_type" = 'CK' AND "account_active" = 'N' THEN "ending_balance" ELSE NULL END) AS "CK_N_ending_balance" ,MIN(CASE WHEN "acct_type" = 'SV' AND "account_active" = 'N' THEN "ending_balance" ELSE NULL END) AS "SV_N_ending_balance" FROM "val_source"."accounts" GROUP BY "cust_id";
- valuestodenorm3
- The values of the third column in indexremovecolumns. Each value listed here, in whole or in combination with the other values parameters, results in a denormalized column.
The valuestodenorm3 parameter is linked with the parameters valuestodenorm and valuestodenorm2. Considering these three parameters in order, you can use the first by itself, the first two together, or all three. No other combinations are allowed.
The following example is using the valuestodenorm2 example with the addition of the third parameter, valuestodenorm3:indexremovecolumns=acct_type,account_active, mycolumn; valuestodenorm=CC,CK,SV; valuestodenorm2=Y,N; valuestodenorm3=myvalue1,myvalue2;
- where
- Requests that the generated SQL contain the specified WHERE clause. The where parameter is independent of the output style requested. Do not include the leading keyword WHERE in the parameter text.