Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

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

Labels (2)
11 Replies
Anonymous
Not applicable

Hi
Sorry, I don't understand your question well, can you please try to explain it some example data again?
Best regards
Shong
_AnonymousUser
Specialist III
Specialist III
Author

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
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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.
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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

Miki
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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

this job can get data from 2015/09/0 2- today.
How can i get from 2015/09/0 1 - today?
 
Thanks.

Miki
Anonymous
Not applicable

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