<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37120#M26265</link>
    <description>&lt;P&gt;I am attempting to apply Mosaic's `grid_pointascellid` method on a spark dataframe with `lat`, `lon` columns.&lt;/P&gt;&lt;P&gt;```&lt;BR /&gt;import pyspark.sql.functions as F&lt;/P&gt;&lt;P&gt;# Create a Spark DataFrame with a lat and lon column&lt;BR /&gt;df = spark.createDataFrame([&lt;BR /&gt;("point1", 10.0, 20.0),&lt;BR /&gt;("point2", 30.0, 40.0),&lt;BR /&gt;("point3", 50.0, 60.0),&lt;BR /&gt;], ["name", "lat", "lon"])&lt;/P&gt;&lt;P&gt;# Print the results of the DataFrame&lt;BR /&gt;df.show()&lt;/P&gt;&lt;P&gt;df1 = df.withColumn("id", grid_pointascellid(st_point(df["lon"], df["lat"]), lit(7)))&lt;BR /&gt;df1.show()&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;The schema of the dataframe is:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;|-- name: string (nullable = true)&lt;BR /&gt;|-- lat: decimal(9,6) (nullable = true)&lt;BR /&gt;|-- lng: decimal(9,6) (nullable = true)&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;Exception:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 251.0 failed 4 times, most recent failure: Lost task 0.3 in stage 251.0 (TID 15016) (10.138.221.80 executor 50): java.lang.ClassCastException: org.apache.spark.sql.types.Decimal cannot be cast to java.lang.Double&lt;/P&gt;&lt;P&gt;&lt;A href="https://databrickslabs.github.io/mosaic/api/spatial-indexing.html?highlight=grid_boundary#grid-pointascellid" target="_blank" rel="noopener"&gt;https://databrickslabs.github.io/mosaic/api/spatial-indexing.html?highlight=grid_boundary#grid-pointascellid&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jul 2023 21:41:25 GMT</pubDate>
    <dc:creator>kll</dc:creator>
    <dc:date>2023-07-06T21:41:25Z</dc:date>
    <item>
      <title>SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid</title>
      <link>https://community.databricks.com/t5/data-engineering/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37120#M26265</link>
      <description>&lt;P&gt;I am attempting to apply Mosaic's `grid_pointascellid` method on a spark dataframe with `lat`, `lon` columns.&lt;/P&gt;&lt;P&gt;```&lt;BR /&gt;import pyspark.sql.functions as F&lt;/P&gt;&lt;P&gt;# Create a Spark DataFrame with a lat and lon column&lt;BR /&gt;df = spark.createDataFrame([&lt;BR /&gt;("point1", 10.0, 20.0),&lt;BR /&gt;("point2", 30.0, 40.0),&lt;BR /&gt;("point3", 50.0, 60.0),&lt;BR /&gt;], ["name", "lat", "lon"])&lt;/P&gt;&lt;P&gt;# Print the results of the DataFrame&lt;BR /&gt;df.show()&lt;/P&gt;&lt;P&gt;df1 = df.withColumn("id", grid_pointascellid(st_point(df["lon"], df["lat"]), lit(7)))&lt;BR /&gt;df1.show()&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;The schema of the dataframe is:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;|-- name: string (nullable = true)&lt;BR /&gt;|-- lat: decimal(9,6) (nullable = true)&lt;BR /&gt;|-- lng: decimal(9,6) (nullable = true)&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;Exception:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 251.0 failed 4 times, most recent failure: Lost task 0.3 in stage 251.0 (TID 15016) (10.138.221.80 executor 50): java.lang.ClassCastException: org.apache.spark.sql.types.Decimal cannot be cast to java.lang.Double&lt;/P&gt;&lt;P&gt;&lt;A href="https://databrickslabs.github.io/mosaic/api/spatial-indexing.html?highlight=grid_boundary#grid-pointascellid" target="_blank" rel="noopener"&gt;https://databrickslabs.github.io/mosaic/api/spatial-indexing.html?highlight=grid_boundary#grid-pointascellid&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 21:41:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37120#M26265</guid>
      <dc:creator>kll</dc:creator>
      <dc:date>2023-07-06T21:41:25Z</dc:date>
    </item>
  </channel>
</rss>

