https://delta.io logo
#random
Title
d

Divyansh Jain

08/20/2023, 7:18 AM
Hi All, Can anyone help me resolve the below issue: I have a scenario where I'm converting dataframe to dictionary and iterating over every value to get the absolute value. But getting error. Refer SS-1 & SS-2. However, when I'm running the same code directly on hard coded dictionary same code is working fine. Refer SS-3 & SS-4. Please help. Thanks!
y

Yousry Mohamed

08/20/2023, 7:59 AM
Print both dictionaries and see what they contain first before executing further logic. It is a bit weird the stack trace in SS2 seems like coming from Spark due to using wrong column name in a dataframe or something while you are using collect and if something fails it should not fail on such line. The exception shown usually means a UDF is called or a DataFrame expression is missing something like wrapping a constant with
lit
function.
d

Divyansh Jain

08/20/2023, 10:00 AM
@Yousry Mohamed I tried to print both the dictionaries i.e. Dict from Screenshot SS1 and even SS2. Both are same. Still facing same issues.
y

Yousry Mohamed

08/20/2023, 10:01 AM
Try to print both dictionaries after line 3 in SS2
d

Divyansh Jain

08/20/2023, 10:02 AM
Did that too..
No issues in Dictionary
y

Yousry Mohamed

08/20/2023, 10:03 AM
Can you share the code for the failing cell along with the full stacktrace
d

Divyansh Jain

08/20/2023, 11:54 AM
SS2 is the code which is failing
y

Yousry Mohamed

08/20/2023, 11:55 AM
Please share the most recent stack trace
d

Divyansh Jain

08/20/2023, 11:58 AM
Hope this helps
y

Yousry Mohamed

08/20/2023, 11:59 AM
phew, that's a know issue
it is the import of spark functions
try to import spark functions as F
import pyspark.sql.functions as F
your
abs
is referring the the abs function in Spark not the Python one
d

Divyansh Jain

08/20/2023, 12:01 PM
Oh okay gotcha
Let me try and will update you. Thanks a ton🙂
Yes, it worked. Thanks much!
y

Yousry Mohamed

08/20/2023, 12:14 PM
you are welcome