Skip to content

[SQL] Fix JDBC V2 join pushdown for partitioned reads and partial AVG - #58958

Draft
urosstan-db wants to merge 2 commits into
apache:masterfrom
urosstan-db:urosstan-db/jdbc-dsv2-join-investigation
Draft

urosstan-db wants to merge 2 commits into
apache:masterfrom
urosstan-db:urosstan-db/jdbc-dsv2-join-investigation

Conversation

@urosstan-db

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Fix two JDBC Data Source V2 join pushdown bugs:

  • Keep reads with partitionColumn configured as Spark-side joins, preserving partitioned JDBC reads. Log the reason at debug level.
  • Preserve pushed-join column aliases when rewriting a partially pushed AVG into SUM and COUNT.

Add SQL regressions to JDBCV2JoinPushdownIntegrationSuiteBase.

Why are the changes needed?

Join pushdown creates a JDBC query, which cannot be combined with partitionColumn. Partitioned inputs currently fail with Options 'query' and 'partitionColumn' can not be specified together.

Partial AVG normalization uses the original relation output instead of the pushed-join aliases. This can silently aggregate the wrong column: the H2 self-join regression returns 5.413043 instead of 4.413043 without the fix.

Does this PR introduce any user-facing change?

Yes. With JDBC V2 join pushdown enabled, partitioned input queries execute successfully using Spark-side joins, and partially pushed averages over joins return the correct result.

How was this patch tested?

The shared SQL tests cover partitioned reads with one and two partitions, and compare AVG results with one partition, two partitions, and join pushdown disabled. The AVG test is skipped when aggregate pushdown is unsupported.

Confirmed both original regressions fail before their fixes. Also reran the revised three-way AVG test without its fix and confirmed the incorrect result above.

Validation on the committed changes with JDK 21 and H2: all 24 tests in
JDBCV2JoinPushdownSuite and all 3 selected partial-pushdown tests in JDBCV2Suite passed.

build/sbt 'sql/testOnly *JDBCV2JoinPushdownSuite' \
  'sql/testOnly *JDBCV2Suite -- -z "partial push-down"'

Other databases' integration suites were not run.

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

Generated-by: OpenAI Codex CLI 0.154.0

val rows = withSQLConf(SQLConf.DATA_SOURCE_V2_JOIN_PUSHDOWN.key -> "false") {
sql(sqlQuery).collect().toSeq
}
assert(rows.nonEmpty)

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.

Let's use only join pushdown = true path, assert join is not pushed down, and assert on entire result


test("Join pushdown preserves aliases in partially pushed averages") {
assume(supportsAggregatePushdown, "Aggregate pushdown is not supported")
val id = caseConvert("id")

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.

Move id to inner function, name it idCol

|""".stripMargin
}

val rows = withSQLConf(SQLConf.DATA_SOURCE_V2_JOIN_PUSHDOWN.key -> "true") {

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.

Use better naming, e.g. rowsWithJoinPushdown

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