What’s New in Apache Spark 4.0.0: ANSI SQL, Spark Connect, Python and Streaming
Apache Spark 4.0.0, released in May 2025, turns on ANSI SQL by default, requires Java 17, makes Spark Connect practical and adds pipe syntax, VARIANT and SQL functions. What changed and what to check before upgrading.
Tecyfy · Published · Updated · 9 min read
Written in June 2025, when this was news. Models and prices have moved on since: today's are on Model prices.
Apache Spark 4.0.0 was released on 23 May 2025, the first release of the 4.x line. The changes that matter most day to day are that SQL now follows the ANSI standard by default, Java 17 is the new minimum, Spark Connect has much wider API coverage, and SQL gained pipe syntax, a VARIANT type for JSON and SQL user-defined functions. This article goes through each, then what to check before upgrading.
ANSI SQL mode is on by default
Spark 3 quietly returned NULL for many errors: a division by zero, a number too big for its type, a string that could not be cast. In Spark 4.0, spark.sql.ansi.enabled is true, and the same queries fail with a named error:
SELECT 1 / 0;
-- [DIVIDE_BY_ZERO] Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead.
SELECT try_divide(1, 0); -- NULL
SELECT try_cast('abc' AS INT); -- NULL
This is the change most likely to break an existing job, and it is a good one: bad data now stops the job instead of turning into empty values that someone finds weeks later. Where a NULL really is the right answer, use the try_ functions (try_divide, try_cast, try_add and others) rather than turning ANSI mode off for the whole session.
Java 17 and Scala 2.13
Spark 4.0 drops Java 8 and 11 and makes Java 17 the default. Java 21 is also supported. Scala 2.12 is gone, so every Scala library must be built for 2.13. Python 3.8 is no longer supported. These are the changes that decide whether your cluster images and dependencies need rebuilding before anything else.
Spark Connect grows up
Spark Connect separates your application (the client) from the cluster (the server): the client sends a plan, the server runs it. Spark 4.0 brings substantial improvements:
- A small Python client.
pip install pyspark-clientinstalls a 1.5 MB package with no JVM, for applications that only talk to a remote cluster. - Wider API coverage, including ML on Spark Connect.
spark.api.mode, a setting that turns Spark Connect on or off for an application.- A Swift client joins the Python, Scala and Java ones. Clients for Go and Rust are separate community projects under the Apache Spark organisation.
SQL: pipe syntax, VARIANT, SQL functions and more
Pipe syntax lets you write a query as a list of steps joined by |>, starting from the table:
FROM sales
|> WHERE amount > 100
|> AGGREGATE SUM(amount) AS revenue GROUP BY region
|> ORDER BY revenue DESC;
Our guide to the pipe operator covers each step.
VARIANT is a new data type for semi-structured data such as JSON, which you load with parse_json. Fields are read with variant_get, not dot notation:
SELECT variant_get(parse_json('{"user": {"id": 5}}'), '$.user.id', 'int'); -- 5
The VARIANT article measures it against JSON strings.
SQL user-defined functions are written in SQL itself:
CREATE TEMPORARY FUNCTION revenue(price INT, qty INT) RETURNS INT RETURN price * qty;
Session variables hold a value for the rest of a SQL session: DECLARE VARIABLE min_amount INT DEFAULT 100; and then WHERE amount > min_amount.
String collation makes comparisons and sorting case- or accent-insensitive per column or expression, for example 'a' COLLATE UNICODE_CI_AI = 'Á' is true.
There is also a built-in XML data source, so reading XML no longer needs an extra package.
Python
- Plotting on DataFrames.
df.plot.line(...),df.plot.bar(...),df.plot.hist(...)and others use PySpark's new native plotting API. - The Python Data Source API. A connector to a new source or sink can be written in Python alone, with no Scala or Java.
- Python UDTFs, functions that return a table, and unified profiling for Python UDFs.
Structured Streaming
transformWithState, the second version of the API for custom stateful processing: several named state variables per key, timers and time-to-live for state.- The State Data Source, which reads a streaming query's state from its checkpoint as an ordinary batch DataFrame. It is the tool to reach for when a stateful job gives a wrong answer and you need to see what it remembered.
Operations
- Structured logging. Spark can write its logs as JSON lines with named fields, which log search tools can filter without parsing text.
- A Spark Kubernetes Operator is now an Apache Spark subproject for running Spark applications on Kubernetes.
- Mesos support is removed and SparkR is deprecated.
Before you upgrade
- Run your SQL with ANSI on in a test environment first. Fix failing casts and divisions with the
try_functions or by cleaning the data. - Move to Java 17 or 21 and Scala 2.13, and check that every connector and library you use has a Spark 4 build.
- Read the migration guide for your parts of Spark (SQL, PySpark, Structured Streaming). It lists every behaviour change.
On Databricks, Databricks Runtime 17.0, released in June 2025, is powered by Apache Spark 4.0.0; support for it has since ended.
Since this release, the 4.1 and 4.2 lines have followed; as of October 2026 the latest releases are 4.2.1, 4.1.4 and 4.0.5.
Tecyfy Takeaway
Spark 4.0 is a major version in the real sense: ANSI SQL by default and Java 17 can break jobs that ran for years on Spark 3, so test before you move. In return you get stricter, safer SQL, a cleaner way to write long queries, a proper type for JSON, and a Spark Connect client light enough to drop into any Python service.
Questions
- When was Apache Spark 4.0 released?
- Apache Spark 4.0.0 was released on 23 May 2025, the first release of the 4.x line. Databricks Runtime 17.0, released in June 2025, is powered by Apache Spark 4.0.0.
- What is the biggest breaking change in Spark 4.0?
- ANSI SQL mode is on by default, so errors that used to return NULL, such as division by zero or a failed cast, now fail the query. Use try_divide, try_cast and the other try_ functions where NULL is the right answer.
- Which Java version does Spark 4.0 need?
- Java 17 is the minimum and the default, and Java 21 is also supported. Java 8 and 11, Scala 2.12 and Python 3.8 are no longer supported.
- What is Spark Connect in Spark 4.0?
- Spark Connect separates your application from the cluster: the client sends a plan and the server runs it. Spark 4.0 adds a 1.5 MB Python client with no JVM (pyspark-client), wider API coverage including ML, and spark.api.mode to switch between classic Spark and Connect.
- What should I check before upgrading to Spark 4.0?
- Run your SQL with ANSI mode on in a test environment, move to Java 17 or 21 and Scala 2.13 with Spark 4 builds of every library, and read the migration guide for SQL, PySpark and Structured Streaming.
Sources