<?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 spark context in databricks in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/spark-context-in-databricks/m-p/58689#M2365</link>
    <description>&lt;P&gt;Hi&amp;nbsp;@all,&lt;/P&gt;&lt;P&gt;In Azure Databricks,&lt;BR /&gt;I am using structured streaming for each batch functionality, in one of the functions I am creating tempview with pyspark dataframe (*Not GlobalTempView) and trying to access the same temp view by using spark.sql functionality.&lt;/P&gt;&lt;P&gt;But I am getting the error temp view not found, seems like the temp view is not created in the same spark context.&lt;BR /&gt;&lt;BR /&gt;I want to create the temp view by using pyspark dataframe and access the tempview using spark sql function in structuring streaming. Could you please share the steps to create tempview and access within same databricks notebook.&lt;/P&gt;&lt;P&gt;is spark keyword and spark.sql will have different spark context within same databricks notebook? or both will have same context.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#databricks #pyspark #sparksql&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 11:41:03 GMT</pubDate>
    <dc:creator>Data_Engineer3</dc:creator>
    <dc:date>2024-01-30T11:41:03Z</dc:date>
    <item>
      <title>spark context in databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/spark-context-in-databricks/m-p/58689#M2365</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@all,&lt;/P&gt;&lt;P&gt;In Azure Databricks,&lt;BR /&gt;I am using structured streaming for each batch functionality, in one of the functions I am creating tempview with pyspark dataframe (*Not GlobalTempView) and trying to access the same temp view by using spark.sql functionality.&lt;/P&gt;&lt;P&gt;But I am getting the error temp view not found, seems like the temp view is not created in the same spark context.&lt;BR /&gt;&lt;BR /&gt;I want to create the temp view by using pyspark dataframe and access the tempview using spark sql function in structuring streaming. Could you please share the steps to create tempview and access within same databricks notebook.&lt;/P&gt;&lt;P&gt;is spark keyword and spark.sql will have different spark context within same databricks notebook? or both will have same context.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#databricks #pyspark #sparksql&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 11:41:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/spark-context-in-databricks/m-p/58689#M2365</guid>
      <dc:creator>Data_Engineer3</dc:creator>
      <dc:date>2024-01-30T11:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: spark context in databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/spark-context-in-databricks/m-p/58695#M2366</link>
      <description>&lt;P&gt;Do you face this issue without spark streaming as well? Also, could you share a minimal repo code preferably without streaming?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 13:11:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/spark-context-in-databricks/m-p/58695#M2366</guid>
      <dc:creator>Lakshay</dc:creator>
      <dc:date>2024-01-30T13:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: spark context in databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/spark-context-in-databricks/m-p/58780#M2372</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&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;Without structured streaming, I can able to create the tempview and make use of it in the same notebook.&lt;BR /&gt;But for the same, when I try to use in structured streaming, it is throwing the error message that view not found.&lt;/P&gt;&lt;P&gt;please refer the below sample code snippet for reference,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;write_to_final_table&lt;/SPAN&gt;&lt;SPAN&gt; = &amp;nbsp;(spark.readStream.format(&lt;/SPAN&gt;&lt;SPAN&gt;'delta'&lt;/SPAN&gt;&lt;SPAN&gt;).option(&lt;/SPAN&gt;&lt;SPAN&gt;'ignoreChanges'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;True&lt;/SPAN&gt;&lt;SPAN&gt;).table(&lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;delta_table_name&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;)).writeStream.queryName(&lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;query_name&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;).format(&lt;/SPAN&gt;&lt;SPAN&gt;"org.elasticsearch.spark.sql"&lt;/SPAN&gt;&lt;SPAN&gt;).trigger(&lt;/SPAN&gt;&lt;SPAN&gt;processingTime&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;'1 minutes'&lt;/SPAN&gt;&lt;SPAN&gt;).outputMode(&lt;/SPAN&gt;&lt;SPAN&gt;"append"&lt;/SPAN&gt;&lt;SPAN&gt;).foreachBatch(process_micro_batch).option(&lt;/SPAN&gt;&lt;SPAN&gt;"checkpointLocation"&lt;/SPAN&gt;&lt;SPAN&gt;,checkpointdirectory_path).option(&lt;/SPAN&gt;&lt;SPAN&gt;"mergeSchema"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"true"&lt;/SPAN&gt;&lt;SPAN&gt;).option(&lt;/SPAN&gt;&lt;SPAN&gt;"failOnDataLoss"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"false"&lt;/SPAN&gt;&lt;SPAN&gt;).start()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;def&lt;/SPAN&gt; &lt;SPAN&gt;process_micro_batch&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;micro_batch_df&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;batchId) :&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;micro_batch_df&lt;/SPAN&gt;&lt;SPAN&gt;.createOrReplaceTempView(&lt;/SPAN&gt;&lt;SPAN&gt;"temp_view"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;df&lt;/SPAN&gt;&lt;SPAN&gt; = spark.sql(&lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"select * from temp_view"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;df&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Here, I am getting error, while reading data from temp_view that temp_view not found error.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 31 Jan 2024 04:50:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/spark-context-in-databricks/m-p/58780#M2372</guid>
      <dc:creator>Data_Engineer3</dc:creator>
      <dc:date>2024-01-31T04:50:37Z</dc:date>
    </item>
  </channel>
</rss>

