Sunday, July 8, 2018

Datastage execution process


IBM InfoSphere DataStage is a GUI based ETL tool which allows us to use familiar graphical point-and-click techniques to develop job flows for extracting, cleansing, transforming, integrating, and loading data into target files, target systems, or packaged applications. It abstracts the actual processing from the developer. This document throws light on what happens in the background of DataStage when an ETL job goes through different phases – design, compile and execution.
How DataStage Works?
DataStage falls under second generation ETL tools which have a provision of creating visual ETL task flows. A GUI-based ETL tool can leverage the productivity and quality of ETL development and maintenance. ETL job designed using GUI-based ETL tools will only give a “big picture” of the design. It is just a picture identifying the source(s) of data, the processing that the data are to undergo, the target(s) for the data and some relevant documentation.
The design paradigm of DataStage is that, ETL design should be a “big-picture”, so that even business users who have minimal or no technical knowledge can grasp the intent of the design. A simple requirement could be, reading from a text file, aggregating data based on grouping keys, and finally writing the results into another text file. When the ETL for this requirement is designed, it would show a picture showing the source component where the file is read, aggregation component where summarization is done, the target component where the final results are written to a file. But this is not all that will accomplish the task. To make it work, we need to go “under the covers” and fill in the details – the pathname of the source file, format, which columns are to be grouped and aggregated, the pathname of the target file, and so on.
Moreover, how DataStage works depends on the job type and the current phase of the job. DataStage supports different job types – Server Jobs, Parallel Jobs and Mainframe Jobs. Design-Time, Compile-Time and Run-Time are three different phases that any DataStage job goes through in its life cycle.
Let us get into details on what happens under the covers right from the beginning.
DataStage Client/Server Connectivity:
A simple DataStage infrastructure consists of DataStage server and a local area network on which one or more DataStage client machines may be connected. Connection from a DataStage client to a DataStage server is managed through a mechanism based upon the UNIX remote procedure call mechanism. DataStage uses a proprietary protocol called “DataStage RPC” which consists of an RPC daemon (dsrpcd) listening on TCP port number 31538 (default) for connection requests from DataStage clients.
But before dsrpcd gets involved, the connection request goes through an authentication process. Authentication is handled by the Information Server through its “login and security service”.

Each connection request from a DataStage client asks for connection to the dscs (DataStage Common Server) service. The dsrpcd (the DataStage RPC daemon) checks itsdsrpcservices file to determine whether there is an entry for that service and, if there is, checks whether the requesting machine’s IP address is authorized to request that service. If so then the executable associated with the dscs service (dsapi_server) is invoked.
DataStage Processes:
For each valid client connection, a “dsapi_server” process is invoked and this process manages traffic, inactivity timeout and also acts as an “agent” on the DataStage server for its own particular client connection. If the client requests access to the Repository, then the dsapi_server process will fork a child process called “dsapi_slave” to perform that work. Typically, therefore, one would expect to see one dsapi_server and one dsapi_slave process for each connected DataStage client. Processes may be viewed with the ps -ef command (UNIX) or with Windows Task Manager. To check for DataStage client connections use:
ps –ef | grep dsapi_slave or ps -ef | grep dscs
Every DataStage process attaches to a shared memory segment that contains lock tables and various other inter-process communication structures. Further each DataStage process is allocated its own private shared memory segment. Shared memory allocation may be viewed in three ways: using the ipcs command (UNIX) or the shrdump command (Windows) or use the analyze.shm command from an operating system command prompt to examine the disk and printer shared memory segments.
In UNIX, check datastage shared memory segments usingipcs – mop | grep ade and to remove them use ipcrm -m ID, where ID is the number from the second column of ipcs –mop
When there are no connected DataStage clients, dsrpcd may be the only DataStage process running on the DataStage server. However, there could be more running at times. This is because, the DataStage deadlock daemon (dsdlockd) wakes up periodically to check for deadlocks in the DataStage database and, to clean up locks held by defunct processes – usually improperly disconnected DataStage clients. JobMonApp is another process that runs at times. A Java application that captures “performance” data (row counts and times) from running DataStage jobs called Job Monitor runs as JobMonApp.
Let us now get into details regarding OSH (Orchestrate), Node Configuration to get better idea of Parallel jobs.
Orchestrate Shell Script
At Compile-Time, the Designer first validates all link requirements, mandatory stage options, transformer logic, etc. It then generates a framework representation of data flows and stages – OSH (Orchestrate Shell Script). For each stage in the job design, there is an Operator, and other relevant information for that operator (such as schema and options) within the script. For each Transformer stage in the design, transform code is generated, i.e., DataStage builds a
C++ Framework operator which is then compiled into C++ and then to corresponding native operators. So when a job contains a Transformer, it takes longer to compile (but not to run). This is why an ANSI-compliant C compiler is required for installations where parallel jobs will be designed. If Custom stages that use reusable BuildOp stages are included in the job design, the C++ code in those BuildOps must also be compiled; this can be done using the Designer GUI or command line.
When the Stages on the diagram are mapped to native Operators, it is not necessary for the mapping to be a one-on-one. Some stages are based on a range of related operators and which one is used depends on the setting of the stage’s properties. All of the stages can include common operators such as partition and sort depending on how they are used in a job. For example, when a Sequential stage is used as a source it is mapped to import operator, as data from the text file (ASCII) has to be imported into native DataStage format. When used as a target it is mapped to the export operator. The converse also holds true. That is different stages get mapped to a single operator. For example, Row Generator and Column Generator are both mapped to the generator operator.
Operators are the basic functional units of an Orchestrate application. An OSH operator is an instance of a C++ class of APT_Operator. Operators read records from input data sets, perform actions on the input records, and write results to output data sets. An operator may perform an action as simple as copying records from an input data set to an output data set without modification. Alternatively, an operator may modify a record by adding, removing, or modifying fields during execution.
Let us consider the below depicted job. The design has three stages connected. At compile time, design is primarily converted into an OSH (Orchestrate shell).

