Skip to content

feat(bigtable): support materialized views in the data client#17676

Open
axyjo wants to merge 2 commits into
googleapis:mainfrom
axyjo:axyjo-add-materialized-view-data-api-target
Open

feat(bigtable): support materialized views in the data client#17676
axyjo wants to merge 2 commits into
googleapis:mainfrom
axyjo:axyjo-add-materialized-view-data-api-target

Conversation

@axyjo

@axyjo axyjo commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds materialized view support to the Bigtable data client, alongside the existing Table and AuthorizedView surfaces:

  • New MaterializedView / MaterializedViewAsync classes (subclasses of _DataApiTarget) and a client.get_materialized_view(instance_id, materialized_view_id) factory. Reads (read_rows*, sample_row_keys, row_exists) route requests via the materialized_view_name field.
  • Materialized views are read-only in the Bigtable API — the mutation RPCs have no materialized_view_name field — so mutate_row, bulk_mutate_rows, check_and_mutate_row, read_modify_write_row, and mutations_batcher are overridden to raise NotImplementedError immediately instead of failing with an opaque proto error (or, for the batcher, failing later in a background flush).
  • Since materialized views are instance-scoped and have no backing table, table identity (table_id/table_name) moves from the shared _DataApiTarget base class into the Table and AuthorizedView subclasses. Public constructor signatures are unchanged.
  • Sync surfaces regenerated via nox -s generate_sync; docs pages added for both new classes.

Test plan

  • Unit tests: new TestMaterializedView suites (async + generated sync) cover construction, routing metadata (name=<instance path> header), factory passthrough, context-manager use, and the mutation-method rejection; get_materialized_view added to the existing API-surface parametrizations
  • Full tests/unit suite passes locally (5394 passed)
  • Manually exercised against a local gRPC server: ReadRows/SampleRowKeys requests carry materialized_view_name (not table_name), rows are returned through the public API, and Table/AuthorizedView behavior is unchanged
  • CI (docs build, lint, sync-up-to-date check across supported Python versions)

Adds a MaterializedView class (async and sync) to the Bigtable data
client, alongside Table and AuthorizedView, plus a
client.get_materialized_view() factory. Materialized views are
instance-scoped and read-only: read_rows and sample_row_keys route
requests via materialized_view_name, while mutation methods raise
NotImplementedError since the mutation RPCs cannot target a
materialized view.

To support targets without a backing table, table identity
(table_id/table_name) moves from the shared _DataApiTarget base class
into the Table and AuthorizedView subclasses.
@axyjo axyjo requested a review from a team as a code owner July 8, 2026 21:23

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for read-only Materialized Views in both synchronous and asynchronous Bigtable data clients, including the necessary client methods, documentation, and unit tests. Feedback highlights a missing @property decorator on the abstract _request_path method in _DataApiTargetAsync for consistency, and identifies a bug in the async unit tests where non-iterable return values from read_row and row_exists are incorrectly subjected to async iteration, which silently swallows errors.

…view metadata test

read_row, row_exists, and the other non-streaming methods return concrete
values; async-iterating them raised a TypeError that the surrounding
except block silently swallowed, which could mask real errors.
@mutianf

mutianf commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for read-only materialized views in the Bigtable data client by adding the MaterializedView and MaterializedViewAsync classes, along with corresponding client methods, documentation, and unit tests. To accommodate this, the base classes _DataApiTarget and _DataApiTargetAsync were refactored to decouple table-specific attributes. Feedback on the changes identifies that the abstract method _request_path in _DataApiTargetAsync is missing the @property decorator, which should be added to ensure consistency with its subclasses and its synchronous counterpart.

Comment on lines 1128 to 1129
@abc.abstractmethod
def _request_path(self) -> dict[str, str]:

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.

medium

In _DataApiTargetAsync, the abstract method _request_path is missing the @property decorator. All of its subclasses (TableAsync, AuthorizedViewAsync, and MaterializedViewAsync) implement _request_path as a property, and the sync counterpart _DataApiTarget also defines it as a property. Adding @property here ensures consistency, prevents potential static analysis/type checking warnings, and matches the subclass implementations.

    @property
    @abc.abstractmethod
    def _request_path(self) -> dict[str, str]:

@mutianf mutianf 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.

Lgtm but we should add a systest (in a follow up PR).

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