cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

shan_chandra
Databricks Employee
Databricks Employee

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
Databricks Employee
Databricks Employee

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
Databricks Employee
Databricks Employee

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);

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group