In the below depicted OSH, Comment blocks introduce each operator, the order of which is determined by the order stages were added to the canvas. However, the actual execution order of operators is dictated by input/output designators, not by placement on the diagram. OSH uses the familiar syntax of the UNIX shell, such as Operator name, schema, operator options (“-name value” format), input (indicated by n< where n is the input#), and output (indicated by the n> where n is the output #). For every operator, input and/or output data sets are numbered sequentially starting from zero. Virtual data sets (in memory native representation of data links) are generated to connect osh operators.

Node Configuration
In DataStage, the degree of parallelism can be changed dynamically by making changes to the file called Configuration file, which contains the number of nodes on which the job runs and the resources to be utilized for job. Configuration file defines how many nodes should be used to run the job in parallel, where to store the temporary data, where to store the intermediate datasets, which database specific nodes should be used for optimum resource allocation and performance of the data load job.
The important thing is that all you need to do to scale up your job for greater throughput is to specify a configuration file with additional processing nodes. No changes to job design are required. No recompilation is required. The configuration files (and the Conductor process) look after it all. To specify a different configuration file, change the value of the APT_CONFIG_FILE environment variable.
The name of the default configuration file is default.apt. Maximum flexibility is obtained by making this into a job parameter, so that any of the available configuration files can be selected when the job is run. Unless someone changes the default location, it is to be found in a directory called Configurations, in the DataStage Engine directory ($DSHOME) on the server machine. If this location cannot be found, then DataStage also searches in the etc directory in the $APT_ORCHHOME directory.
Let us now go through the life cycle of a Parallel Job.
Parallel Job Life Cycle
As said earlier, job type does matter in understanding DataStage execution process. This document is restricted to parallel job type. To understand how DataStage handles parallel jobs, we need to consider the architectural differences when designing, when compiling and when executing.
IBM InfoSphere DataStage Designer client is used to create DataStage jobs that are compiled into parallel job flows, and reusable components that execute on the parallel Information Server engine.
Design-Time Architecture
Job type doesn’t matter when designing, as the architecture for Parallel, Server and Mainframe jobs is same at Design-Time, because, the developer uses the same Datastage Designer client. Developer has the choice to choose the job type – a server job, a parallel job or a mainframe job that is to be worked upon.
Compile-Time Architecture
Compile-Time architecture of Parallel job is different from that of a Server job or a Mainframe job. When a parallel job is compiled, a directory RT_SCnn (where nn is the job number) gets created. This folder contains the actual Orchestrate script OshScript.osh generated for the job and the script OshExecuter.sh for invoking osh. OshExecuter.sh uses the environment variable APT_ORCHHOME to determine the location of the executable.
If viewing generated OSH is enabled in Administrator, it can be viewed from the Generated OSH tab in Job Properties, Job Run Log in Director. For passive stages, See OSH option is available in View Data dialog.
Run-Time Architecture
Parallel jobs are executed under control of DataStage Server runtime environment. In IBM Infosphere DataStage when we RUN a job from Director/Designer, or when we invoke it from the command line interface using dsjob command or invoke it using DSRunJob() function, the job doesn’t run immediately, in fact a request is issued to the Engine to invoke execution of the job. When a request to run a job is made, it is exactly that: a request. Similarly, when we try to stop a job, it is a STOP request; it causes a signal to be sent to the running process.
As request made is asynchronous by default, the requesting user does not retain any control of the request made and jobs do not run as child processes of the requesting user process. So whether that process can handle the signal governs whether the Stop/Start request is successful.
Once the START request is successfully made, processing of request depends on the job type.
Conductor Process:
When a run request is processed for a parallel job, the first process to start is the Conductor process. This runs an Orchestrate shell (osh) on the server machine. It picks up values of all environment variables that are required, one of which (APT_CONFIG_FILE) locates the configuration file for this run of the job. Location of the osh executable is supplied via the APT_ORCHHOME environment variable.
Conductor composes Job “score” using the OSH and configuration file. This is similar to SQL query optimization plan generated by an RDBMS. It identifies the degree of parallelism and node assignments for each operator, inserts sorts and partitioners as and when needed to ensure correct results, defines connection topology (virtual datasets) between adjacent operators, inserts buffer operators to prevent deadlocks in fork-joins, defines number of actual OS processes, where possible, optimize resource requirements by combining multiple operators within a single OS process, where possible, thereby improving performance.
Job Score is used to fork processes with communication channels for data, message, and control. To have insights on what happens in the background, set$APT_STARTUP_STATUS environment variable to show each step of job startup and $APT_PM_SHOW_PIDS to show process IDs in DataStage log. Only after the score is composed and all the processes are created, actually processing begins. Startup time in the below screenshots tells us the time taken to compose score and to fork all processes.

Job processing ends when the final operator processes the last row of data or when any of the operator encounters a fatal error or when the Job receives a halt (SIGINT) signal either because of DataStage Job Control or because of human intervention (STOP request issued from DataStage Director).
When $APT_DUMP_SCORE is set, Job Score is output to the job log. One can see 2 score dumps written in the job log for each job. Of them, first one is for license operator and the second entry is the real job score. Score dump event can be identified from the job log, by looking for “main program: This step …”.
In the below depicted Job Score, it can be seen that, score is divided into two sections – DataSets and Operators. Datasets represent the partitioning and collecting, while operators are the mapping of stages to nodes. Job Score yields very useful info like the number of operators, sequential/parallel processing that each operator does, stage combinations, run-time insertions of sort and buffer operators and the total number of actual processes.

Conductor is responsible for forking a “section leader” process on each processing node which runs osh on that node. Section leader processes communicate with the conductor process about the progress, which then consolidates all messages from various processing nodes, and writes them into the job log.
Once all the section leader processes indicate that processing on their processing node is complete, the conductor process performs a final cleanup.
Section Leader Process:
As said earlier, each processing node starts a “section leader” process which runs osh on that node. Its job is to coordinate processing on that particular node. It extracts its instructions from the osh script generated by compiling the parallel job.
The task of each section leader process is to fork instances of required player processes to execute each of the operators in the osh script. Schema information, (re-)partitioning information and other options are passed to each player process, stdout and stderr of which are redirected to the parent section leader process. Section leader processes communicate with the conductor process, primarily to pass back any messages to be logged, and to notify of completion and status.
Player process:
A player process executes operators from osh. It runs osh to invoke the method(s) exposed by an operator. An operator is an instance of a C++ operator inheriting from APT_Operator.
Player processes communicate with each other to facilitate data transfer. If the players are on the same machine (an SMP environment), then communication is done through shared memory. If the players are on separate machines (an MPP cluster environment) then communication is effected using TCP.
Every player will be able to communicate with every other player. There are separate communication channels (pathways) for control, messages, errors, and data. There wont be any data channel going through the section leader/conductor, as this would limit scalability. Data flows directly from upstream operator to downstream operator using APT_Communicator class. Conductor and Section Leader communicate only via Control Channel. Section Leader communicates with player processes in three different channels, one for Control, the other two for stdout and stderr.
Each player process may consume disk space from the resource disk allocated to its processing node and/or from the resource scratch disk allocated to its processing node in the configuration file for the job. For example, a Sort stage will spill to disk when its memory limit property is exceeded.
Conclusion:
Thus we saw the Client-Server connectivity in DataStage, the processing that occurs at design-time, at compile-time, and at run-time. We learnt how to read job log, OSH, job score and the whole orchestrate execution process.

Datastage Tips

  • Problem 1: How to do Cartesian join Ã¨ Join every row of a table to every row of other table
  • Solution : Use “column generator” stage
  • How to :
1) Add both tables in DS job
2) Add dummy column using “Column Generator” stage each for both tables. Make sure dummy column values are same.
3) Join both tables using these dummy columns
  • Problem 2: How to add century break for date value
  • Solution : Use “Format” string option in Date Type
  • How to:
For date column, add format string based on century break value you required.
  • Problem 3: How to add DataStage Echo statements for OSH statements
    • Solution: Set “OSH_ECHO” parameter value to “True”
    • How to:
      • From project parameter list, add “OSH_ECHO”
      • Set default value to “True”
  • Problem 4:How to count number of jobs in DS project
    • Solution: Use dsjobs “-ljobs” command
    • How to: Go to DS Administrator “projects” tab
      •     Click on command button
      •     Enter following command to execute:
      •     SH -c “dsjob -ljobs | wc -l”
  • Problem 5: How to execute Unix command from DS job
    • Solution : Use “External Source” stage in DS job
    • How to:
      • Add “External Source” stage in DS job
      • In source program property, enter Unix command
  • Problem 6: How to suppress job warnings in DS job log
    • Solution: Add “rule” in Message Handler
    • How to:
      • From DS Director, from Message Handler, add a rule
      • Select Warning message as example of Message text
  • Problem 7: How to use “Otherwise” constraint in Transformer Stage
    • Solution: To use “Otherwise” constraint in Transformer stage, Order of link is important.
    • How to:
      • Typically link with “Otherwise” constraint should be last in Transformer stage link order
  • Problem 8: How to set Pad Character in DS Job
    • Solution: Use “APT_STRING_PADCHAR” project parameter
    • How to:
      • From project parameters, add “APT_STRING_PADCHAR” in DS job parameters
      • Set value for this parameter with required character
    • Note:
      • DS Default value is 0x0 ASCII NULL character
      • Override is mainly useful for column with data type CHAR
  • Problem 9: How to get a last record
    • Solution: Use “Tail” stage in DS job
    • How to:
      • Add “Tail” stage in DS job
      • Specify “Number of Rows” = 1
  • Problem 10:How to get category name from DS job name
    • Solution :Use following statement: Select * from DS_JOBS where NAME = ‘’;
    • How to:
      • Go to DS Administrator “projects” tab
      • Click on command button
      • Enter following command to execute:
      Select * from DS_JOBS where NAME = ‘’;
  • Problem 11: How to get DS job detailed information in log
    • Solution: Set “APT_DUMP_SCORE” parameter value to “1”
    • How to:
      • From project parameters, add “APT_DUMP_SCORE” as job parameter
      • Set value to “1”
  • Problem 12: How to Reject Sequential file records with strings longer than their declared maximum column length
    • Solution: Set “APT_IMPORT_REJECT_STRING_FIELD_OVERRUNS” to “1”
  • Problem 13:What to use instead of “Transformer” Stage
    • Solution:
      • Use “Copy” stage instead of “Transformer” Stage for following:
        • Renaming columns
        • Dropping columns
        • Default type conversions
        • Job design placeholder between stages
      • Use “Modify” stage
        • Non default type conversions
        • Null handling
        • Character string trimming
  • Problem 14 : How to copy group permissions from one project to other
    • Solution : From Unix, copy following files from source project to target project dir: .developer.adm, .operator.adm, .prodmgr.adm
    • How to:
      • Login to Unix server using “dsadm” account
      • Go to target project dir “/local/data1/Ascential/DataStage/
      • Copy .adm files from source project to this project

Complex flat file data load to a table

This document gives the step by step procedure to develop a data stage job. This job gets the data from a Complex Flat File and Loads in a table.
  • Step 1 – Import COBOL File Layout
  • Step 2 – Import Table Definitions
  • Step 3 – Create DS Jobs
  • Step 4 – Job Compilation
  • Step 5 – Job Execution
Step 1 – Import COBOL Definitions
  1. Open Webspehere Datastage Designer Window.
  2. Import Ã  Table Definitions Ã  COBOL File Definitions. (Shown as below Fig)

  3. Provide the path of the COBOL Layout File in the COBOL File Pathname as shown below and Click Import.

  1. After Click import, the Table and To source will be updated Automatically. The Table will be saved as mentioned in the ‘To folder’ Tab.

Step 2 – Import Table Definitions
  1. Open Webspehere Datastage Designer Window.
  2. Import Ã  Table Definitions Ã  Start Connector Import Wizard.

  1. In the Connector Metadata import window, Select desired connector from ‘Connector selection’ list and click Next. In the below figure, the ODBC connector is selected.
+
  1. In the ‘Connection details’, provide the appropriate Datasource and the credentials and then click Text.

  1. In the Filter Page, Select the Appropriate schema name and rpovide the table name in the ‘Name filter’ from the text box and click ‘Next’

  1. In the selection section, select Appropriate table name and click ‘Next’

  1. After Reviewing the Table Information, click ‘Next’.

