Four Stars

how to get top 5 for each customer from a flat file

There is a flat file with CustomerID, OrderDate, SalesAmount.

Each customer can have multiple orders. The report will get the recent 5 orders for each customer.

It is easy to do in SQL, but the source is a flat file and the data will not be loaded to SQL database.

 

Is there any way in Talend to apply this scenario? Thank you very much for your help.

(if a new column RowNumber is added to the data flow and the value is set to 1,2,3,4,5,...for each customer, then a tFilterRow can get the records with RowNumber<=5

how to write java code in the tjavaflex?)

CustomerIDOrder DateSalesAmount
18/23/20176.6
18/11/20176.6
18/7/20176.6
17/29/20176.6
17/23/20176.6
17/16/20176.6
17/3/20176.6
18/23/20176.6
17/23/20176.6
26/23/20176.6
24/23/20176.6
21/23/20176.6
  • Data Integration
Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars sgv
Six Stars

Re: how to get top 5 for each customer from a flat file

Hi,

Yes with tJavaFlex it's look like fine . Your code can be like :

 

TFileInput ---row11--- tJavaFlex --- row12 --- tlogrow

 

Capture.PNG

 

Don't Forget to add a column to your tJavaFlex output schema.

This will be work but you have maybe some special code to limit case like first and last line

 

Good luck

SGV

2 REPLIES
Six Stars sgv
Six Stars

Re: how to get top 5 for each customer from a flat file

Hi,

Yes with tJavaFlex it's look like fine . Your code can be like :

 

TFileInput ---row11--- tJavaFlex --- row12 --- tlogrow

 

Capture.PNG

 

Don't Forget to add a column to your tJavaFlex output schema.

This will be work but you have maybe some special code to limit case like first and last line

 

Good luck

SGV

Four Stars

Re: how to get top 5 for each customer from a flat file

SGV: thank you for your reply. Your solution works like magic.