Skip to content

[FEATURE] Support Spark DataSource V2 API #704

Description

@lawofcycles

Is your feature request related to a problem?

The current Spark connector uses the DataSource V1 API. This limits the optimizations that Spark's Catalyst optimizer can delegate to OpenSearch. For example, aggregations like GROUP BY with COUNT cannot be pushed down to OpenSearch, forcing Spark to pull all matching documents and perform aggregation in memory.

This limitation has been reported in #302.

What solution would you like?

Migrate the Spark connector from DataSource V1 to DataSource V2 API. This would enable the following optimizations:

Capability Spark Interface Benefit
Aggregation pushdown SupportsPushDownAggregates (Spark 3.2+) Translate GROUP BY / COUNT / SUM etc. into OpenSearch aggregation queries, returning only aggregated results instead of all documents
LIMIT pushdown SupportsPushDownLimit (Spark 3.3+) Pass size: N to OpenSearch instead of scrolling through all documents
TopN pushdown SupportsPushDownTopN (Spark 3.3+) Translate ORDER BY ... LIMIT N into OpenSearch sort + size
Statistics reporting SupportsReportStatistics Report row count and data size estimates to Spark for better JOIN strategy selection
Partitioning reporting SupportsReportPartitioning Inform Spark about OpenSearch shard layout to reduce unnecessary shuffles

The V2 API is stable across Spark 3.2+ and Spark 4.0, so the implementation would be compatible with both the sql-30 and sql-40 modules.

A phased approach could be taken:

  1. Phase 1: Implement the core V2 framework (TableProvider, Table, ScanBuilder, Batch) with existing filter pushdown
  2. Phase 2: Add SupportsPushDownAggregates for aggregation pushdown
  3. Phase 3: Add SupportsPushDownLimit and SupportsPushDownTopN

What alternatives have you considered?

N/A

Do you have any additional context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions