Skip to content

bigtable: add ValueBitmaskFilter for data client#17252

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

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

Conversation

@axyjo

@axyjo axyjo commented May 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #17255

@axyjo axyjo requested a review from a team as a code owner May 26, 2026 15: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 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

parthea commented May 26, 2026

Copy link
Copy Markdown
Contributor

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

axyjo commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

@parthea Done!

@mutianf

mutianf commented May 28, 2026

Copy link
Copy Markdown
Contributor

I think the unit test failures are unrelated to this PR, taking a look. Meanwhile @axyjo can you address this review comment #17252 (review)? Thanks.

@daniel-sanche

Copy link
Copy Markdown
Contributor

The test issues should have been fixed on main, but you may need to update your branch

@mutianf

mutianf commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Closing. Created #17567 to address the comments and pulled from main.

@mutianf mutianf closed this Jun 24, 2026
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

4 participants