<?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: Spark Structured Streaming foreachBatch with databricks-connect in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97049#M39405</link>
    <description>&lt;P&gt;Is this by any chance submitted to an UC enabled assigned cluster?&lt;/P&gt;</description>
    <pubDate>Thu, 31 Oct 2024 17:10:07 GMT</pubDate>
    <dc:creator>VZLA</dc:creator>
    <dc:date>2024-10-31T17:10:07Z</dc:date>
    <item>
      <title>Spark Structured Streaming foreachBatch with databricks-connect</title>
      <link>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/95549#M39121</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I'm trying to use the foreachBatch method of a Spark Streaming DataFrame with databricks-connect. Given that spark connect supported was added to &amp;nbsp;`foreachBatch` in 3.5.0, I was expecting this to work.&lt;/P&gt;&lt;P&gt;Configuration:&lt;BR /&gt;- DBR 15.4 (Spark 3.5.0)&lt;BR /&gt;- databricks-connect 15.4.2&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
from databricks.connect import DatabricksSession

# Setup
spark = DatabricksSession.builder.clusterId("0501-011833-vcux5w7j").getOrCreate()

# Execute
df = spark.readStream.table("brz_stock_prices_job")

def update_metrics(batch_df, batch_id):
    size = batch_df.count()
    print(f"Batch size: {size}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  File "/Users/osoucy/miniconda3/envs/lac/lib/python3.10/site-packages/pyspark/sql/connect/client/core.py", line 2149, in _handle_rpc_error
    raise convert_exception(
pyspark.errors.exceptions.connect.SparkConnectGrpcException: (java.io.IOException) 

Connection reset by peer
JVM stacktrace:
java.io.IOException
	at sun.nio.ch.FileDispatcherImpl.read0(FileDispatcherImpl.java:-2)
	at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
	at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
	at sun.nio.ch.IOUtil.read(IOUtil.java:197)
	at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
	at sun.nio.ch.SocketAdaptor$SocketInputStream.read(SocketAdaptor.java:208)
	at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
	at java.io.DataInputStream.readInt(DataInputStream.java:387)
	at org.apache.spark.api.python.StreamingPythonRunner.init(StreamingPythonRunner.scala:206)
	at org.apache.spark.sql.connect.planner.StreamingForeachBatchHelper$.$anonfun$pythonForeachBatchWrapper$3(StreamingForeachBatchHelper.scala:146)
        [...]
	at org.apache.spark.sql.connect.execution.ExecuteThreadRunner$ExecutionThread.run(ExecuteThreadRunner.scala:561)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 16:39:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/95549#M39121</guid>
      <dc:creator>olivier-soucy</dc:creator>
      <dc:date>2024-10-22T16:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Spark Structured Streaming foreachBatch with databricks-connect</title>
      <link>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97049#M39405</link>
      <description>&lt;P&gt;Is this by any chance submitted to an UC enabled assigned cluster?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 17:10:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97049#M39405</guid>
      <dc:creator>VZLA</dc:creator>
      <dc:date>2024-10-31T17:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Spark Structured Streaming foreachBatch with databricks-connect</title>
      <link>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97144#M39434</link>
      <description>&lt;P&gt;It's a single user UC enabled cluster.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 02:52:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97144#M39434</guid>
      <dc:creator>olivier-soucy</dc:creator>
      <dc:date>2024-11-01T02:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Spark Structured Streaming foreachBatch with databricks-connect</title>
      <link>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97145#M39435</link>
      <description>&lt;P&gt;It turned out that my local machine had a different python version when compared to the workers. Updating python solved this issue. I simply had to look into the driver log, the error message was very obvious:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;pyspark.errors.exceptions.base.PySparkRuntimeError: [PYTHON_VERSION_MISMATCH] Python in worker has different version: 3.11 than that in driver: 3.10, PySpark cannot run with different minor versions.
Please check environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON are correctly set.&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 01 Nov 2024 02:53:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97145#M39435</guid>
      <dc:creator>olivier-soucy</dc:creator>
      <dc:date>2024-11-01T02:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Spark Structured Streaming foreachBatch with databricks-connect</title>
      <link>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97173#M39450</link>
      <description>&lt;P&gt;Thanks for sharing the solution! Just curious, was the original error message reported in this post in the Driver log as well?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 08:18:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97173#M39450</guid>
      <dc:creator>VZLA</dc:creator>
      <dc:date>2024-11-01T08:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Spark Structured Streaming foreachBatch with databricks-connect</title>
      <link>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97312#M39473</link>
      <description>&lt;P&gt;From I can remember, I think it was!&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2024 06:00:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/spark-structured-streaming-foreachbatch-with-databricks-connect/m-p/97312#M39473</guid>
      <dc:creator>olivier-soucy</dc:creator>
      <dc:date>2024-11-02T06:00:18Z</dc:date>
    </item>
  </channel>
</rss>

