Skip to content

[SPARK-59030][SQL] Support DSv2 Join pushdown for DB2 connector - #58321

Open
shrirangmhalgi wants to merge 1 commit into
apache:masterfrom
shrirangmhalgi:SPARK-59030-db2-join-pushdown
Open

[SPARK-59030][SQL] Support DSv2 Join pushdown for DB2 connector#58321
shrirangmhalgi wants to merge 1 commit into
apache:masterfrom
shrirangmhalgi:SPARK-59030-db2-join-pushdown

Conversation

@shrirangmhalgi

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR enables DSv2 Join pushdown for the DB2 JDBC connector by:

  1. Fixing DB2SQLQueryBuilder.build() to use the tableOrQuery method instead of directly accessing options.tableOrQuery. The tableOrQuery method returns the join subquery (when set by withJoin()), which is required for join pushdown to produce correct SQL.
  2. Adding override def supportsJoin: Boolean = true to DB2Dialect.

Why are the changes needed?

Join pushdown was introduced in SPARK-52187 and enabled for Oracle (SPARK-52823), PostgreSQL (SPARK-52906), and MySQL/MSSQL (SPARK-52929). DB2 was not included in that batch despite supporting ANSI standard join syntax natively.

Additionally, DB2SQLQueryBuilder.build() had a latent bug - it used ${options.tableOrQuery} (the raw table name) instead of $tableOrQuery (the method that returns the join subquery when one is pushed). Without this fix, enabling supportsJoin would generate incorrect SQL that ignores the pushed join entirely. All other dialects with custom build() overrides (Oracle, MySQL, MSSQL) correctly use the $tableOrQuery method.

Does this PR introduce any user-facing change?

No. Join pushdown is an internal optimization that produces the same query results. Users reading from DB2 via JDBC with joins will see improved performance as the join is now executed on the DB2 server instead of in Spark.

How was this patch tested?

  • Added a unit test in JDBCSuite that directly verifies DB2SQLQueryBuilder generates correct join SQL when withJoin() is called.
  • Added DB2JoinPushdownIntegrationSuite — a Docker integration test following the exact pattern of the existing Oracle/PostgreSQL/MySQL/MSSQL join pushdown integration suites.
  • All 317 existing JDBC tests pass with zero regressions.

Was this patch authored or co-authored using generative AI tooling?

Yes. Co-Authored using Claude Opus 4.8.

Fix DB2SQLQueryBuilder.build() to use the tableOrQuery method instead of
directly accessing options.tableOrQuery. The tableOrQuery method returns
the join subquery when joinQuery is set by withJoin(), which is required
for join pushdown to produce correct SQL. Without this fix, enabling
supportsJoin would generate queries against the raw table name, ignoring
the pushed join entirely.

Also enables supportsJoin = true for DB2Dialect, completing the join
pushdown support that was added for Oracle (SPARK-52823), PostgreSQL
(SPARK-52906), and MySQL/MSSQL (SPARK-52929).

DB2 uses ANSI standard join syntax, so no dialect-specific SQL generation
override is needed -- the shared JdbcSQLQueryBuilder.withJoin() framework
handles it correctly.

Tests:
- Added unit test in JDBCSuite verifying DB2 join query builder output
- Added DB2JoinPushdownIntegrationSuite (Docker integration test)
- All 317 existing JDBC tests pass with zero regressions

@shrirangmhalgi shrirangmhalgi left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @PetarVasiljevic-DB / @cloud-fan. Could you PTAL. This PR extends the join pushdown series built (SPARK-52187 / SPARK-52823 / SPARK-52906 / SPARK-52929) to DB2 - also fixes a latent bug in DB2SQLQueryBuilder.build() that used options.tableOrQuery instead of the tableOrQuery method.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant