Skip to content

[SPARK-33903][SQL] Add CREATE VIEW AS SELECT support for V2 ViewCatalog#55042

Open
viirya wants to merge 3 commits intoapache:masterfrom
viirya:create-view-v2
Open

[SPARK-33903][SQL] Add CREATE VIEW AS SELECT support for V2 ViewCatalog#55042
viirya wants to merge 3 commits intoapache:masterfrom
viirya:create-view-v2

Conversation

@viirya
Copy link
Copy Markdown
Member

@viirya viirya commented Mar 26, 2026

What changes were proposed in this pull request?

Route CREATE VIEW and DROP VIEW through the V2 execution path when the target catalog implements ViewCatalog.

Changes:

  • ResolveSessionCatalog: allow CreateView and DropView to fall through (instead of throwing) when the target catalog implements ViewCatalog; non-ViewCatalog V2 catalogs still throw the capability error.

  • DataSourceV2Strategy: add routing cases for CreateView and DropView targeting a ViewCatalog. For CREATE VIEW, the aliased schema and current catalog/namespace are pre-computed from the session and passed to the exec.

  • CreateV2View: a new logical plan node that extends AnalysisOnlyCommand, to replace the CreateView fall-through path when targeting a ViewCatalog.

  • CreateViewExec: new LeafV2CommandExec that validates the view body (no temp-object references, no auto-generated aliases) and calls ViewCatalog.createView / replaceView with a ViewInfo built from the analyzed query schema, SQL text, and user properties.

  • DropViewExec: new LeafV2CommandExec that calls ViewCatalog.dropView.

  • InMemoryViewCatalog: in-memory ViewCatalog + SupportsNamespaces implementation for testing.

  • CreateViewV2Suite: tests for basic create, OR REPLACE, IF NOT EXISTS, duplicate-view error, non-ViewCatalog error, and comment/ property propagation.

Why are the changes needed?

CREATE VIEW AS SELECT only worked with the V1/session catalog. When targeting a V2 catalog that implements ViewCatalog, Spark threw an error despite the ViewCatalog API (createView, replaceView, ViewInfo) already being fully in place. The missing piece was the execution plumbing from SQL parsing through to that API.

Does this PR introduce any user-facing change?

Yes. CREATE VIEW AS SELECT supports V2 ViewCatalog after this PR.

How was this patch tested?

Unit test

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

Generated-by: Claude Sonnet 4.6

viirya and others added 3 commits March 26, 2026 23:08
Route CREATE VIEW and DROP VIEW through the V2 execution path when the
target catalog implements ViewCatalog.

**Changes:**

- `ResolveSessionCatalog`: allow `CreateView` and `DropView` to fall
  through (instead of throwing) when the target catalog implements
  `ViewCatalog`; non-`ViewCatalog` V2 catalogs still throw the
  capability error.

- `DataSourceV2Strategy`: add routing cases for `CreateView` and
  `DropView` targeting a `ViewCatalog`. For CREATE VIEW, the aliased
  schema and current catalog/namespace are pre-computed from the
  session and passed to the exec.

- `CreateViewExec`: new `LeafV2CommandExec` that validates the view
  body (no temp-object references, no auto-generated aliases) and calls
  `ViewCatalog.createView` / `replaceView` with a `ViewInfo` built from
  the analyzed query schema, SQL text, and user properties.

- `DropViewExec`: new `LeafV2CommandExec` that calls
  `ViewCatalog.dropView`.

- `InMemoryViewCatalog`: in-memory `ViewCatalog` + `SupportsNamespaces`
  implementation for testing.

- `CreateViewV2Suite`: tests for basic create, OR REPLACE, IF NOT
  EXISTS, duplicate-view error, non-ViewCatalog error, and comment/
  property propagation.

Known limitation (TODO): temp-view reference validation is skipped in
the V2 exec path because the optimizer inlines view bodies before
`CreateViewExec.run()`. A follow-up should prevent optimizer traversal
into `CreateView.query` for V2 targets (similar to `AnalysisOnlyCommand`
in the V1 path).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…operties

- Expose ViewHelper.viewSchemaModeToProps so CreateViewExec can call it;
  WITH SCHEMA BINDING / EVOLUTION is now stored as view.schemaMode in ViewInfo.
- Capture active SQL configs (e.g. ANSI mode, session timezone) at creation
  time via ViewHelper.sqlConfigsToProps, mirroring V1 generateViewProperties.
- Add TODO comment documenting the referred-temp-object-names gap.
- Add tests for schema mode and SQL config capture in CreateViewV2Suite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…V2View

Introduce CreateV2View, a new logical plan node that extends
AnalysisOnlyCommand, to replace the CreateView fall-through path when
targeting a ViewCatalog.

- AnalysisOnlyCommand hides the view query from the optimizer once
  analyzed, so View(isTempView=true) nodes remain intact and can be
  detected by verifyTemporaryObjectsNotExists.
- markAsAnalyzed captures referredTempFunctionNames from AnalysisContext,
  which is now threaded through to CreateViewExec and passed to
  verifyTemporaryObjectsNotExists.
- ResolveSessionCatalog produces CreateV2View (instead of falling through)
  when CreateView targets a ViewCatalog.
- DataSourceV2Strategy matches on CreateV2View instead of CreateView.
- Un-ignore the temp-view rejection test in CreateViewV2Suite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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