Skip to content

feat(plugin-iceberg): Add ALTER MATERIALIZED VIEW SET PROPERTIES#27806

Draft
tdcmeehan wants to merge 1 commit into
prestodb:masterfrom
tdcmeehan:atmv
Draft

feat(plugin-iceberg): Add ALTER MATERIALIZED VIEW SET PROPERTIES#27806
tdcmeehan wants to merge 1 commit into
prestodb:masterfrom
tdcmeehan:atmv

Conversation

@tdcmeehan
Copy link
Copy Markdown
Contributor

@tdcmeehan tdcmeehan commented May 14, 2026

Description

Adds a new SQL statement, ALTER MATERIALIZED VIEW <name> SET PROPERTIES (...), and implements it for the Iceberg connector. Lets users update stale_read_behavior, staleness_window, and refresh_type on existing Iceberg materialized views. storage_schema and storage_table remain creation-only since they identify the physical storage table. NULL values are rejected (no clearing).

The statement is gated at the engine on legacy_materialized_views=false; legacy mode is rejected before any connector dispatch, preserving prior behavior.

Motivation and Context

Today an Iceberg materialized view's freshness/refresh policy is fixed at creation. Changing it requires dropping and recreating the MV — which also drops the storage table and any cached data. This PR makes those policy properties tunable in place.

Impact

New SQL surface: ALTER MATERIALIZED VIEW name SET PROPERTIES (...).

Connector SPI gains ConnectorMetadata.setMaterializedViewProperties(ConnectorSession, SchemaTableName, Map<String, Object>) with a default that throws NOT_SUPPORTED. Existing connectors are unaffected.

Plumbing mirrors ALTER TABLE ... SET PROPERTIES: SetProperties.Type gains MATERIALIZED_VIEW, and the engine Metadata facade / MetadataManager / its wrappers expose the new method. Access control reuses checkCanSetTableProperties against the MV name.

Test Plan

  • TestSqlParser#testSetProperties covers parsing of the new statement (positive and IF EXISTS cases).
  • TestIcebergMaterializedViewMetadata adds four integration tests: golden-path update, rejection of storage_schema/storage_table, legacy-mode rejection, and missing-MV behavior with/without IF EXISTS.

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

== RELEASE NOTES ==

General Changes
* Add ``ALTER MATERIALIZED VIEW <name> SET PROPERTIES (...)`` SQL statement to update materialized view properties after creation. :pr:`27806`

Iceberg Changes
* Allow updating ``stale_read_behavior``, ``staleness_window``, and ``refresh_type`` on existing materialized views via ``ALTER MATERIALIZED VIEW ... SET PROPERTIES`` (requires ``legacy_materialized_views=false``). :pr:`27806`

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label May 14, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 14, 2026

Reviewer's Guide

Adds end-to-end support for ALTER MATERIALIZED VIEW ... SET PROPERTIES for Iceberg materialized views, including parser/AST support, metadata wiring, Iceberg connector implementation, property serialization, access control, and tests for behavior and failure modes.

Sequence diagram for ALTER MATERIALIZED VIEW SET PROPERTIES flow

sequenceDiagram
    actor Client
    participant Parser as AstBuilder
    participant Task as SetPropertiesTask
    participant MetaMgr as MetadataManager
    participant ConnMeta as IcebergAbstractMetadata
    participant MVProps as IcebergMaterializedViewProperties

    Client->>Parser: visitSetMaterializedViewProperties()
    Parser-->>Client: SetProperties(MATERIALIZED_VIEW)

    Client->>Task: execute(SetProperties)
    Task->>Task: SystemSessionProperties.isLegacyMaterializedViews()
    Task->>MetaMgr: getMaterializedViewPropertyManager().getUserSpecifiedProperties()
    Task->>Task: setMaterializedViewProperties()
    Task->>MetaMgr: setMaterializedViewProperties(Session, QualifiedObjectName, Map)

    MetaMgr->>ConnMeta: setMaterializedViewProperties(ConnectorSession, SchemaTableName, Map)
    ConnMeta->>ConnMeta: getMaterializedView()
    ConnMeta->>MVProps: serializeForUpdate(name, value)
    MVProps-->>ConnMeta: Map.Entry(storageKey, serializedValue)
    ConnMeta->>ConnMeta: updateIcebergViewProperties(ConnectorSession, SchemaTableName, Map)
    ConnMeta-->>MetaMgr: properties updated
    MetaMgr-->>Task: done
    Task-->>Client: ALTER MATERIALIZED VIEW completed
