Skip to content

bigtable: add ValueBitmaskFilter for data client#17252

Open
axyjo wants to merge 1 commit into
googleapis:mainfrom
axyjo:axyjo-add-value-bitmask-filter
Open

bigtable: add ValueBitmaskFilter for data client#17252
axyjo wants to merge 1 commit into
googleapis:mainfrom
axyjo:axyjo-add-value-bitmask-filter

Conversation

@axyjo
Copy link
Copy Markdown
Contributor

@axyjo axyjo commented May 26, 2026

Fixes #17255

@axyjo axyjo requested a review from a team as a code owner May 26, 2026 15:23
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 the ValueBitmaskFilter class to support filtering cells by a value bitmask, along with corresponding unit tests. The reviewer pointed out that the _to_dict method incorrectly returns an instantiated protobuf message (data_v2_pb2.ValueBitmask) instead of a plain dictionary, which is inconsistent with other filters and could cause a NameError. Suggestions were provided to return a plain dictionary representation and to update the unit tests accordingly.

Comment on lines +510 to +512
def _to_dict(self) -> dict[str, Any]:
"""Converts the row filter to a dict representation."""
return {"value_bitmask_filter": data_v2_pb2.ValueBitmask(mask=self.mask)}
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.

high

The _to_dict method should return a plain dictionary representation of the filter rather than instantiating a protobuf message (data_v2_pb2.ValueBitmask). Returning a protobuf message inside _to_dict is inconsistent with other filters, can cause NameError if data_v2_pb2 is not imported in this module, and defeats the purpose of a dictionary representation.

Instead, return a nested dictionary {"mask": self.mask} for the value_bitmask_filter key.

Suggested change
def _to_dict(self) -> dict[str, Any]:
"""Converts the row filter to a dict representation."""
return {"value_bitmask_filter": data_v2_pb2.ValueBitmask(mask=self.mask)}
def _to_dict(self) -> dict[str, Any]:
"""Converts the row filter to a dict representation."""
return {"value_bitmask_filter": {"mask": self.mask}}

Comment on lines +1997 to +2003
def test_to_dict(self):
from google.cloud.bigtable_v2.types import data as data_v2_pb2

mask = b"\xaa" * 8
row_filter = self._target_class()(mask)
expected = {"value_bitmask_filter": data_v2_pb2.ValueBitmask(mask=mask)}
assert row_filter._to_dict() == expected
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

Update the test to assert against the plain dictionary representation returned by _to_dict(), which avoids the need to import data_v2_pb2 locally.

Suggested change
def test_to_dict(self):
from google.cloud.bigtable_v2.types import data as data_v2_pb2
mask = b"\xaa" * 8
row_filter = self._target_class()(mask)
expected = {"value_bitmask_filter": data_v2_pb2.ValueBitmask(mask=mask)}
assert row_filter._to_dict() == expected
def test_to_dict(self):
mask = bytes([0xaa]) * 8
row_filter = self._target_class()(mask)
expected = {"value_bitmask_filter": {"mask": mask}}
assert row_filter._to_dict() == expected

@parthea
Copy link
Copy Markdown
Contributor

parthea commented May 26, 2026

Hi @axyjo, Please could you file a new issue (or link to an existing issue) in https://github.com/googleapis/google-cloud-python/issues?

@axyjo
Copy link
Copy Markdown
Contributor Author

axyjo commented May 26, 2026

@parthea Done!

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.

google-cloud-bigtable: ValueBitmaskFilter support for data client

2 participants