Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

Denormalize Sorted

Denormalize Sorted consolidates groups of related records by key into a single output record
with a vector field for each group, and optionally computes summary fields in the output
record for each group.

Properties of Denormalize Sorted

Key-method: Method by which component group records. There are 2 options for this
parameter.
Use Key Specifier
Use Key_change function
Key: Name of the key fields, that the component will use to group records are mentioned
here. This parameter is available only when Key method parameter is set as “Use Key
specifier”.
Check-sort: If you use a key specifier, this parameter indicates whether or not to abort
execution on the first input record that is out of sorted order.
Transform: The name of the file containing the types and transform functions, or a transform
string.
Reject-threshold: The component's tolerance for reject events.
Logging: Specifies whether or not to log component events.

Sample Graph
************************************************************

Example 1 – Using transform functions


This is a simple denormalize application. It sorts input data records using the customer_id key
specifier. The Denormalize component combines each group of records with the same key into
a single denormalized record containing an element for each record of the group, as well as a
summary value for all the records in the group.
Following steps should be followed in transformation string.
1) Define element_type, which is the built-in transform vector element (elt) type. This
element will contain the data you are collecting from the individual records for the
vector in the output record.
2) Specify certain details of the built-in denormalization_type transform vector.
3) Use the required and optional transformation functions.
Input
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amount;
end

Code in Transform
type element_type = decimal("|");
type denormalization_type = element_type[3];

/*Initialize vector element*/


out::initial_denormalization()=
begin
out :: 0;
end;

/*Do computation*/
denorm_out::denormalize(denorm,in,count)=
begin
denorm_out.index:: count;
denorm_out.elt:: in.amount;
end;

/*Create output record*/


out::finalize(denorm,in)=
begin
out.* :: in.*;
out.amounts :: denorm;
end;

Output
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amounts[3];
end
*******************************************************************************

Example 2 – With Rollup Functionality


In previous example two more fields are added in output to give number of transactions and
total amount which can be done through rollup functions.
If you use a rollup transform function with Denormalize Sorted, you must define a
temporary_type to provide the temporary storage needed by the rollup transform function.
Input
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amount;
end

Code in Transform
type element_type = decimal("|");
type denormalization_type = element_type[3];

/*Initialize vector element*/


out::initial_denormalization()=
begin
out :: 0;
end;

/* Create temporary variables*/


type temporary_type =
record
decimal(8.2) total_amount;
decimal(4) count;
end;

/* Initialize temporary variables*/


out :: initialize(in) =
begin
out.total_amount :: 0;
out.count :: 0;
end;

/* Create Rollup functionality*/


out :: rollup(temp, in) =
begin
out.total_amount :: temp.total_amount + in.amount;
out.count :: temp.count + 1;
end;

/*Do computation*/
denorm_out::denormalize(temp,denorm,in,count)=
begin
denorm_out.index:: count;
denorm_out.elt:: in.amount;
end;

/*Create output record*/


out::finalize(temp,denorm,in)=
begin
out.* :: in.*;
out.amounts :: denorm;
out.total_amount :: temp.total_amount;
out.no_of_trans :: temp.count;
end;

Output
record
decimal("|") cust_id;
string("|") cust_name;
decimal("|") no_of_trans;
decimal("|") total_amount;
decimal("\n") amounts[3];
end

************************************************************

Additional functions in Denormalize Sorted


1) Input_select – Performs selection of input records.
2) Output_select – Performs selection of output records.
3) Key_change – As an alternative to sorting by the key parameter, key_change
function is used to define grouping.

Example 3 – Using input_select function

Input
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amount;
end

Code in Transform
type element_type = decimal("|");
type denormalization_type = element_type[3];

/*Initialize vector element*/


out::initial_denormalization()=
begin
out :: 0;
end;

/*Input select*/
out :: input_select(in) =
begin
out :: in.amount>1000;
end;

/*Do computation*/
denorm_out::denormalize(denorm,in,count)=
begin
denorm_out.index:: count;
denorm_out.elt:: in.amount;
end;

/*Create output record*/


out::finalize(denorm,in)=
begin
out.* :: in.*;
out.amounts :: denorm;
end;

Output
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amounts[3];
end

*******************************************************************
Example 4 – Using output_select function

Input
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amount;
end

Code in Transform
type element_type = decimal("|");
type denormalization_type = element_type[3];

/*Initialize vector element*/


out::initial_denormalization()=
begin
out :: 0;
end;

/*Do computation*/
denorm_out::denormalize(denorm,in,count)=
begin
denorm_out.index:: count;
denorm_out.elt:: in.amount;
end;

/*Create output record*/


out::finalize(denorm,in)=
begin
out.* :: in.*;
out.amounts :: denorm;
end;

/*Output Select*/
out :: output_select(out) =
begin
out :: out.cust_id>=2;
end;

Output
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amounts[3];
end

*******************************************************************

Example 5 – Using key_change function

Input
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amount;
end

Key specifier - cust_id not specified in parameters.


Code in Transform
type element_type = decimal("|");
type denormalization_type = element_type[3];

/*Initialize vector element*/


out::initial_denormalization()=
begin
out :: 0;
end;

/*Do computation*/
denorm_out::denormalize(denorm,in,count)=
begin
denorm_out.index:: count;
denorm_out.elt:: in.amount;
end;

/*Create output record*/


out::finalize(denorm,in)=
begin
out.* :: in.*;
out.amounts :: denorm;
end;

/*Key change function*/


out :: key_change(in1, in2) =
begin
out :: in2.cust_id!=in1.cust_id;
end;

Output
record
decimal("|") cust_id;
string("|") cust_name;
decimal("\n") amounts[3];
end
*******************************************************************

You might also like