Data extraction "this month" using tfilter

Highlighted
One Star

Data extraction "this month" using tfilter

Hi,
I want to this month data from csv to csv using tfilter.
now Date format MM-DD-YYYY in csv, and talend batch run next day.
How can I compare (current day -1)month and MM-DD-YYYY data?

sorry for short message question.
thanks.
Miki

Highlighted
Community Manager

Re: Data extraction "this month" using tfilter

Hi
Sorry, I don't understand your question well, can you please try to explain it some example data again?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: Data extraction "this month" using tfilter

Hi,
I want to retrieve only the current month of data from csv using tfilterrow.



Source data image is ;  
------------------------------
Date ,  Sales 
07-01-2014, 10000,
07-02-2014, 20000,
07-03-2014, 10000,
 :
 :
09-09-2015, 30000,


Output image is ;
------------------------------
Date |  Sales 

09-01-2015, 30000,

09-02-2015, 20000,

09-03-2015, 30000,

09-04-2015, 30000,

09-05-2015, 30000,

09-06-2015, 30000,

09-07-2015, 30000,

09-08-2015, 30000,

09-09-2015, 30000,



(only current month) 

Thanks.

Miki
Highlighted
Community Manager

Re: Data extraction "this month" using tfilter

Hi
You can populate the current month whenever you execute the job on a tJava with following code:
 
java.util.Date mydate=TalendDate.getCurrentDate();
int year=TalendDate.getPartOfDate("YEAR",mydate);
int month=TalendDate.getPartOfDate("MONTH",mydate)+1;
String months=String.valueOf(month);
if(months.length()==1){
months="0"+months;
}

java.util.Date currentMonth=TalendDate.parseDate("yyyy-MM-dd", year+"-"+months+"-"+"01");
globalMap.put("currentMonth",currentMonth);

Then, you can compare the current date column with the current month date on tFilterRow component to filter the rows, eg:
tJava
 |
onsubjobok
 |
tFileInputDelimited--main--tFilterRow--main--tLogRow
on tFilterRow, check the 'Use advanced model' box, and write the following code:
TalendDate.compareDate(input_row.dateColumn, (java.util.Date)globalMap.get("currentMonth")


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: Data extraction "this month" using tfilter

Hi,

Thank you for support, and I tried to test, but some error was occured.

error messsage said that input type is unmatch.

How can i resolve this problem?

-----------------------------------------

[statistics] connecting to socket on port 3810
[statistics] connected
Exception in thread "main" java.lang.Error: 
 ? Operator_tFilterRow_1 ????? matches(boolean, String) ??? (int, String) ????????


    ? type Operator_tFilterRow_1 method matches(boolean, String)  can't use argument(int,String).

 at cpc.test_month_compare_0_1.test_month_compare.tJava_1Process(test_month_compare.java:412)
 at cpc.test_month_compare_0_1.test_month_compare.runJobInTOS(test_month_compare.java:4362)
 at cpc.test_month_compare_0_1.test_month_compare.main(test_month_compare.java:4219)
[statistics] disconnected
??? test_month_compare ? 10:16 11/09/2015 ???????? [?????=1]


-----------------------------------------

I tried to upload image files, but can't login correctly this community, 
URL redirection seems to be failure  the login information.

Thanks.
Highlighted
Community Manager

Re: Data extraction "this month" using tfilter

Hi 
It is a compilation error, there must be a wrong configuration on tFilterRow component. You can send me the job design via email right now.
If you have login issue, please report a new topic with details for it, we will forward it to our IT team for help.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: Data extraction "this month" using tfilter

Hi,
I sent a e-mail to you including export Jobs.
Thank you for your support.

Miki
Highlighted
Community Manager

Re: Data extraction "this month" using tfilter

Hi Miki 
It is a wrong code on tFilterRow, change it to the code as below should work.
TalendDate.compareDate(input_row.Date,(java.util.Date)globalMap.get("currentMonth"))==1
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: Data extraction "this month" using tfilter

Hi,
I could error handling fine,but this output file has incorrect, lack of data.

this job can get data from 2015/09/02- today.
How can i get from 2015/09/01 - today?
 
Thanks.

Miki
Highlighted
Community Manager

Re: Data extraction "this month" using tfilter

change the code to
TalendDate.compareDate(input_row.Date,(java.util.Date)globalMap.get("currentMonth"))>=0

It will include the first day of each month.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: Data extraction "this month" using tfilter

Hi,
I tried it, but it was not in the correct output.
now output range is 2015/07/01- Today.Smiley Sad

I am confused out the expected value and different output.
I tried to change the Talend version, but the results were the same.
Is there any other way?

Thanks.

Miki
Highlighted
Community Manager

Re: Data extraction "this month" using tfilter

Hi Miki 
I don't understand the output result, it seems the filter condition does not take effect, I tested the code and it works fine on my side! Can you upload some screenshots of your job? I think there must be something wrong in your job.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Talend Integration with Databricks

Take a look at this video about Talend Integration with Databricks

Watch Now