<?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 Re: SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37169#M5455</link>
    <description>&lt;P&gt;At which step are you getting the error? Also, can you share the code for "&lt;SPAN&gt;grid_pointascellid" function to understand what it is doing?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2023 14:16:00 GMT</pubDate>
    <dc:creator>Lakshay</dc:creator>
    <dc:date>2023-07-07T14:16:00Z</dc:date>
    <item>
      <title>SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid</title>
      <link>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37097#M5454</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>Fri, 07 Jul 2023 14:23:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37097#M5454</guid>
      <dc:creator>kll</dc:creator>
      <dc:date>2023-07-07T14:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid</title>
      <link>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37169#M5455</link>
      <description>&lt;P&gt;At which step are you getting the error? Also, can you share the code for "&lt;SPAN&gt;grid_pointascellid" function to understand what it is doing?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 14:16:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37169#M5455</guid>
      <dc:creator>Lakshay</dc:creator>
      <dc:date>2023-07-07T14:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid</title>
      <link>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37170#M5456</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/75976"&gt;@Lakshay&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On this step, when I attempt to apply the method:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;```&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;df1 = df.withColumn("id", grid_pointascellid(st_point(df["lon"], df["lat"]), lit(7)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df1.show()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;```&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 14:27:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37170#M5456</guid>
      <dc:creator>kll</dc:creator>
      <dc:date>2023-07-07T14:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid</title>
      <link>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37470#M5457</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/58899"&gt;@kll&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope you are well. Just wanted to see if you were able to find an answer to your question and would you like to mark an answer as best? It would be really helpful for the other members too.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 09:42:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37470#M5457</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-07-12T09:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: SparkException: Job aborted due to stage failure when attempting to run grid_pointascellid</title>
      <link>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37606#M5458</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/58899"&gt;@kll&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This error appears because the function&amp;nbsp;&lt;SPAN&gt;grid_pointascellid expects a Double type column and a Decimal column type was provided as input.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To overcome this, before you apply the grid_pointascellid, I would recommend casting the columns lat and lon.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;df1 = df.withColumn("lat", df["lat"].cast("double")).withColumn("lon", df["lon"].cast("double"))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;df2 = df1.withColumn("id", grid_pointascellid(st_point(df1["lon"], df1["lat"]), lit(7)))&lt;BR /&gt;df2.show()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;By performing this explicit cast before calling the mosaic functions, i was able to get the output below.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;| name.&amp;nbsp; &amp;nbsp;| lat.&amp;nbsp; &amp;nbsp;| lon.&amp;nbsp; &amp;nbsp;| id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp;&lt;BR /&gt;|point1.&amp;nbsp; &amp;nbsp;|10.0. |20.0.&amp;nbsp; |609880166050562047|&lt;BR /&gt;|point2.&amp;nbsp; &amp;nbsp;|30.0&amp;nbsp; |40.0.&amp;nbsp; |609448747927076863|&lt;BR /&gt;|point3.&amp;nbsp; &amp;nbsp;|50.0&amp;nbsp; |60.0.&amp;nbsp; |608566547836829695|&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 19:02:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/sparkexception-job-aborted-due-to-stage-failure-when-attempting/m-p/37606#M5458</guid>
      <dc:creator>Tharun-Kumar</dc:creator>
      <dc:date>2023-07-14T19:02:40Z</dc:date>
    </item>
  </channel>
</rss>

