Data Source V2
| Also known as | DSV2, DataSource V2 API, connector API |
|---|---|
| Field | Query engine extensibility |
| Key parts | CatalogPlugin and TableCatalog, Table, ScanBuilder and Scan, WriteBuilder and BatchWrite, pushdown mix-ins |
| Open source implementations | Apache Spark; used by Apache Iceberg, Delta Lake and the Spark JDBC source |
| Related | Catalog plugin API (Spark), Predicate pushdown, Time travel (SQL) |
Data Source V2 (DSV2) is the connector API of Apache Spark: a set of Java interfaces in the org.apache.spark.sql.connector package that lets an external system plug its catalogs, tables, reads and writes into Spark's query planning and execution.[1] A connector starts from a small core and opts in to features such as filter pushdown, columnar reads, row-level DELETE/UPDATE/MERGE and catalog support by implementing mix-in interfaces. The Spark documentation names the built-in JDBC source, Apache Iceberg, Delta Lake and Lance as users of the API.[1]
What problem does Data Source V2 solve?
The earlier Data Source V1 API depended on Scala. Data Source V2 is a pure Java API, adds native catalog integration (namespaces, tables, views, functions and procedures), and lets a connector receive pushed-down filters, columns, aggregates, limits and offsets. A connector can also report its data layout so that Spark skips shuffles and sorts, or ask Spark to repartition and sort rows before a write.[1]
Data Source V2 also unifies batch and streaming. The same Table abstraction serves batch reads, micro-batch and continuous streaming reads, and streaming writes, chosen by the capabilities the table declares.[1][2]
History
Spark 2.3.0 introduced "Data source API V2" (SPARK-15689) as an experimental API and warned that breaking changes should be expected.[3] Spark 3.0.0 refactored the API (SPARK-25390) and added the catalog plugin API (SPARK-31121); the core interfaces Table, TableProvider and TableCatalog carry @since 3.0.0.[4][5]
Later releases extended the API rather than replacing it. Spark 3.3.0 added complete aggregate pushdown, top-N pushdown and the AS OF time travel syntax (SPARK-37219); Spark 3.5.0 added MERGE and UPDATE handling for delta-based and group-based sources.[6][7] Spark 4.0.0 added the Python Data Source API (SPARK-44076), a Python wrapper for lightweight connectors.[8] In 4.3.0 core interfaces such as Table, TableCatalog and ScanBuilder are annotated @Evolving, and some newer ones, such as SupportsRowLevelOperations and SupportsRuntimeV2Filtering, are @Experimental.[9][10][11][12][13]
What are the entry points?
A Data Source V2 connector enters Spark in one of two ways.[1]
TableProviderreturns aTablefrom a map of options, such as a path or a Kafka topic. It is used withspark.read.format(...). Built-in file sources addSupportsCatalogOptionsso that option-based tables can take part in DDL through the session catalog.CatalogPluginis registered under a name withspark.sql.catalog.<name>=<class>and exposes a catalog of namespaces and tables (and optionally views, functions and procedures). Iceberg and Delta Lake use this route. See Catalog plugin API (Spark).
How does the read path work?
A table that implements SupportsRead returns a ScanBuilder. Spark negotiates pushdown with the builder, calls build() to get a logical Scan, and turns that into a physical Batch. The Batch returns an array of InputPartition objects, one per Spark task, and a serializable PartitionReaderFactory that creates a PartitionReader on each executor. Readers return rows or columnar batches.[1]
A Scan can add further mix-ins. SupportsReportPartitioning reports how output is partitioned, which enables storage-partitioned joins without a shuffle; SupportsReportOrdering reports sort order; SupportsReportStatistics feeds the cost-based optimizer; and SupportsRuntimeV2Filtering accepts filters at execution time for dynamic partition pruning.[1]
Which pushdown interfaces exist?
Pushdown in Data Source V2 is a negotiation: Spark calls a method on the ScanBuilder with the operators, the connector returns what it cannot handle, and Spark evaluates the rest itself.[1] The documented order is sample, filter, aggregate, limit or top-N, offset, then column pruning.[1] See Predicate pushdown for the general idea.
Mix-in on ScanBuilder |
Pushes down | Since |
|---|---|---|
SupportsPushDownRequiredColumns |
Column pruning | 3.0.0[14] |
SupportsPushDownFilters |
Filters as V1 Filter objects |
3.0.0[15] |
SupportsPushDownV2Filters |
Filters as V2 Predicate expressions; preferred over the V1 variant |
3.3.0[16] |
SupportsPushDownAggregates |
Aggregates and group-by | 3.2.0[17] |
SupportsPushDownLimit, SupportsPushDownTopN |
LIMIT, and ORDER BY with LIMIT |
3.3.0[18] |
SupportsPushDownTableSample |
TABLESAMPLE |
3.3.0[19] |
SupportsPushDownOffset |
OFFSET |
3.4.0[20] |
SupportsPushDownJoin |
Joins whose two sides the same underlying source can process together (for example two JDBC scans on one server) | 4.1.0[21] |
How does the write path work?
A table that implements SupportsWrite returns a WriteBuilder. Mix-ins on the builder select the write mode: SupportsTruncate, SupportsOverwriteV2 (overwrite rows matching a filter) and SupportsDynamicOverwrite (overwrite partitions). The builder produces a logical Write, which produces a BatchWrite or a StreamingWrite.[1]
BatchWrite uses a two-phase commit. Each task's DataWriter commits or aborts its own part and returns a message; after all tasks finish, the driver calls commit(messages) or abort(messages). Data from individual tasks should not be visible to readers until the driver commit succeeds.[1] A Write that implements RequiresDistributionAndOrdering makes Spark insert a shuffle and sort before writing, which table formats use for clustering.[1]
For row-level DML, a table implements SupportsRowLevelOperations. Group-based sources (copy-on-write) rewrite whole files or partitions; delta-based sources (merge-on-read) accept a stream of row changes. Simpler deletes can go through SupportsDeleteV2, whose canDeleteWhere lets Spark fall back to a rewrite when the source cannot drop rows by predicate alone.[1] See Copy-on-write and merge-on-read.
Example
The Python Data Source API wraps Data Source V2 for connectors written in Python. This PySpark sketch defines a source with two input partitions, registers it and reads it:[22]
from pyspark.sql.datasource import DataSource, DataSourceReader, InputPartition
class EvenOddSource(DataSource):
@classmethod
def name(cls):
return "even_odd"
def schema(self):
return "id INT"
def reader(self, schema):
return EvenOddReader(int(self.options.get("n", "10")))
class EvenOddReader(DataSourceReader):
def __init__(self, n):
self.n = n
def partitions(self):
return [InputPartition(0), InputPartition(1)] # one Spark task each
def read(self, partition):
for i in range(partition.value, self.n, 2):
yield (i,)
spark.dataSource.register(EvenOddSource)
spark.read.format("even_odd").option("n", "6").load().show()
Use in an open lakehouse
Open table formats reach Spark through Data Source V2. Iceberg registers org.apache.iceberg.spark.SparkCatalog and Delta Lake registers org.apache.spark.sql.delta.catalog.DeltaCatalog as Spark catalogs, and the Spark documentation lists both projects as users of the API.[1][23][24] Unity Catalog OSS connects to Spark through its own catalog class, io.unitycatalog.spark.UCSingleCatalog.[25]
See also
- Catalog plugin API (Spark)
- Predicate pushdown
- Time travel (SQL)
- Copy-on-write and merge-on-read
- Apache Spark
References
- ↑ 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 Data Source V2 (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ TableCapability.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Spark Release 2.3.0. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Spark Release 3.0.0. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Table.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Spark Release 3.3.0. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Spark Release 3.5.0. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Spark Release 4.0.0. Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Table.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ TableCatalog.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ ScanBuilder.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsRowLevelOperations.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsRuntimeV2Filtering.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownRequiredColumns.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownFilters.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownV2Filters.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownAggregates.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownTopN.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownTableSample.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownOffset.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SupportsPushDownJoin.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ datasource.py (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Spark Configuration (Apache Iceberg 1.12.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Table batch reads and writes. Delta Lake (Linux Foundation).Retrieved 2026-11-23.
- ↑ Unity Catalog Apache Spark integration. Unity Catalog (LF AI & Data).Retrieved 2026-11-23.