Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
hi Team,
i wanted to compare two date columns coming from two tables
i used TalendDate.compareDate(date1,date2) != 0 as it is returning an integer value this is not expected result
getting null pointer exception in tmap, please help on it.
Regards,
Meena
Thanks for your inputs my issue has been fixed, i am very thankful to you for giving me prompt response
row1.date1 == null && row2.date2 == null ? false :
(
row1.date1!= null && row2.date2!= null ?
(
TalendDate.compareDate(row1.date1,row2.date2)==0? false: true)
:true), i used this condition in tmap
This fixed my issue i compared with nulls too.
once again Thank you all
Regards,
Meena
What is the expected result? Can you show me the tMap settings?
OK, in your tMap filter you need.....
TalendDate.compareDate(row1.date1,row2.date2) != 0
.....the nulls are handled by the routine method.
I'm guessing that your tMap output schema has the date column set to not nullable. I suspect that row2.date2 is null when it fails. However I will need to see the tMap config to tell if this is true
@muralam,first handale the nulls for bothe dates and comprare so that you will not get null pointer exception.
@manodwhb nulls are handled by the method.
/**
* compare two date
*
* @param date1 (first date)
* @param date2 (second date)
* @param pattern (compare specified part, example: "yyyy-MM-dd")
* @return the result wheather two date is the same, if first one less than second one return number -1, equlas
* return number 0, bigger than return number 1. (can compare partly)
*
* {talendTypes} Integer
*
* {Category} TalendDate
*
* {param} date(myDate) date1 : the first date to compare
*
* {param} date(myDate2) date2 : the second date to compare
*
* {param} String("yyyy-MM-dd") pattern : compare specified part
*
* {examples}
*
* ->> compareDate(2008/11/24 12:15:25, 2008/11/24 16:10:35) return -1
*
* ->> compareDate(2008/11/24 16:10:35, 2008/11/24 12:15:25) return 1
*
* ->> compareDate(2008/11/24 12:15:25, 2008/11/24 16:10:35,"yyyy/MM/dd") return 0 #
*/
public static int compareDate(Date date1, Date date2, String pattern) {
if (date1 == null && date2 == null) {
return 0;
} else if (date1 != null && date2 == null) {
return 1;
} else if (date1 == null && date2 != null) {
return -1;
}
if (pattern != null) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String part1 = sdf.format(date1), part2 = sdf.format(date2);
return (part1.compareTo(part2) >= 1 ? 1 : (part1.compareTo(part2) <= -1 ? -1 : 0));
} else {
long time1 = date1.getTime(), time2 = date2.getTime();
return (time1 < time2 ? -1 : (time1 == time2 ? 0 : 1));
}
}
yes @rhall,then he shoul dnot get null pointer exception in tmap while comparing.it coud be other filed that he needs to handle nulls in tmap.
Can you send us the complete nullpointerexception error?