<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Simonmasquelier on Medium]]></title>
        <description><![CDATA[Stories by Simonmasquelier on Medium]]></description>
        <link>https://medium.com/@simonmasquelier_66114?source=rss-edb4ee6b97de------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TbB-uqMmo_xEOn_nHIx2gA.jpeg</url>
            <title>Stories by Simonmasquelier on Medium</title>
            <link>https://medium.com/@simonmasquelier_66114?source=rss-edb4ee6b97de------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:36:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@simonmasquelier_66114/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Apache Spark 4.0: What’s new and where it’s going]]></title>
            <link>https://medium.com/orange-business/apache-spark-4-0-whats-new-and-where-it-s-going-2488024f7d36?source=rss-edb4ee6b97de------2</link>
            <guid isPermaLink="false">https://medium.com/p/2488024f7d36</guid>
            <category><![CDATA[apache-spark]]></category>
            <dc:creator><![CDATA[Simonmasquelier]]></dc:creator>
            <pubDate>Tue, 15 Jul 2025 07:01:25 GMT</pubDate>
            <atom:updated>2025-07-15T07:01:25.794Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve worked with Spark since the 2.x days, and it’s been exciting to see it evolve into a core piece of many modern data stack. With Spark 4.0, the project reaches a major milestone with some clear directions : elevating SQL, embracing modularity and multi-language support, and closing the gap with industry standards. Rather than covering every changelog item, in this article, I’ll focus on the features supporting these 3 directions as well as few other highlights worth noting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rtrx_jkMSW16Ot-G5xrHQ.png" /><figcaption>Image from Apache Software Foundation</figcaption></figure><h3>1. A More Intuitive Way to Write SQL? Introducing the PIPE Syntax</h3><p>One of the most novel additions in Spark 4.0 is the new |&gt; PIPE syntax — arguably the biggest SQL update Spark has made in years. Inspired by functional programming and Unix pipelines, it allows SQL transformations to be chained in the same logical order we typically think about them.</p><p>Let’s take as an example this query with traditional syntax.</p><pre>select <br>    case when (unix_timestamp(tpep_dropoff_datetime) - unix_timestamp(tpep_pickup_datetime)) / 60 &gt; 30 then &#39;Yes&#39; else &#39;No&#39; end as ge_30_min_trip,<br>    max(trip_distance) as max_trip_distance,<br>    max(fare_amount) as max_fare<br>from common.nyctaxi.trips<br>where fare_amount &gt; 50<br>group by case when (unix_timestamp(tpep_dropoff_datetime) - unix_timestamp(tpep_pickup_datetime)) / 60 &gt; 30 then &#39;Yes&#39; else &#39;No&#39; end<br>order by max_fare desc</pre><p>Pipe syntax lets you construct the exact same query like this:</p><pre>from common.nyctaxi.trips<br>|&gt; where fare_amount &gt; 50<br>|&gt; aggregate max(trip_distance) as max_distance,<br>   max(fare_amount) as max_fare <br>   group by case when (unix_timestamp(tpep_dropoff_datetime) - unix_timestamp(tpep_pickup_datetime)) / 60 &gt; 30 then &#39;Yes&#39; else &#39;No&#39; end as ge_30_min_trip<br>|&gt; order by max_fare desc</pre><p>The PIPE operator’s goal is to make SQL feel more ergonomic and more like a data pipeline again for multi-step transformations: each transformation stands alone, is easier to reason about, and reads top-to-bottom.</p><p>The main benefits of this approach as per me are :</p><ul><li><strong>No Lateral Column reference</strong>: You can compute new columns incrementally — and use them immediately in the next step — without needing lateral column references or repeating logic.</li><li><strong>Aggregation Clarity</strong>: Unlike traditional SQL where aggregates live in the SELECT clause and are controlled by a GROUP BY far below, the PIPE syntax treats aggregation as an explicit, standalone step.</li><li><strong>Cleaner Filtering Logic</strong>: With PIPE, you don’t have to worry about the exact ordering of WHERE and GROUP BY. Each filtering or aggregation operation becomes its own distinct, logical step and your query stays DRY.</li><li><strong>Backward compatibility</strong>: You can mix and match PIPE-based SQL with regular SQL, apply it only to subqueries, or adopt it gradually, applying it to just a subquery or a specific part of a larger SQL statement, which makes experimenting with it low-risk and highly approachable.</li></ul><p>Interestingly, this syntax has garnered broader attention (and controverses). A recent <a href="https://research.google/pubs/sql-has-problems-we-can-fix-them-pipe-syntax-in-sql/">paper</a> from Google in 2024 proposed PIPE syntax as a potential SQL standard and some databases have implemented it (like DuckDB and BigQuery with GoogleSQL). It’s still early, but I am curious whether this pattern will get adopted more widely — particularly for tools aiming to make SQL friendlier for data analysts and developers.</p><h4>Other SQL Engine features worth noticing:</h4><ul><li><strong>SQL-defined UDFs and UDTFs</strong>: Spark 4.0 allows defining reusable logic directly in SQL more maintainable queries integrated with Spark’s query optimizer for enhanced performance.</li><li><strong>Parameterized Queries</strong> : Spark 4.0 supports named (:var) and unnamed (?) parameter markers in SQL queries, allowing safe value substitution through the spark.sql() API, reducing the risk of SQL injection.</li><li><strong>SQL Scripting &amp; Control Flow</strong>: Spark 4.0 introduces multi-statement SQL scripting with support for variables, control flow (with various ways to loop, control flows and exception handling) — enabling complex workflows entirely in SQL making it more convenient to move parts of ETL logic into pure SQL.</li></ul><h3>2. Spark Connect Grows Up</h3><p>If you haven’t paid much attention to Spark Connect yet, now’s the time.</p><p>Originally introduced in Spark 3.4, Spark Connect is a client-server architecture that decouples Spark’s driver from the user application. Instead of running a full Spark session locally, your code can now talk to a remote Spark cluster via a lightweight client — kind of like a modern API layer for Spark. And in Spark 4.0, Spark Connect gets a serious upgrade.</p><p>One of the biggest wins in Spark 4.0 is high feature parity between Spark Connect and the traditional “Spark Classic” mode. That means most of the logic you’d typically write using the classic driver mode can now run unchanged through Spark Connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4jU0YBhwstbytuxP4yC6sw.png" /><figcaption>Spark Connect Architecture Graph from Apache Software Foundation</figcaption></figure><p>Spark has traditionally been JVM-first — Scala, Java, Python (via Py4J). But with Spark Connect, that’s starting to change: Spark Connect supports not just Python and Scala (lightweight) clients out of the box, but also community-backed clients for Go and Rust. With Spark 4.0 it also now supports Swift as well. This gives us the opportunity to highlight something perhaps yet unfamiliar to many Spark users which is that Spark Connect developers outside the JVM world can build Spark-powered applications in the language they’re most comfortable with. Want to run DataFrame queries in a Rust data engineering tool? Or trigger Spark jobs from a Go microservice? You know now that you can — no JVM, no heavyweight setup, just a clean client-server API.</p><h3>3. Variant Data Type: First-Class Support for Semi-Structured Data</h3><p>If you’re working with semi-structured data (JSON, XML), Spark 4.0 introduces the VARIANT data type, designed to make your life easier. Working with JSON and other semi-structured formats has long been a pain point in Spark. Until now, users had to choose between flexibility and performance: either store raw JSON as strings (flexible but slow), or enforce rigid schemas with nested structs (faster, but fragile when schemas evolve). Spark 4.0 addresses this trade-off with the introduction of the VARIANT data type.</p><p>VARIANT is a new columnar type designed for semi-structured data, offering:</p><ul><li>Up to 8× performance improvements over querying JSON stored as strings<a href="#_ftn1">[1]</a></li><li>Schema-on-read flexibility, without requiring upfront normalization or verbose parsing logic.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGHD3Z0tuGyJJG1xoWDnBA.png" /><figcaption>Image from Databricks blog</figcaption></figure><p>Let’s assume we have to deal with such kind of log error entries.</p><pre># Sample JSON error log entries<br>data = [<br>    Row(service=&quot;serviceA&quot;, json_str=&quot;&quot;&quot;{&quot;timestamp&quot;: &quot;2024-06-01T12:34:56Z&quot;, &quot;level&quot;: &quot;ERROR&quot;, &quot;message&quot;: &quot;Failed to connect&quot;, &quot;code&quot;: 504, &quot;details&quot;: {&quot;retry&quot;: true, &quot;timeout&quot;: 30}}&quot;&quot;&quot;),<br>    Row(service=&quot;serviceB&quot;, json_str=&quot;&quot;&quot;{&quot;timestamp&quot;: &quot;2024-06-01T12:35:10Z&quot;, &quot;level&quot;: &quot;WARN&quot;, &quot;message&quot;: &quot;Slow response&quot;, &quot;latency_ms&quot;: 420}&quot;&quot;&quot;),<br>    Row(service=&quot;serviceC&quot;, json_str=&quot;&quot;&quot;{&quot;timestamp&quot;: &quot;2024-06-01T12:35:45Z&quot;, &quot;level&quot;: &quot;ERROR&quot;, &quot;message&quot;: &quot;Null pointer&quot;, &quot;stacktrace&quot;: [&quot;line42&quot;, &quot;line87&quot;]}&quot;&quot;&quot;)<br>]<br><br>df = spark.createDataFrame(data)</pre><p>You can now query nested fields directly in SQL using a familiar notation, all while enjoying improved performance. It’s a cleaner, more efficient approach for modern datasets that don’t fit neatly into rows and columns.</p><pre># Create a Variant Column from JSON<br>df_with_variant = df.selectExpr(&quot;service&quot;, &quot;parse_json(json_str) as json_variant&quot;)<br># Create a temp view to allow for later SQL querying<br>df_with_variant.createOrReplaceTempView(&quot;df_with_variant_view&quot;)</pre><pre>SELECT <br>    service,<br>    json_variant:timestamp AS timestamp,<br>    json_variant:level AS level,<br>    json_variant:code AS code,<br>    json_variant:details.retry AS retry                         <br>FROM df_with_variant_view</pre><p>Variant is particularly useful when the JSON sources have unknown, changing, and frequently evolving schema. Variant data type’s flexibility allows the data to be ingested and performant without requiring an explicit schema. Crucially, VARIANT also brings Spark closer to the capabilities of proprietary cloud data warehouses like Snowflake’s VARIANT, offering an open-source alternative that helps avoid vendor lock-in — something many enterprise users have asked for during migrations.</p><h4>Other developer productivity and data integrity features worth noticing</h4><ul><li><strong>ANSI SQL Mode Now Default</strong>: Spark 4.0 enables ANSI SQL mode by default, enforcing stricter and more predictable SQL behavior and bringing it closer to traditional databases data integrity standards.</li><li><strong>Structured Logging </strong>: Analyzing Spark logs was challenging due to their unstructured nature. Spark 4.0 introduces structured logging, outputting logs as JSON lines with rich metadata like timestamps, log levels and task/job identifiers making logs easier to parse, search, and ingest into modern observability platforms (Spark SQL, ELK or Splunk).</li></ul><h3>Python API, Streaming and other Enhancements in Spark 4.0</h3><p>On top of the major highlights covered above, Spark 4.0 also brings a handful of valuable updates for Python developers and streaming workloads — here are a few worth noting:</p><ul><li><strong>Embedded Plotly</strong>: Plot directly from PySpark DataFrames using .plot() with Plotly — no need to convert to pandas. Ideal for in-notebook EDA and streamlines exploratory data analysis experience.</li><li><strong>Polymorphism for Python UDTFs</strong>: Define Python User-Defined Table Functions that return dynamic schemas based on input. Supports flexible, table-like outputs from Python logic.</li><li><strong>State Store Data Source</strong>: Introspect and debug streaming state directly as a readable DataFrame. Useful for tracking state evolution, errors, and verifying correctness.</li></ul><h3>Where is Spark going ?</h3><p>Apache Spark 4.0 sends a signal about the framework’s future. This release shows Spark is evolving towards a SQL developer-friendly framework, more modular and standards-compliant, aligning closely with how modern data teams actually work. I believe that the efforts which have been and will be steered are following these directions:</p><p>1. <strong>SQL-oriented</strong>: SQL Data Analytics experience is getting more and more streamlined in Spark while allowing developers to express rich logic without leaving SQL. Efforts are clearly focusing on making SQL developments in Spark an overall smoother experience.</p><p>2. <strong>Connect from anywhere:</strong> Spark Connect redefines how teams interact with Spark — lightweight, remote, and multi-language clients with the objective of making Spark even more accessible across environments and applications developed outside of JVM realm.</p><p>3. <strong>Closing the gap with industry standards</strong>: Spark 4.0 continues closing longstanding gaps with some features present in enterprise other data warehouses/platforms, like the VARIANT type or ANSI SQL mode and structured logging, turning workload migration to Spark easier than ever.</p><p>For the full changelog and all the finer engine-level details, check out the <a href="https://spark.apache.org/releases/spark-release-4-0-0.html">official Spark 4.0 release notes</a>.</p><h3>References</h3><ul><li><a href="https://www.databricks.com/blog/introducing-apache-spark-40#:~:text=Apache%20Spark%204.0%20marks%20a%20major%20milestone%20in,new%20Python%20capabilities%2C%20streaming%20improvements%2C%20and%20better%20usability.">Introducing Apache Spark 4.0 | Databricks Blog</a></li><li><a href="https://spark.apache.org/releases/spark-release-4-0-0.html">Spark Release 4.0.0 | Apache Spark</a></li><li><a href="https://www.databricks.com/blog/introducing-open-variant-data-type-delta-lake-and-apache-spark">Introducing the Open Variant Data Type in Delta Lake and Apache Spark | Databricks Blog</a></li></ul><p><a href="#_ftnref1">[1]</a> The benchmarks were conducted by Databricks over schemas inspired by customer data with Databricks Runtime 15.0 with Photon enabled.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2488024f7d36" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orange-business/apache-spark-4-0-whats-new-and-where-it-s-going-2488024f7d36">Apache Spark 4.0: What’s new and where it’s going</a> was originally published in <a href="https://medium.com/orange-business">Orange Business</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>