Loading

File-Level Changes

Change Details Files
Introduce structured metadata for Iceberg materialized-view properties and support safe serialization of updatable properties for ALTER MATERIALIZED VIEW SET PROPERTIES.
  • Refactor MV-specific property definitions into a static list of MaterializedViewProperty instances with creation-only vs updatable semantics and storage key/serializer metadata.
  • Add MV_ONLY_PROPERTIES_BY_NAME index for fast lookup of MV properties by name.
  • Implement serializeForUpdate to validate that a property is updatable, reject null (clearing) values, and map logical property names/values to underlying storage keys and serialized strings.
  • Change materializedViewProperties construction to reuse MV_ONLY_PROPERTIES metadata rather than rebuilding the list inline.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergMaterializedViewProperties.java
Implement connector- and engine-level plumbing to set materialized view properties, including enforcement of legacy MV restrictions and existence checks.
  • Extend ConnectorMetadata, Metadata, DelegatingMetadataManager, MetadataManager, StatsRecordingMetadataManager, and ClassLoaderSafeConnectorMetadata with setMaterializedViewProperties, with default NOT_SUPPORTED in SPI and delegating/wrapping implementations elsewhere.
  • Implement IcebergAbstractMetadata.setMaterializedViewProperties to validate MV existence, serialize user properties via IcebergMaterializedViewProperties.serializeForUpdate, and push updates to Iceberg via updateIcebergViewProperties.
  • Update SetPropertiesTask to route MATERIALIZED_VIEW targets through materialized-view property manager, enforce legacy_materialized_views guard, perform existence/IF EXISTS handling, and invoke Metadata.setMaterializedViewProperties with access-control checks.
presto-spi/src/main/java/com/facebook/presto/spi/connector/ConnectorMetadata.java
presto-spi/src/main/java/com/facebook/presto/spi/connector/classloader/ClassLoaderSafeConnectorMetadata.java
presto-main-base/src/main/java/com/facebook/presto/metadata/Metadata.java
presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataManager.java
presto-main-base/src/main/java/com/facebook/presto/metadata/StatsRecordingMetadataManager.java
presto-main-base/src/main/java/com/facebook/presto/metadata/DelegatingMetadataManager.java
presto-main-base/src/main/java/com/facebook/presto/execution/SetPropertiesTask.java
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java
presto-main-base/src/test/java/com/facebook/presto/metadata/AbstractMockMetadata.java
Extend SQL parsing, AST, and formatting to support ALTER MATERIALIZED VIEW ... SET PROPERTIES syntax.
  • Add setMaterializedViewProperties rule to SqlBase.g4 grammar for ALTER MATERIALIZED VIEW (IF EXISTS)? ... SET PROPERTIES.
  • Extend SetProperties.Type enum and SqlFormatter visitSetProperties to distinguish TABLE vs MATERIALIZED_VIEW and emit appropriate ALTER prefix.
  • Add AstBuilder.visitSetMaterializedViewProperties to produce a SetProperties node of type MATERIALIZED_VIEW with parsed properties and IF EXISTS flag.
  • Add parser tests to verify valid/invalid ALTER MATERIALIZED VIEW SET PROPERTIES statements and AST shapes.
presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
presto-parser/src/main/java/com/facebook/presto/sql/parser/AstBuilder.java
presto-parser/src/main/java/com/facebook/presto/sql/SqlFormatter.java
presto-parser/src/main/java/com/facebook/presto/sql/tree/SetProperties.java
presto-parser/src/test/java/com/facebook/presto/sql/parser/TestSqlParser.java
Add Iceberg integration tests covering property updates, error handling, and legacy/IF EXISTS behaviors for ALTER MATERIALIZED VIEW SET PROPERTIES.
  • Add tests that ALTER MATERIALIZED VIEW SET PROPERTIES updates staleness_window and refresh_type while preserving unspecified properties, and that incremental updates leave existing values intact.
  • Add tests asserting that storage_schema and storage_table cannot be updated via SET PROPERTIES and produce the expected error message.
  • Add tests that legacy_materialized_views=true rejects ALTER MATERIALIZED VIEW ... SET PROPERTIES and that missing views behave correctly with and without IF EXISTS.
presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergMaterializedViewMetadata.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@steveburnett
Copy link
Copy Markdown
Contributor

ALTER MATERIALIZED VIEW will need documentation, yes? Probably a new page in https://github.com/prestodb/presto/tree/master/presto-docs/src/main/sphinx/sql.

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

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants