Wednesday, December 5, 2012

3. Design a mapping to load the last 3 rows from a flat file into a target?

3. Design a mapping to load the last 3 rows from a flat file into a target?

Solution:
Consider the source has the following data.
col
a
b
c
d
e

Step1: You have to assign row numbers to each record. Generate the row numbers using the expression transformation as mentioned above and call the row number generated port as O_count. Create a DUMMY output port in the same expression transformation and assign 1 to that port. So that, the DUMMY output port always return 1 for each row.

In the expression transformation, the ports are
V_count=V_count+1
O_count=V_count
O_dummy=1

The output of expression transformation will be
col, o_count, o_dummy
a, 1, 1
b, 2, 1
c, 3, 1
d, 4, 1
e, 5, 1

Step2: Pass the output of expression transformation to aggregator and do not specify anygroup by condition. Create an output port O_total_records in the aggregator and assign O_count port to it. The aggregator will return the last row by default. The output of aggregator contains the DUMMY port which has value 1 and O_total_records port which has the value of total number of records in the source.

In the aggregator transformation, the ports are
O_dummy
O_count
O_total_records=O_count

The output of aggregator transformation will be
O_total_records, O_dummy
5, 1

Step3: Pass the output of expression transformation, aggregator transformation to joiner transformation and join on the DUMMY port. In the joiner transformation check the property sorted input, then only you can connect both expression and aggregator to joiner transformation.

In the joiner transformation, the join condition will be
O_dummy (port from aggregator transformation) = O_dummy (port from expression transformation)

The output of joiner transformation will be
col, o_count, o_total_records
a, 1, 5
b, 2, 5
c, 3, 5
d, 4, 5
e, 5, 5

Step4: Now pass the ouput of joiner transformation to filter transformation and specify the filter condition as O_total_records (port from aggregator)-O_count(port from expression) <=2

In the filter transformation, the filter condition will be
O_total_records - O_count <=2

The output of filter transformation will be
col o_count, o_total_records
c, 3, 5
d, 4, 5
e, 5, 5

6 comments:

  1. Iam really satisfy by your information.
    It's well-written, to the point, and relative to what I do.
    I like it very much for giving information on
    Excellent Informatica Online Training
    .

    ReplyDelete
  2. I have a question. Can you please explain why checking the sorted input option in joiner transformation allows us to connect both expression and aggregator transformations to joiner transformation? Did not really understand the reason.

    ReplyDelete
    Replies
    1. you can even use MOD function to get the last 3 records..

      Delete
    2. you can not connect two active transformation in parallel, to connect active transformation, we are using joiner and its by default compulsion to tick on sorted input, if you will not tick on it then it would never connect the port from another transformation .
      and whenever you tick on sorted input, it considers the master table is already in the sorted form.

      Delete
  3. take seq no, take a rank and choose bottom 3 rank connect to target... is it simple?

    ReplyDelete

Thank you :
- kareem