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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Sudhee_Maximus
Creator
Creator

Run IF condition is not working as expected

In my tjava assigned below values ...

 

System.out.println("Testing the results");
System.out.println("*******************");

System.out.println("File_Name_Input_S3="+StringHandling.RIGHT((String)globalMap.get("row11.File_Name"),20));
System.out.println("File_Name_Derived="+context.File_Name_Header);
System.out.println("*******************");

System.out.println("MainJOb_Rowcount="+context.f_rowcount);
System.out.println("From child job="+(context.lines_processed+context.lines_errored ));
System.out.println("*******************");

System.out.println("Date_Boolean="+context.Date_boolean);

System.out.println("Testing results END");
System.out.println("*******************");
context.f_filename=StringHandling.RIGHT((String)globalMap.get("tFileExist_1_FILENAME"),20);
System.out.println("*******************");
System.out.println("f_filename="+context.f_filename);

 

my o/p also as below

 

Testing the results
*******************
File_Name_Input_S3=AME_PROV20190611.DAT
File_Name_Derived=AME_PROV20190611.DAT
*******************
MainJOb_Rowcount=5054
From child job=5054
*******************
Date_Boolean=false
Testing results END
*******************
*******************
f_filename=AME_PROV20190611.DAT

 

but when I use the below condition in run if this is failing as resulting in false ....

 

context.File_Name_Header == context.f_filename
&&
context.f_rowcount == context.lines_processed+context.lines_errored

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi,

 

   Filename is a String and it would be ideal to use .equals() function to do data comparison. You will have to also handle null check using Relational.ISNULL function. Could you please make necessary changes and try it again?

 

    I am not giving exact answer so that you will get time to debug. If you are stuck, please feel free to come back.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

 

View solution in original post

8 Replies
Anonymous
Not applicable

Hi,

 

   Filename is a String and it would be ideal to use .equals() function to do data comparison. You will have to also handle null check using Relational.ISNULL function. Could you please make necessary changes and try it again?

 

    I am not giving exact answer so that you will get time to debug. If you are stuck, please feel free to come back.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

 

Sudhee_Maximus
Creator
Creator
Author

may I know why there is behavioral difference between == and .equals() , though I have used both in multiple occasions I was wondering why they both act differently ?
I have similar kind of ? on finding nulls 
used 

not able to find nulls when used Relational.ISNULL  and == null but when used length(str)==0 was able to say the record is having no values ...

may I ask you a favor to explain it in detail elaboration on above scecnarios, so that many others can get benefited and clearly knows how our tool works and expects the data to be like while performing above validations ...(something like a thumb rule for validations).


 

There should be clear indications on when to use what 

Raghuram_Puram
Contributor III
Contributor III

Sudhee_Maximus
Creator
Creator
Author

Thanks that helped !

Sudhee_Maximus
Creator
Creator
Author

Hi Nikhilthampi,

 

I have similar issue while using for date column (but even after using relational.ISNULL / .equals(null)/ Length  I am having null pointer exceptions )
*********************************************Coded as below *******  
(row2.P_SPECL_BEG_DT1.equals(null) || row2.P_SPECL_END_DT1.equals(null)) ||  --------- > checking fro null column 
(StringHandling.LEN(row2.P_SPECL_BEG_DT1.toString())==0 || StringHandling.LEN(row2.P_SPECL_END_DT1.toString())==0 ) ---> Checking if it is not null but o chars
? null :
!(TalendDate.isDate(row2.P_SPECL_BEG_DT1.toString(),"MM-dd-yyyy") && TalendDate.isDate(row2.P_SPECL_END_DT1.toString(),"MM-dd-yyyy"))? null :  --->checking if it is not desired date 
TalendDate.diffDate(row2.P_SPECL_END_DT1,row2.P_SPECL_BEG_DT1) < 0 ? " Error SPECL_BEG_DT1 > SPECL_END_DT1,"
:null

 

 

 

**************************** Please let me know why even after handling nulls I am having Null pointer exception ***********  did I  miss anything here ...

 

please correct my basic if I am missing any here

 

attaching sample date values  for reference .... in which highlighted are null values coming and a 3 char word is another col in b/w which is not considered .

 

 


Capture.JPG
Anonymous
Not applicable

@SudheeReddy 

 

Lets not dilute the original content by adding a different query to this post. Could you please create a new post with the details along with sample input records and expected output (do not ad them as images as we may not be able to copy them for testing)? 

 

Please also add the screen shot of your current job so that we will get what you are doing in your job.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

Sudhee_Maximus
Creator
Creator
Author

@nthampi 
yes I felt same and raised in separate discussion.

Initially I felt it is around same Null pointer but on different context so raised in same ...

but thanks for your reply and help nikhil ....

aaronrums
Contributor II
Contributor II

For anyone who stumbles on this later, using .equals() also helped me. I was at first using "==" to compare two strings that I KNEW were equal to eachother. Turns out that .equals checks the values, and "==" checks if both objects correspond to the same location in memory.