Step 3 – Create DS Job
  1. Open Datastage Designer Ã  File Ã  New Ã  Parallel Job. Then Click ‘Ok’

  1. Drag and Drop the required [CFF stage, DB2 connector stage, transformer stage] stages from the Repository palette.

  1. Right click on one stage and drag it to the next stage to create a link

  1. Rename the stages and links with a proper name.

Please Note that, a File to Table Load job would require a transformer stage only if there is a mapping columns required between the source file and the destination table, Unless it is not required.
  1. Set the Requried Parameters for the job. [Database Name, Username, Password, Table Name and the schema name.]

  1. After set the Parameters, Go to the CFF_table_input Properties – From the File Options tab, Provide the file name of the Complex Flat File.

In the file options tab you need to specify the type of file from which it reads or writes.
When your file is source file, the options you can select.
  1. File(s) – A single file or multiple files. This option is the default.
  2. File Pattern – When you have a group of files. This option is available only for source stages.
  3. Source – One or more Programs and arguments that provide source data to the import Operator.
  4. Source List – A file which contains the names of multiple programs that will provide source data to the import operator.
When your file is Destination file, te Options you can select.
  1. File(s) – A single file or multiple files. This option is the default.
  2. Destination – It will read one or more programs and arguments that data was exported.
  3. Destination List – A file that contains the names of multiple programs that provide destinations for the exported data.
  1. CFF_table_input Properties – From the Records tab, Load the Imported COBOL layout as we did in STEP-1 and then Click ‘OK’

  1. Now the table defintions will be loaded into the stage as shown in the screenshot

  1. Double – Click the TRNS_table_mapping stage – Map all the source file columns to output target as shown in the below screenshot. (You can apply any logic in the transformer stage based on the business requirement unless omit this stage if it is direct mapping.)

  1. DB2_table_output – From the Properties tab, the parameters have to be set for DB Name, Username, Password and the Table name.

Once you given the Appropriate connection details, test the DB connections by clicking ‘Test’ and View the data by clicking ‘ViewData’. Then Click ‘ok’
  1. DB2_table_output – Column properties. From the columns tab, load the table definition that you have imported in step – 2. Select the fields that are requried to load into the target table.

  1. If the Write mode is set to Bulk Load – Set the associated Properties too

  1. Change Message File – To a File Directory, where the DB2 loader writes diagnostic messages. The database instance must have read/write privileges to the file. (Note:- Give the right path to the message file, the file name is the defaulted one which is shown the below screenshot)

Since we are doing non-logged insert, there should be some place we need to log the errors (in case of abends). So, we are giving the file name in the “message file” option.
  1. Change Non-Recoverable load – Yes. With this options, table spaces are not put in backup pending state following the load operation, and a copy of the loaded data does not have to be made during the load operation.
  • Data Buffer Size – Set depending on the resources available.
  • Sort Buffer Size – Set depending on the resources available.
  • CPU Parallelism – Set depending on the CPUs available.

  1. In addition to the above mentioned properties, one can parameterize the record count and Array size options to have the flexibility of entering different values for these options, as per our requirement, each time the job is run. We also need to optimize these values to suit the size of the tables involved.

  1. Save the Job.
Step 4 – Job Compilation
  1. Clickt the Icon to compile the Job.

  1. Once it is sucessfully compiled, you can be able to see the window as shown. Click ‘Close’ then.

Step 5 – Job Execution
  1. Click the Icon to Run the Job.

  1. The table is loaded Successfully.