Wednesday, 28 August 2013

Talend File Rank


I have received some queries about apply Dense Rank for the files. Below post will give clear idea.
Please have a look at the below table.
I have to generate Dense Rank depending upon "Total Sales" column values


CustomerID Name Total_Sales
1010 Pivot Point College 1127
1018 Petes Auto Repaire 1127
1022 Green Bay Travel Services 1127
1009 BBQ Smith's Tex Mex 1137
1017 janice Mann Accounting Service 1137
1021 Bee Line Publishing 1137
1007 Vanity Town 1199
1015 Resnick DDS 1199
1019 Michael Montgomery Hair Saloon 1199
1006 Nitelites Party Rental 1227
1014 Acturial Enterprises Ltd. 1227

The following job will give the rank for the above table.

  1. tFineInputExcel: Reading data from excel with above table
  2. tSortRow : Sort the rows based on "Total Sales" either Ascending / Descending order
  3. tMemorizeRows: Memory the last two rows of "Total  Sales" values
  4. tJavaFlex: I have written some java code here for Rank I explained in below
  5. tMap: To map source and destination
  6. tFileoutputExcel: To load data in destination




Declare one variable in context "cnt"

Java code in tJavaFlex:

Start Code:
                              int count=0;

Main Code:

         if  (!TOTAL_SALES_tMemorizeRows_2[0].equals(TOTAL_SALES_tMemorizeRows_2[1]))
             {
                     count++;
              }
        context.cnt=count;



Finally you will get output like below table.

CustomerID Name Total_Sales Rank
1010 Pivot Point College 1127 1
1018 Petes Auto Repaire 1127 1
1022 Green Bay Travel Services 1127 1
1009 BBQ Smith's Tex Mex 1137 2
1017 janice Mann Accounting Service 1137 2
1021 Bee Line Publishing 1137 2
1007 Vanity Town 1199 3
1015 Resnick DDS 1199 3
1019 Michael Montgomery Hair Saloon 11993
1006 Nitelites Party Rental 12274
1014 Acturial Enterprises Ltd. 12274


No comments:

Post a Comment