Skip to content

[SPARK-58226][SQL] Honor persistentCatalogFirst for DDL on two-part name resolution#57381

Open
jiashenC wants to merge 1 commit into
apache:masterfrom
jiashenC:ddl-multi-part-resolution
Open

[SPARK-58226][SQL] Honor persistentCatalogFirst for DDL on two-part name resolution#57381
jiashenC wants to merge 1 commit into
apache:masterfrom
jiashenC:ddl-multi-part-resolution

Conversation

@jiashenC

@jiashenC jiashenC commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

The DDL / misc-command resolution path (Analyzer.lookupTableOrView, used by DESCRIBE TABLE, ALTER TABLE, etc.) always resolved a local temp view before the persistent relation for a two-part session.<name> identifier, ignoring spark.sql.legacy.persistentCatalogFirst. Whereas, the SELECT/DML path (RelationResolution.resolveRelation) already honors that config for the same name shape from #53630, so the two paths diverged: the same session.<name> could resolve to different relations in a query vs. a DDL command.

Why are the changes needed?

To resolve the resolution divergence and ambiguity between DDL and SELECT.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Add test to check for DDL commands like DESCRIBE TABLE and ALTER TABLE resolve to the correct table entity.

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

Generated-by: Claude-Opus4.8

@jiashenC
jiashenC force-pushed the ddl-multi-part-resolution branch from 20933bc to b8297e0 Compare July 20, 2026 16:30
…ession.<name>

The DDL / misc-command resolution path (`Analyzer.lookupTableOrView`, used by
DESCRIBE TABLE, ALTER TABLE, etc.) always resolved a local temp view before the
persistent relation for a two-part `session.<name>` identifier, ignoring
`spark.sql.legacy.persistentCatalogFirst`. The SELECT/DML path
(`RelationResolution.resolveRelation`) already honors that config for the same
name shape, so the two paths diverged: the same `session.<name>` could resolve
to different relations in a query vs. a DDL command.

This makes `lookupTableOrView` mirror `resolveRelation`: for a two-part
`session.<name>`, resolution order follows `SQLConf.prioritizeSystemCatalog`
(the inverse of `PERSISTENT_CATALOG_FIRST`). All other name shapes and the
default (`prioritizeSystemCatalog = true`) keep their existing behavior.

Adds SECTION 15 to `RelationQualificationSuite`, the DDL companion to the
existing SELECT-path SECTION 13.
@jiashenC
jiashenC force-pushed the ddl-multi-part-resolution branch from b8297e0 to 84aa25c Compare July 20, 2026 17:01
@jiashenC jiashenC changed the title [SPARK-XXXXX][SQL] Honor persistentCatalogFirst for DDL on two-part s… [SPARK-XXXXX][SQL] Honor persistentCatalogFirst for DDL on two-part name resolution Jul 20, 2026
@jiashenC jiashenC changed the title [SPARK-XXXXX][SQL] Honor persistentCatalogFirst for DDL on two-part name resolution [SPARK-58226][SQL] Honor persistentCatalogFirst for DDL on two-part name resolution Jul 20, 2026

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @jiashenC! LGTM, adding @cloud-fan @srielau @zhengruifeng - PTAL

@cloud-fan cloud-fan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 blocking, 0 non-blocking, 0 nits.
One blocking correctness issue: the DDL path can still perform persistent lookup for a missing three-part system.session.<name>, unlike the temp-only SELECT/DML path.

Correctness (1)

  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:1333: Three-part system.session.<name> is not temp-only in the DDL path when the temp view is missing. -- see inline

Verification

Traced Analyzer.lookupTableOrView candidate evaluation against RelationResolution.resolveRelation and checked every added test branch. No tests were run.

PR description suggestions

  • Update the user-facing change section: the PR intentionally changes which relation two-part DDL identifiers resolve to when persistentCatalogFirst is enabled.

!conf.prioritizeSystemCatalog) {
persistentCandidate.orElse(tempViewCandidate)
} else {
tempViewCandidate.orElse(persistentCandidate)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please keep system.session.<name> temp-only before taking this fallback. Three-part names also reach this else, so a missing temp view evaluates persistentCandidate, unlike SELECT/DML's early return from resolveTempView. The new test always creates the temp view and cannot catch that miss path; please add a no-temp case as well.

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.

3 participants