Tharun-Kumar
Databricks Employee
Databricks Employee

@kll 

This error appears because the function grid_pointascellid expects a Double type column and a Decimal column type was provided as input.

To overcome this, before you apply the grid_pointascellid, I would recommend casting the columns lat and lon.

df1 = df.withColumn("lat", df["lat"].cast("double")).withColumn("lon", df["lon"].cast("double"))

df2 = df1.withColumn("id", grid_pointascellid(st_point(df1["lon"], df1["lat"]), lit(7)))
df2.show()

By performing this explicit cast before calling the mosaic functions, i was able to get the output below.

| name.   | lat.   | lon.   | id                                | 
|point1.   |10.0. |20.0.  |609880166050562047|
|point2.   |30.0  |40.0.  |609448747927076863|
|point3.   |50.0  |60.0.  |608566547836829695|