Skip to content

[SPARK-56619][CONNECT][TESTS] Add DSv2 repeated table access tests with internal/external changes in Spark Connect#55456

Open
longvu-db wants to merge 23 commits into
apache:masterfrom
longvu-db:dsv2-connect-pr2-repeated-sql
Open

[SPARK-56619][CONNECT][TESTS] Add DSv2 repeated table access tests with internal/external changes in Spark Connect#55456
longvu-db wants to merge 23 commits into
apache:masterfrom
longvu-db:dsv2-connect-pr2-repeated-sql

Conversation

@longvu-db
Copy link
Copy Markdown
Contributor

@longvu-db longvu-db commented Apr 21, 2026

What changes were proposed in this pull request?

Add 6 tests in a new DataSourceV2RepeatedSQLConnectSuite that verify DSv2 tables reflect the latest state when accessed repeatedly via sql() in Spark Connect mode (without CACHE TABLE). Each sql("SELECT * FROM t") call creates a fresh plan that is re-analyzed on the server, so it always sees the most recent data, schema, and table identity.

The tests use an in-process Connect server (SparkConnectServerTest) and cover three scenarios, each with a session-write and an external-write variant:

  • Scenario 1 (external writes): After a writer adds rows (via session SQL or catalog API), a subsequent sql() query sees the new data.
  • Scenario 2 (external schema changes): After a writer adds a column and inserts data with the new schema (via session SQL or catalog API), a subsequent sql() query reflects the updated schema.
  • Scenario 3 (drop/recreate): After a writer drops and recreates the table (via session SQL or catalog API), a subsequent sql() query sees the empty recreated table.

External writes use getServerSession() to access the server-side catalog API (loadTable with write privileges, alterTable, dropTable/createTable), matching the pattern used by the classic-mode tests in #55462.

This is the Spark Connect counterpart of #55462.

Shared test infrastructure changes

  • CachingInMemoryTableCatalog (new): A per-instance caching test catalog that wraps InMemoryTableCatalog with a ConcurrentHashMap-based loadTable cache. Although not directly used by these tests, it is included here as shared infrastructure for the broader DSv2 test effort.

Why are the changes needed?

These tests document and lock down the expected behavior: repeated sql() access in Connect mode always sees the latest table state. This prevents regressions if internal resolution or caching logic changes.

Does this PR introduce any user-facing change?

No. This PR is test-only.

How was this patch tested?

6 new tests in DataSourceV2RepeatedSQLConnectSuite, all passing:

build/sbt 'connect/testOnly *DataSourceV2RepeatedSQLConnectSuite'

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

Generated-by: Claude Code (claude-opus-4-6)

@longvu-db longvu-db marked this pull request as draft April 21, 2026 20:48
@longvu-db longvu-db force-pushed the dsv2-connect-pr2-repeated-sql branch from e0758b8 to f94c5cf Compare April 24, 2026 15:35
@longvu-db longvu-db changed the title [SPARK-XXXXX][CONNECT][TESTS] Add Connect repeated SQL refresh tests [SPARK-56619][CONNECT][TESTS] Add Connect repeated SQL refresh tests Apr 24, 2026
@longvu-db longvu-db changed the title [SPARK-56619][CONNECT][TESTS] Add Connect repeated SQL refresh tests [SPARK-56619][CONNECT][TESTS] Add DSv2 repeated table access tests with internal/external changes in Spark Connect Apr 27, 2026
@longvu-db longvu-db closed this Apr 27, 2026
@longvu-db longvu-db reopened this Apr 28, 2026
@longvu-db longvu-db marked this pull request as ready for review April 28, 2026 08:23
@longvu-db longvu-db force-pushed the dsv2-connect-pr2-repeated-sql branch from 44ff5d3 to 994ea5c Compare May 8, 2026 19:56
Copy link
Copy Markdown
Contributor

@andreaschat-db andreaschat-db left a comment

Choose a reason for hiding this comment

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

LGTM. Please update the PR description with the correct number of tests added.

@longvu-db longvu-db force-pushed the dsv2-connect-pr2-repeated-sql branch from 235aa03 to bbdcc77 Compare May 20, 2026 14:04
@longvu-db
Copy link
Copy Markdown
Contributor Author

Auto-review results

1 critical issue found and fixed:

CachingInMemoryTableCatalog.clearCache() in withCleanup (line 82) was called as a companion-object static method, but no companion object exists — only an instance method. This would not compile.

Fix (commit cb75a89): Get the server-side catalog instance and call clearCache() on it, matching the pattern used by the classic DataSourceV2DataFrameSuite:

val serverSession = getServerSession(session)
serverCatalog[CachingInMemoryTableCatalog](serverSession, "cachingcat").clearCache()

No other issues found. Test logic, assertions, cleanup patterns, imports, and style all look good. ✅

@longvu-db
Copy link
Copy Markdown
Contributor Author

Auto-review result (iteration 1)

Status: 1 fix applied and pushed (320e00ea723)

Finding

  • Scaladoc wording: Fixed cross-reference in class-level Scaladoc to use neutral wording when referencing classic-path tests (DataSourceV2DataFrameSuite).

Summary

  • All imports verified: CachingInMemoryTableCatalog, BufferedRows, InMemoryBaseTable, SparkConnectServerTest, getServerSession all exist in the codebase.
  • Code structure looks clean: proper cleanup via withCleanup, named arguments used throughout, test scenarios cover session writes, external writes, schema changes, drop/recreate, and DataFrame reuse — both with and without caching connectors.
  • Branch is rebased against latest upstream master.

The auto-review loop will run one more verification pass to confirm convergence. CI is currently in progress.

longvu-db added 18 commits May 26, 2026 07:51
Adds 6 tests to verify that repeated sql() calls in Spark Connect
mode always see the latest table state. This mirrors the classic-mode
tests added to DataSourceV2DataFrameSuite, covering:

1. Session write: INSERT via SQL, next SELECT sees new row
2. External write: data added via catalog API, next SELECT sees it
3. Session schema change: ADD COLUMN via SQL, next SELECT sees new schema
4. External schema change: column added via catalog API, next SELECT sees it
5. Session drop/recreate: DROP+CREATE via SQL, next SELECT sees empty table
6. External drop/recreate: drop+create via catalog API, next SELECT sees empty

In Connect, every sql() call creates a fresh plan re-analyzed on the
server, so all modifications are always visible.

Co-authored-by: Isaac
Co-authored-by: Isaac
Add 3 new tests that create a DataFrame ONCE and reuse it across
external mutations (data write, schema change, drop/recreate). These
tests would FAIL in classic Spark (where the resolved plan is captured
at DataFrame creation time) but PASS in Connect (where each action
re-sends the plan for fresh server-side analysis).

This makes the suite genuinely Connect-specific, not just a copy of
the classic tests with Connect infrastructure.

Co-authored-by: Isaac
Adds 3 Connect tests verifying that when a DSv2 connector caches table
state, external changes are invisible through repeated sql() calls.

Co-authored-by: Isaac
CachingInMemoryTableCatalog.clearCache() must run AFTER DROP TABLE,
not before. Otherwise DROP TABLE re-caches the table via loadTable(),
and the next test's CREATE TABLE hits a stale cache entry.

Co-authored-by: Isaac
… sql() tests

After asserting stale data with the caching connector, REFRESH TABLE
invalidates the connector cache and verifies external changes become
visible. Also adds invalidateTable override to CachingInMemoryTableCatalog.

Co-authored-by: Isaac
…ng tests

Move each cache test next to its corresponding external test with
matching section numbers. Also adds invalidateTable override to
CachingInMemoryTableCatalog for REFRESH TABLE support.

Co-authored-by: Isaac
Co-authored-by: Isaac
Remove unnecessary ClassTag from serverCatalog, add externalAppend
helper method, and use it to reduce boilerplate in test bodies.

Co-authored-by: Isaac
Co-authored-by: Isaac
longvu-db added 5 commits May 26, 2026 07:51
…panion object

CachingInMemoryTableCatalog has no companion object, so the static call
CachingInMemoryTableCatalog.clearCache() does not compile. Fixed by
getting the server-side catalog instance and calling clearCache() on it,
matching the pattern used by the classic DataSourceV2DataFrameSuite.

Co-authored-by: Isaac
The withCleanup method was unconditionally accessing the cachingcat
catalog to clear its cache, but the Connect server session only loads
a catalog when first accessed via SQL. Tests using testcat never
trigger loading cachingcat, causing CatalogNotFoundException.

Co-authored-by: Isaac
@longvu-db longvu-db force-pushed the dsv2-connect-pr2-repeated-sql branch from 3b13024 to b06c979 Compare May 26, 2026 07:52
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.

2 participants