Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
pnair123
Contributor II

Tmap expression always false

Hi there,
I an joining a tfileinput and a table in tamp and comparing two integer fields. My condition looks like this

row1.rec_count==row2.lz_count?0:1
However, the condition is always failing even though the counts match (I checked the output with a tlogrow) and both rec_count and lz_count are defined as integer. Do you have any idea why?
Labels (2)
8 Replies
Anonymous
Not applicable

Hello,

Could you please post your tMap editor screenshot on forum? Did you put your condition in tMap expression field?

Best regards

Sabrina

manodwhb
Champion II

@pnair123,condition is right one,if you have configured your tMap correctly then the problem with data.

 

Please check.

manodwhb
Champion II

@pnair123,condition is right one,if you have configured your tMap correctly then the problem with data.

 

Please check.

Jesperrekuh
Specialist

Alternative: Join also on the the count fields in addition to the filenames in the tMap component then row2.lz_count == null ? 0 : 1

Do you use the 0 or 1 as a bit/boolean?
Change it's value in true or false and type boolean
pnair123
Contributor II
Author

Thanks for your suggestion. I figured out the issue. One field was defined as integer and other was defined as integer(11). When I changed both to integer(11), it worked. 

Jesperrekuh
Specialist

WOW. really... hummm it made (re)think again on what happens on a low level and recently I read something about hash comparison (stored in bytes) vs string comparison vs integer comparison... the only thing I can come up with is... it compares the whole block of bytes. a block size of 4 vs 8 even if they both store the same value 1 ... their byte representation still differs... If somebody has a better explanation love to read it!

Thank you for your post and solving the issue!!! 0683p000009MACn.png)
Anonymous
Not applicable

NO this is not the actually reason. The length of a data type will never be used within the job! Such settings only are used when the job has to create the table for itself.

The reason why your expression is not working is because you have to think about what == actually means in Java!

It means the SAME content of the variable! If you have both values as none nullable integer, then both variables have the same content.

If you have nullable Integer the variables actually contains the addresses of the Integer objects and in most cases both Integer objects are using different addresses within the RAM. The only Java like language dealing with it in a human way is Groovy.

if you compare a nullable Integer with a not nullable int value the Integer value will be converted implicit into the primitive value and now the == works well. If you have both values a not nullable you have to check both for being not null and than use the equals method!

Example:

 (i1 != null && i1.equals(i2))

  this is save and will always work!

Jesperrekuh
Specialist

Thanks!
Started reading a little bit to fully understand what you are saying. So in addition to what you where saying with examples:
https://stackoverflow.com/questions/1514910/how-to-properly-compare-two-integers-in-java