-
Notifications
You must be signed in to change notification settings - Fork 61
feat: Rerouted CheckAndMutateRows and ReadModifyWriteRows #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: row-filters
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @gkevinzheng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the internal handling of mutations and read-modify-write operations within the Bigtable client library. By transitioning Row objects to store data client-specific mutation and rule objects, it modernizes the internal API. This change also reroutes conditional and append row commit operations to utilize a new, more centralized data client implementation, leading to a cleaner and more maintainable codebase. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this 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 is a significant and well-executed refactoring. It replaces direct protobuf manipulation with higher-level data objects like Mutation and ReadModifyWriteRule, which greatly improves code clarity and maintainability. Rerouting the commit methods in ConditionalRow and AppendRow to use the _table_impl abstraction is also a good move towards better separation of concerns. The test suite has been updated thoroughly to reflect these changes.
I have one suggestion in tests/unit/v2_client/test_row.py to improve the robustness of a test helper by aligning its logic more closely with the production code it's testing.
Overall, this is an excellent set of changes that enhances the quality of the codebase.
| expected_mutation = DeleteRangeFromColumn(family=column_family_id, qualifier=column) | ||
| if time_range is not None: | ||
| expected_pb.delete_from_column.time_range._pb.CopyFrom(time_range._to_pb()._pb) | ||
| assert row._pb_mutations == [expected_pb] | ||
| time_range_pb = time_range._to_pb() | ||
| if time_range_pb.start_timestamp_micros: | ||
| expected_mutation.start_timestamp_micros = ( | ||
| time_range_pb.start_timestamp_micros | ||
| ) | ||
| if time_range_pb.end_timestamp_micros: | ||
| expected_mutation.end_timestamp_micros = time_range_pb.end_timestamp_micros | ||
| _assert_mutations_equal(row._mutations, [expected_mutation]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to construct expected_mutation is a bit complex and uses time_range._to_pb(), while the production code in _delete_cells uses time_range._to_dict(). This discrepancy could make the test brittle or hide potential bugs if the two methods diverge.
To improve robustness and readability, I suggest aligning the test with the production code's logic. You could extract the timestamps from time_range._to_dict() and then construct the expected_mutation in a single call.
| expected_mutation = DeleteRangeFromColumn(family=column_family_id, qualifier=column) | |
| if time_range is not None: | |
| expected_pb.delete_from_column.time_range._pb.CopyFrom(time_range._to_pb()._pb) | |
| assert row._pb_mutations == [expected_pb] | |
| time_range_pb = time_range._to_pb() | |
| if time_range_pb.start_timestamp_micros: | |
| expected_mutation.start_timestamp_micros = ( | |
| time_range_pb.start_timestamp_micros | |
| ) | |
| if time_range_pb.end_timestamp_micros: | |
| expected_mutation.end_timestamp_micros = time_range_pb.end_timestamp_micros | |
| _assert_mutations_equal(row._mutations, [expected_mutation]) | |
| start_timestamp_micros = None | |
| end_timestamp_micros = None | |
| if time_range is not None: | |
| timestamps = time_range._to_dict() | |
| start_timestamp_micros = timestamps.get("start_timestamp_micros") | |
| end_timestamp_micros = timestamps.get("end_timestamp_micros") | |
| expected_mutation = DeleteRangeFromColumn( | |
| family=column_family_id, | |
| qualifier=column, | |
| start_timestamp_micros=start_timestamp_micros, | |
| end_timestamp_micros=end_timestamp_micros, | |
| ) | |
| _assert_mutations_equal(row._mutations, [expected_mutation]) |
daniel-sanche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple small comments. The only important one is dealing with mutations_list
This is looking really good though, it's great seeing all this code removed!
| mutation_val = data_v2_pb2.Mutation.DeleteFromFamily( | ||
| family_name=column_family_id | ||
| self._get_mutations(state).append( | ||
| mutations.DeleteAllFromFamily(family_to_delete=column_family_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like you aren't using mutations_list, but it's still set at the top of the function (and then accessed at the bottom)
| delete_kwargs["time_range"] = time_range._to_pb() | ||
| timestamps = time_range._to_dict() | ||
| start_timestamp_micros = timestamps.get("start_timestamp_micros") | ||
| end_timestamp_micros = timestamps.get("end_timestamp_micros") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this logic might be a bit cleaner like this:
timerange_dict = time_range._to_dict() if time_range else {}
start_timestamp_micros = timestamps.get("start_timestamp_micros")
end_timestamp_micros = timestamps.get("end_timestamp_micros")
But it's fine as-is too
| for cell in row_response.cells: | ||
| result.setdefault(cell.family, {}).setdefault(cell.qualifier, []).append( | ||
| (cell.value, _datetime_from_microseconds(cell.timestamp_micros)) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is a bit complex for a one-liner
Changes made:
Rowobjects holdMutationandReadModifyWriteRowRuleobjects from the data client rather than raw protos.ConditionalRow.commitandAppendRow.commit(CheckAndMutateRows and ReadModifyWriteRows respectively) to use the data client, or more specifically,self._table._table_implDirectRow._to_mutation_pbsfor retrieving mutations in proto form for the currentMutateRowsimplementation, as well as forDirectRow.get_mutations_size.