Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
android1686764069
Contributor
Contributor

How can I test if a value of INT-type (Not INTEGER TYPE, I'm talking about INT type) is null?

hello

I have a simple tmap

As an input I have csv file with 4 columns:

The last 2 colums are INT and INTEGER.

I'm not sure of the difference; anyway here, INT can not be null as you can see below (nullable box is no checked)

As an output, these last 2 colmuns are a string-type.

for the colmun which is an INTEGER, in the tmap I hve this

row3.code2==null?null: row3.code2.toString()

it's OK

 

But for the column which is an INT (non nullable), still want to make sure that if is null; then i have a null value so I alos do this:

row3.code1==null?null: row3.code1.toString()

but in this case I have 2 errors because talend told me i can't use toString() with int and I can't use "==" with int.

So I tried row3.code2==null?null: String.valueOf(row3.code2)

Now I have one error because talend told me i can't use "==" with int.

what can i do if I I still want to test whetehr code 1 is null or not.

0695b00000nQUw3AAG.png

Labels (3)
1 Solution

Accepted Solutions
anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @android devops​ 

 

The int data type is a primitive data type that is not instantiated from a Java class, unlike Integer. Therefore, it cannot hold a null value.

 

If we are discussing a tMap lookup table using a left join, by default, any int column from this table that does not match with the main row will become 0. However, since you are attempting to validate an int column from the main row, the situation is not as straightforward.

 

So, when you are dealing with the int data type and need to implement this type of validation, I suggest considering the following:

 

  1. Does this column really need to be of type int? If it comes from a file, for instance, you could safely enable the Nullable option on the schema, and empty values would become null. If it comes from a database table where the source column is not nullable, the validation might not be necessary.
  2. If it truly needs to be of the int data type, is there a value that could be considered equivalent to null, such as 0 (zero)? If so, you could use something like this: row3.code2 == 0 ? null : row3.code2.toString()

 

View solution in original post

2 Replies
anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @android devops​ 

 

The int data type is a primitive data type that is not instantiated from a Java class, unlike Integer. Therefore, it cannot hold a null value.

 

If we are discussing a tMap lookup table using a left join, by default, any int column from this table that does not match with the main row will become 0. However, since you are attempting to validate an int column from the main row, the situation is not as straightforward.

 

So, when you are dealing with the int data type and need to implement this type of validation, I suggest considering the following:

 

  1. Does this column really need to be of type int? If it comes from a file, for instance, you could safely enable the Nullable option on the schema, and empty values would become null. If it comes from a database table where the source column is not nullable, the validation might not be necessary.
  2. If it truly needs to be of the int data type, is there a value that could be considered equivalent to null, such as 0 (zero)? If so, you could use something like this: row3.code2 == 0 ? null : row3.code2.toString()

 

android1686764069
Contributor
Contributor
Author

thanks a lot