cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.ArithmeticException: Casting XXXXXXXXXXX to int causes overflow

shan_chandra
Honored Contributor III
Honored Contributor III

My job started failing with the below error when inserting rows into a delta table. 

ailing with the below error when inserting rows (timestamp) to a delta table, it was working well before.

java.lang.ArithmeticException: Casting XXXXXXXXXXX to int causes overflow

1 ACCEPTED SOLUTION

Accepted Solutions

shan_chandra
Honored Contributor III
Honored Contributor III

This is because the Integer type represents 4-byte signed integer numbers. The range of numbers is from -2147483648 to 2147483647.

Kindly use double as the data type to insert the "2147483648" value in the delta table.

In the below example, The second insert will fail when we insert it into the table because it is exceeding the maximum allowed range for int data type. However as a double data type. The value would be successfully inserted because double represents 8-byte signed integer numbers.

Eg. CREATE TABLE test (c1 int, c2 double);

INSERT INTO test VALUES (2147483647, 2147483647);

INSERT INTO test VALUES (100574987462592, 100574987462592);

INSERT INTO test VALUES (NULL, 100574987462592);

View solution in original post

1 REPLY 1

shan_chandra
Honored Contributor III
Honored Contributor III

This is because the Integer type represents 4-byte signed integer numbers. The range of numbers is from -2147483648 to 2147483647.

Kindly use double as the data type to insert the "2147483648" value in the delta table.

In the below example, The second insert will fail when we insert it into the table because it is exceeding the maximum allowed range for int data type. However as a double data type. The value would be successfully inserted because double represents 8-byte signed integer numbers.

Eg. CREATE TABLE test (c1 int, c2 double);

INSERT INTO test VALUES (2147483647, 2147483647);

INSERT INTO test VALUES (100574987462592, 100574987462592);

INSERT INTO test VALUES (NULL, 100574987462592);

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.