Tmap expression always false

Five Stars

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?
Moderator

Re: Tmap expression always false

Hello,

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

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Thirteen Stars

Re: Tmap expression always false

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

 

Please check.

Manohar B
Thirteen Stars

Re: Tmap expression always false

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

 

Please check.

Manohar B
Tags (1)
Ten Stars

Re: Tmap expression always false

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
Five Stars

Re: Tmap expression always false

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. 

Ten Stars

Re: Tmap expression always false

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!!! Smiley Happy)
Seventeen Stars

Re: Tmap expression always false

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!

Ten Stars

Re: Tmap expression always false

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