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:ย 

Databricks Data Type Conversion error

Vibhor
Contributor

In databricks while writing data to curated layer, see error - Failed to execute user defined function (Double => decimal(38,18)). Does anyone know if faced such issue and how to resolve it.

1 ACCEPTED SOLUTION

Accepted Solutions

-werners-
Esteemed Contributor III

What happens if you explicitly cast it?

I remember having such issues with implicit casting when goin from spark 2.x to 3.x, but these were solved by using explicit casting (not round()).

View solution in original post

5 REPLIES 5

Anonymous
Not applicable

Hi Vibhor,

Thanks for your question. Let's give it a while to see what the community comes up with. We'll circle back if we need to.

-werners-
Esteemed Contributor III

What happens if you explicitly cast it?

I remember having such issues with implicit casting when goin from spark 2.x to 3.x, but these were solved by using explicit casting (not round()).

When we multiply 2 numbers; the result size could go to the tune of 2x (num1 size + num2 size). Before we are explicitly casting multiplication of these 2, the result is bigger than to be casted data type. Its something like (double (x,y) can't be converted to decimal (x,y-1)). If we decrease the data type size of the values to me multiplied before multiplication we are getting incorrect value due to precision loss.

Scala 2.11 spark 2.4.5

jose_gonzalez
Databricks Employee
Databricks Employee

Hi @Vibhor Sethiโ€‹ ,

Could you please share more details on this issue? whats the error stack trace? could you share your code? are you writing to Delta or Parquet or which format?

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