Apache Spark 4.2 features: what's new and what breaks
Spark 4.2.0, released on 14 July 2026, adds geospatial types, change data capture with a CHANGES clause, Auto CDC in declarative pipelines, metric views, a NEAREST BY join and Arrow-optimized Python UDFs by default. What each one does, the code, and the 10 changes to check before you upgrade.
Tecyfy · Published · 8 min read

Apache Spark 4.2.0 came out on 14 July 2026. Its main additions are geospatial types, change data capture built into Spark, Auto CDC in declarative pipelines, metric views, a nearest-neighbour join, and Python UDFs that run on Arrow by default. Most PySpark code runs on it unchanged. The things to check before upgrading are PyArrow 18, the Arrow default for UDFs and a few SQL results that now differ.
Databricks ships it in Databricks Runtime 19. If you are on Spark 4.0, what's new in Spark 4.0 covers the step before this one.
The new features at a glance
| Feature | What it gives you | Who it is for |
|---|---|---|
GEOMETRY and GEOGRAPHY types | Map shapes and points as real types, ST_* functions, Parquet read and write | Anyone joining on location |
CHANGES clause, spark.read.changes() | Read the rows a table inserted, updated or deleted between 2 versions | Incremental pipelines |
| Auto CDC | Apply a change feed to a table without writing MERGE | Declarative pipeline users |
| Metric views | Define a measure once, query it by any grouping with MEASURE() | BI and AI on Spark SQL |
NEAREST BY join | The top-K nearest rows from another table, in one join | Matching and similarity search |
| Arrow Python UDFs by default | Faster Python UDFs with no code change | Every PySpark user |
QUALIFY, WITH SCHEMA EVOLUTION, time_bucket | Smaller SQL for common jobs | SQL users |
| New Spark UI, Java 25 | Dark mode and searchable plans; a newer JVM | Everyone |
Geospatial types, on by default
Spark now has GEOMETRY and GEOGRAPHY types with ST_* functions, reads and writes them as WKB, WKT and Parquet, and has a full registry of coordinate systems. Until now this needed Apache Sedona or a library of UDFs. Delivery zones, store catchments and "orders within 5 km" become plain SQL.
Change data capture inside Spark
Change data captureChange Data CaptureCopying only the rows that were added, changed or deleted in a source database, read from its change log, instead of copying the whole table again. is now part of Spark itself. A table's changes between 2 versions come back as a DataFrame:
changes = (
spark.read
.option("startingVersion", "10")
.option("endingVersion", "20")
.changes("shop.orders")
)
SQL has a matching CHANGES clause, and a streaming read keeps up with new changes. There is a catch in the docs: it works for Data Source V2 tables whose catalog implements the change log, so it depends on your table format supporting it.
The other half is Auto CDC, which applies a change feed to a target table in Spark Declarative Pipelines. In 4.2 it keeps a SCD type 1Slowly Changing DimensionsThe ways a warehouse handles a change to a descriptive record, such as a customer's address: type 1 overwrites it, type 2 adds a new dated version, and type 3 keeps the previous value in an extra column. table from Python only: SQL and type 2 are marked for Spark 4.3. Spark 4.2 Auto CDC works through it with late and deleted rows.
Metric views come to open-source Spark
CREATE VIEW ... WITH METRICS defines measures in YAML once, so revenue per customer is computed correctly whatever it is grouped by. Databricks has had metric views in Unity Catalog for a while; 4.2 brings the same idea to Spark SQL. Databricks metric views shows an example and the limits.
Python is faster by default
Plain Python UDFs and UDTFs now run Arrow-optimized, and data moves between Python and the JVM as Arrow, with no change to your code. It is the biggest change most people will notice, in speed, and the one most likely to surface a type difference. The settings to switch each back are in the questions below.
The rest worth knowing
NEAREST BYis a new join that keeps the top K nearest rows of the other table, with new vector similarity, norm and average functions beside it. Matching products to embeddings no longer needs a cross join and a window.- Real-time mode processes streams with millisecond latency, in 4.2 for stateless PySpark queries without Python UDFs.
- SQL:
QUALIFYfilters on a window function directly;INSERT INTO ... WITH SCHEMA EVOLUTIONadds new columns;INSERT INTO ... REPLACE ONreplaces matching rows;time_bucketgroups timestamps;SET PATHandCURRENT_PATH()control name lookup, off unless you turn onspark.sql.path.enabled. - Data Source V2 connectors can commit several operations as one transaction.
- Platform: Java 25 support, a new Spark UI with dark mode and side-by-side plans, and R 3.x dropped.
What breaks, or gives a different answer
Mark what your jobs use:
PySpark
PyArrow older than 18
Not usedPySpark
PyPy
Not usedPySpark
Plain Python UDFs
Results can differPySpark
Pandas UDFs on integer columns with nulls
Results can differPySpark
createDataFrame from a NumPy array
Not usedPySpark
pandas API on Spark drop()
Not usedSQL
GROUP BY GROUPING SETS (())
Results can differSQL
NATURAL JOIN on mixed-case names
Not usedSQL
A schema named builtin or session
Not usedSQL
Observation.get in error handling
Not used
3 changes to check, none that fail outright: the results can differ, so compare outputs. Start with: usually faster with no change. If results differ, set spark.sql.execution.pythonUDF.arrow.enabled to false and test.
From the Spark 4.2.0 SQL migration guide and the PySpark 4.1 to 4.2 upgrade guide. Not every line of either guide is here: these are the changes most jobs can meet.
2 more changes affect everyone a little. Shuffle outputs now carry order-independent checksums by default: when a retried stage gives different data, Spark reruns the stages that depend on it, and fails the job if it cannot. And duplicate CTE names that differ only in case, such as a and A, are now an error.
Should you upgrade now?
On Databricks, try it on Runtime 19 with a copy of your heaviest jobs. On your own clusters, upgrade PyArrow first, run the test suite on 4.2, and compare a day's output of every job that uses Python UDFs or pandas UDFs. Our data engineering course runs every example on PySpark 4.2.0, so it is a quick way to see the new version working.
Questions
- When was Apache Spark 4.2 released?
- Apache Spark 4.2.0 was released on 14 July 2026. It is the third release of the Spark 4.x line, with over 1,700 Jira tickets resolved by more than 250 contributors. Databricks says it is available in Databricks Runtime 19.
- What are the main new features in Spark 4.2?
- Geospatial GEOMETRY and GEOGRAPHY types with ST_ functions, on by default; change data capture through a SQL CHANGES clause and spark.read.changes(); Auto CDC in Spark Declarative Pipelines for SCD type 1; metric views with CREATE VIEW ... WITH METRICS; a NEAREST BY top-K join; vector functions; SQL PATH name resolution; Arrow-optimized Python UDFs by default; a QUALIFY clause; INSERT ... WITH SCHEMA EVOLUTION; a new Spark UI with dark mode; and Java 25 support.
- Does Spark 4.2 break my PySpark code?
- Most code runs unchanged, but check 6 things: PyArrow must be 18.0.0 or later, PyPy is no longer supported, Python UDFs now run with Arrow by default, pandas UDFs get nullable integer columns as Int64 instead of float64, createDataFrame from NumPy needs PyArrow, and pandas-on-Spark drop() raises KeyError for any missing label.
- How do I turn off Arrow Python UDFs in Spark 4.2?
- Set spark.sql.execution.pythonUDF.arrow.enabled to false for UDFs, spark.sql.execution.pythonUDTF.arrow.enabled to false for UDTFs, and spark.sql.execution.arrow.pyspark.enabled to false for the Arrow data exchange between PySpark and the JVM. Test with the default first: it is usually faster.
- Does Spark 4.2 have SCD type 2 in Auto CDC?
- No. Spark 4.2's create_auto_cdc_flow supports SCD type 1 only, from Python. The SQL AUTO CDC syntax and SCD type 2 are marked for Spark 4.3 in Apache's Jira. Databricks' Lakeflow pipelines already have both.
Sources