-
Notifications
You must be signed in to change notification settings - Fork 58
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
feat: replace internal dictionaries with protos in gapic calls #875
Changes from all commits
7aad7a0
c68e410
de89f92
57d65ef
ead484a
5197d13
dc596df
5bbae6c
fcfcc1d
d98cf46
a0c8834
9300ec5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,12 @@ | |
from abc import ABC, abstractmethod | ||
from sys import getsizeof | ||
|
||
import google.cloud.bigtable_v2.types.bigtable as types_pb | ||
import google.cloud.bigtable_v2.types.data as data_pb | ||
|
||
from google.cloud.bigtable.data.read_modify_write_rules import _MAX_INCREMENT_VALUE | ||
|
||
|
||
# special value for SetCell mutation timestamps. If set, server will assign a timestamp | ||
_SERVER_SIDE_TIMESTAMP = -1 | ||
|
||
|
@@ -36,6 +39,12 @@ class Mutation(ABC): | |
def _to_dict(self) -> dict[str, Any]: | ||
raise NotImplementedError | ||
|
||
def _to_pb(self) -> data_pb.Mutation: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to double store all of the attributes? Can't we store all of the attributes in the proto directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the main downside is we'd need a lot more boilerplate setters/getters (we lose the simplicity of the dataclasses). And marshaling to/from the protos is more expensive, but I guess that should'nt be too much of an issue here. I see this is how we handled it in the ReadRowsQuery class, which is more complicated than these would be. What do you think of making these immutable? That would simplify the setters/getters, and then we wouldn't have to worry about making a static copy before starting a mutate_rows operation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think so. We do use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally the logic for converting from models to protos for the test proxy is self contained in the proxy. A side goal of test proxy was to be a rosetta stone for expressing the same concepts across every cleint impl There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I dont think you need to worry about someone mutating the model after passing it to the proxy...I dont think you need to be that defensive in your code |
||
""" | ||
Convert the mutation to protobuf | ||
""" | ||
return data_pb.Mutation(**self._to_dict()) | ||
|
||
def is_idempotent(self) -> bool: | ||
""" | ||
Check if the mutation is idempotent | ||
|
@@ -221,6 +230,12 @@ def _to_dict(self) -> dict[str, Any]: | |
"mutations": [mutation._to_dict() for mutation in self.mutations], | ||
} | ||
|
||
def _to_pb(self) -> types_pb.MutateRowsRequest.Entry: | ||
return types_pb.MutateRowsRequest.Entry( | ||
row_key=self.row_key, | ||
mutations=[mutation._to_pb() for mutation in self.mutations], | ||
) | ||
|
||
def is_idempotent(self) -> bool: | ||
"""Check if the mutation is idempotent""" | ||
return all(mutation.is_idempotent() for mutation in self.mutations) | ||
|
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.
If we make the mutation classes immutable, we can simplify this
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.
I think making each individual mutation (ie SetCell, DeleteCell, etc) is a great idea
Howevr I dont think you can make the collection of mutations immutable (ie RowMutationEntry)