Skip to content

feat: support row_range in sample_row_keys method#17330

Open
anvitTawar wants to merge 5 commits into
googleapis:mainfrom
anvitTawar:sample-row-keys-row-range
Open

feat: support row_range in sample_row_keys method#17330
anvitTawar wants to merge 5 commits into
googleapis:mainfrom
anvitTawar:sample-row-keys-row-range

Conversation

@anvitTawar
Copy link
Copy Markdown

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #17329

- In Table.sample_row_keys, updated the docstring to clarify that the end key of the provided row range is always returned as the last sample (or empty string if no range is specified), and updated the offset_bytes description to specify it includes preceding rows but after the last sample before the range.
- In async and sync unit tests, updated the mocked SampleRowKeys stream responses to use realistic keys falling inside the RowRange bounds (e.g. b"a_key1" and b"b"), and updated the key/length assertions accordingly.
- Reverted manual GAPIC type patches to let OwlBot/Librarian auto-patching handle the API class fields natively upon proto submission.

TAG=agy
CONV=6cea44b5-6adb-45c6-b8c8-58b37f95584c
@anvitTawar anvitTawar requested a review from a team as a code owner June 1, 2026 21:43
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 adds support for a row_range parameter in the sample_row_keys method across the asynchronous, synchronous autogenerated, and legacy Bigtable clients, allowing users to restrict sampled row keys to a specific range. It also updates the test proxy handlers and adds corresponding unit tests. The review feedback highlights a potential bug in client_handler_legacy.py where an empty byte string b"" could be incorrectly treated as falsy when resolving range keys. Additionally, it suggests encapsulating None checks within helper functions and using explicit is not None checks instead of truthiness checks for optional parameters.

Comment on lines +253 to +256
row_range = None
if "row_range" in request:
from google.cloud.bigtable.data.read_rows_query import RowRange
row_range = RowRange._from_dict(request["row_range"])
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

When processing optional parameters with a helper function, prefer placing the null or None check within the function body rather than at the call site to simplify the calling code and improve encapsulation. Instead of checking if row_range is in the request at the call site, pass the optional value directly to RowRange._from_dict and handle the None check inside that helper function.

        from google.cloud.bigtable.data.read_rows_query import RowRange
        row_range = RowRange._from_dict(request.get("row_range"))
References
  1. When processing optional parameters with a helper function, prefer placing the null or None check within the function body rather than at the call site to simplify the calling code and improve encapsulation.

Comment on lines +190 to +194
row_range = None
if "row_range" in request:
from google.cloud.bigtable.data.read_rows_query import RowRange

row_range = RowRange._from_dict(request["row_range"])
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

When processing optional parameters with a helper function, prefer placing the null or None check within the function body rather than at the call site to simplify the calling code and improve encapsulation. Instead of checking if row_range is in the request at the call site, pass the optional value directly to RowRange._from_dict and handle the None check inside that helper function.

        from google.cloud.bigtable.data.read_rows_query import RowRange
        row_range = RowRange._from_dict(request.get("row_range"))
References
  1. When processing optional parameters with a helper function, prefer placing the null or None check within the function body rather than at the call site to simplify the calling code and improve encapsulation.

Comment thread packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py Outdated
Comment thread packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py Outdated
…ler_legacy.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@anvitTawar anvitTawar changed the title Sample row keys row range feat: support row_range in sample_row_keys method Jun 1, 2026
anvitTawar and others added 2 commits June 1, 2026 17:50
…nc/client.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…c_autogen/client.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.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.

Implement specifying a row_range for sample_row_keys()

2 participants