tExtractJSONFields and Int data type

Four Stars

tExtractJSONFields and Int data type

I am using tExtractJSONFields and chose to do a built in schema.  For one of my output columns I chose int for the data type.  My data appears to be bypassed when this value is greater than 7000516717.  I have other rows with values like 7000563800 that are being bypassed.  Is there a value limit here that I'm unaware of? 

Nine Stars

Re: tExtractJSONFields and Int data type

By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -2^31 and a maximum value of 2^31-1. So the highest number you could have is 2147483647.

 

Clearly 7000516717 or 7000563800 would not hold. Try changing to long - which has a minimum value of -2^63 and a maximum value of 2^63-1

 

Link - https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Six Stars

Re: tExtractJSONFields and Int data type

That's because 7000516717 is bigger than the largest value that will fit into a Java int (2147483647). Use a long.

 

Java represents integers in signed 2's complement format. An integer is 32 bits wide. This means the smallest value it can store is -2^31 and that the largest is 2^31 -1. We lose one place on the positive side because we need to be able to represent zero. It would take 33 bits to store 7000516717. You can figure this out quickly by using a log base 2 calculator like this one: https://www.miniwebtool.com/log-base-2-calculator/