Day 4
5/16/2019
1 | ©2010, Cognizant Technology Solutions Confidential
Day Four: Components-III & Introduction
to Built-in Functions
• Reformat
• Overview of built-in functions
• Normalize
• Denormalize Sorted
• Rollup
• Gather Log
5/16/2019
2 | ©2010, Cognizant Technology Solutions Confidential
Day Four: Components-III
Reformat
Reformat changes the input record format
by dropping fields, or by using DML
expressions to add fields, combine fields,
or transform the data in the records.
This can be got by clicking on “Transform”
in component organizer then Reformat
(Double Click or drag “Reformat” from
Transform).
Double Click or right click, on the Reformat
icon to get the Reformat Properties
window.
5/16/2019
3 | ©2010, Cognizant Technology Solutions Confidential
Reformat : properties tab
5/16/2019
Click on Parameters tab.
4 | ©2010, Cognizant Technology Solutions Confidential
Reformat : properties : parameters
Count – You can mention the number of out ports.
Transform – This is where the transform logic is
written.
Select – This helps in selection of records for
transformation.
Reject-threshold – This tells the component
when to abort.
Logging – Tells whether the component is writing
to log port. Also the frequency of logging
can be mentioned if Logging is
set to “True”.
Now click on the Ports tab.
5/16/2019
5 | ©2010, Cognizant Technology Solutions Confidential
Reformat : properties : ports
Here the in & out() port record formats needs to be entered, if required.
Reject() port has the same record format as the Out() port.
5/16/2019
Error() & log() ports have a pre-defined record format.
6 | ©2010, Cognizant Technology Solutions Confidential
In-Built Functions
Categories:
• Date functions
• Inquiry and error functions
• Lookup functions
• Math functions
• Miscellaneous functions
• String functions
•Ab Initio Help contains detailed description of each function.
However, some peculiarities are discussed in the next few slides
5/16/2019
7 | ©2010, Cognizant Technology Solutions Confidential
Date functions :
start with 'date....', with the exception of :
• decode_date,
• decode_date_record,
• decode_datetime,
• encode_date,
• encode_datetime,
• now,
• today,
• today1.
The first date,or reference date for Ab Initio is Jan 1, 1900.
every date can be expressed in terms of days elapsed from this reference date.
for eg.
01 / April / 2004 translates to 38076 days.
•The function to be used is date_to_int()
5/16/2019
8 | ©2010, Cognizant Technology Solutions Confidential
Date functions : continued…
•datetime_difference_abs(date1,date2)
gives the absolute difference between two dates in a particular recordtype format.
datetime_difference_type :
record
integer(8) days;
integer(8) hours;
integer(8) minutes;
integer(8) seconds;
integer(8) microseconds;
end
5/16/2019
9 | ©2010, Cognizant Technology Solutions Confidential
•date_day_of_week ( date d )
returns 1-7 depending on which day of the week is specified by the given date.
if the date falls on a Sunday, 1 is returned, if Saturday, 7 is returned.
•date_day_of_year(date d)
will similarly return 1-366,depending on how many days have elapsed till that d, starting from Jan 1
of the year contained in d.
•Similarly, datetime_add()
will return the result of adding a given number of days, hours, minutes, seconds, and microseconds
to the value of a date.
•today() and today1() (no arguements are required here)
return the internal representation of the current date.
the difference between the two functions is that while today() Returns the internal representation of
the current date on each call,
•today1()
Returns the internal representation of the current date on the first call : for eg. At the first call in a
job, today1() calls the operating system for the date. On the second and subsequent calls, the
function returns the value of the first call.
The difference between the two functions is noticeable on jobs that start before
and end after midnight.
5/16/2019
10 | ©2010, Cognizant Technology Solutions Confidential
•lookup :
it may be understood as a select query with certain where clauses. The conditional clauses
are given as parameters.
for clarity, consider the syntax of calling a lookup funtion :
lookup( "file_containing_results_of_select_query" , "1" , "NSRag" ).Emp_Salary
will return
value of the column Emp_Salary (say employee salary) of that record
where
"1" matches against 1st parameter (say Sl_No)
and
"NSRag" matches with 2nd parameter(say emp name in this case).
i.e. 1000 will be returned
Lookup file named :
S_No Emp_Name Emp_Salary Emp_table
1 NSRag 1000 file_containing_results_of_select_query
1 Raveena 1205
2 Tendlya 25420
3 Nagavara 254234
S_No Emp_Name Emp_Salary
Select * from emp_table where Sl_No <3 1 NSRag 1000
1 Raveena 1205
5/16/2019 Results of query
11 | ©2010, Cognizant Technology Solutions Confidential 2 Tendlya 25420
Mathematical Functions :
• floor(x) :
Returns the smallest integer value less than or equal to x.
one word of caution though, floor(2.5) returns "2.", which needs a bit of
manipulatoin before being put to some uses.
• ceiling( x ) :
Returns the smallest integer value greater than or equal to a value.
similar caution, as ceiling(2.01) returns "3.", and not just "3"
5/16/2019
12 | ©2010, Cognizant Technology Solutions Confidential
Miscellaneous
• next_in_sequence() :
Returns a sequence of integers on successive calls, starting with 1.
the returned value depends on the number of times the function has been called.
• first_defined( a , b ) :
Returns the first defined (not NULL) argument of two arguments.
very similar to NVL function of ORACLE, this is used to translate a null input to a
meaningful, defined output.
In layman's terms,
if we pass 'a' to this function (which will be redirected somewhere else, say in output),
the function will return(send/redirect) 'a' if 'a' is defined, else it will return 'b'.
5/16/2019
13 | ©2010, Cognizant Technology Solutions Confidential
String Functions :
Generally start with 'string_...' or contain 'string' somewhere in their name.
Some interesting string functions :
string_char( string s, int i ) :
Returns the raw character code of a character in a string; helpful if you want to know the ascii
value of a particular string character.
char_string(int c) :
Returns a one-character native string with a specified code.
e.g. char_string(97) returns "a"
5/16/2019
14 | ©2010, Cognizant Technology Solutions Confidential
string_compare(string s1, string s2) :
is similar to strcmp function in C.
re_get_match(string_sentence s1, string_pattern s2) :
will search the pattern s2 in the sentence s1, and returnsthe first
string that matches a regular expression.
the effectiveness of this function lies in the way it can use regular
expressions,
or regex. almost identical to the regex patterns of UNIX, (which we
use in grep command).
for e.g., re_get_match("1234.5678","12") will return "12";
re_get_match("1234.5678","^[0-9][0-9]") will return 12;
re_get_match("1234.5678","^[0-9][0-9]+") will return
1234;
re_get_match("1234.5678","[0-9][0-9]+$") will return
5678;
Nota Bene :Unix users : for wildcard character * of unix, use +, the
complete list can be obtained from AbInitio Help.
5/16/2019
15 | ©2010, Cognizant Technology Solutions Confidential
m_eval
What is it &
How to use it…
follows in next slide
5/16/2019
16 | ©2010, Cognizant Technology Solutions Confidential
m_eval :
testing/ executing commands without actually
executing the graph.
Syntax :
m_eval ‘statement’
Working :
•Press F8 or Run>Execute Command…
•Type (say), m_eval ‘string_lrtrim(“ xyz ”)’
•Press Enter, result will be displayed
in a window.
Note :
•a space after m_eval is a must
• statement MUST be contained within single
5/16/2019
quotes
17 | ©2010, Cognizant Technology Solutions Confidential
Normalize
Normalize generates multiple data records from
each input data record based on specified
number of output records, or the number of
output records can depend on a field or fields in
each input data record. Normalize can separate a
data record with a specified field into several
individual records, each containing one element of
the specified field.
This can be got by clicking on “Transform” in
component organizer then Normalize (Double
Click or drag “Normalize” from Transform).
Double Click or right click, on the Normalize icon to
get the Normalize Properties window.
5/16/2019
18 | ©2010, Cognizant Technology Solutions Confidential
Normalize : properties tab
Click on Parameters tab.
5/16/2019
19 | ©2010, Cognizant Technology Solutions Confidential
Normalize : properties : parameters
Transform – This is where the
transform logic is written.
Reject-threshold – This tells
the component when to abort.
Logging – Tells whether the
component is writing to log port.
Also the frequency of logging
can be mentioned if Logging is
set to “True”.
Click on the Ports tab.
5/16/2019
20 | ©2010, Cognizant Technology Solutions Confidential
Normalize : properties : parameters
The in & out ports record format needs to be defined.
Reject port has the same record format as the Out port.
5/16/2019 Error & log ports have a pre-defined record format.
21 | ©2010, Cognizant Technology Solutions Confidential
Denormalize Sorted
Denormalize Sorted consolidates groups of related
data records into a single output record with a
vector field for each group, and optionally
computes summary fields in the output record for
each group .
Denormalize Sorted requires grouped input.
This can be got by clicking on “Transform” in
component organizer then Denormalize Sorted
(Double Click or drag “Denormalize Sorted” from
Transform).
Double Click or right click, on the Denormalize
Sorted icon to get the Denormalize Sorted
Properties window.
5/16/2019
22 | ©2010, Cognizant Technology Solutions Confidential
Deormalize Sorted : properties
Click on Parameters tab.
5/16/2019
23 | ©2010, Cognizant Technology Solutions Confidential
Deormalize Sorted: properties : parameters
Key-method – Choose the key specifier method.
Either “Use key specifier” (atleast one key needs to be
specified) or “Use key_change function”. (the key value
is constant till the key value changes)
Key – If “Use key specifier” is selected then the key
needs to be mentioned here. (When “Use key_change
function” is selected then this parameter does not
appear)
Transform – This is where the transform logic is
written.
Reject-threshold – This tells the component
when to abort.
Logging – Tells whether the component
is writing to log port. Also the frequency of
logging can be mentioned if Logging is
set to “True”.
Click on the Ports tab.
5/16/2019
24 | ©2010, Cognizant Technology Solutions Confidential
Deormalize Sorted: properties : ports
The in & out ports record format needs to be defined.
Reject port has the same record format as the Out port.
5/16/2019 Error & log ports have a pre-defined record format.
25 | ©2010, Cognizant Technology Solutions Confidential
Rollup
Rollup generates data records that summarize
groups of data records.
This can be got by clicking on “Transform” in
component organizer then Rollup (Double Click or
drag “Rollup” from Transform).
Double Click or right click, on the Rollup icon to get
the Rollup Properties window.
5/16/2019
26 | ©2010, Cognizant Technology Solutions Confidential
Rollup : properties : parameters
Sorted-input – Selected “Input must be sorted or
grouped” if the input records are sorted else
select “In-memory: Input need not be sorted”.
Key-method – Choose the key specifier method.
Either “Use key specifier” (atleast one key needs
to be specified) or “Use key_change function”.
(the key value is constant till the key value
changes)
Key – If “Use key specifier” is selected then the
key needs to be mentioned here. (When “Use
key_change function” is selected then this
parameter does not appear)
Transform – This is where the transform logic is
written.
Reject-threshold – This tells the component
when to abort.
Logging – Tells whether the component is writing
to log port. Also the frequency of logging can be
mentioned if Logging is set to “True”.
Click on the Ports tab.
Click on Parameters tab.
5/16/2019
27 | ©2010, Cognizant Technology Solutions Confidential
Rollup : properties : ports
The in & out ports record format needs to be defined.
Reject port has the same record format as the Out port.
5/16/2019 Error & log ports have a pre-defined record format.
28 | ©2010, Cognizant Technology Solutions Confidential
Gather Logs
Gather Logs collects the output from the
error and log ports of components for
analysis of a graph after execution.
This can be got by clicking on
“Miscellaneous” in component organizer
then Gather Logs (Double Click or drag
“Gather Logs” from Miscellaneous).
Double Click or right click, on the Gather
Logs icon to get the Gather Logs Properties
window.
5/16/2019
29 | ©2010, Cognizant Technology Solutions Confidential
Gather Logs : properties : parameters
LogFile – The path of the physical file where the
logs are to be written is entered in the Path.
StartText – This text will be present at the start of
the log file.
EndText – This text will be present at the end of the
log file.
Note: The StartText & EndText is mainly
to mark the beginning & end of the log file.
Click on the Ports tab.
Click on Parameters tab.
5/16/2019
30 | ©2010, Cognizant Technology Solutions Confidential
Gather Logs : properties : ports
•There is no out port as this component is used only for logging.
The in port record format needs to be defined.
5/16/2019
31 | ©2010, Cognizant Technology Solutions Confidential
End of Day 4
Proceed to Day 5
Back to Index
5/16/2019
32 | ©2010, Cognizant Technology Solutions Confidential