Repository navigation
fix(bigtable): encode str qualifier in DeleteRangeFromColumn and allow -2**63 in int mutations #18881
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: main
Are you sure you want to change the base?
fix(bigtable): encode str qualifier in DeleteRangeFromColumn and allow -2**63 in int mutations #18881
Changes from all commits
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,10 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| 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 | ||||||||||||||||||
| from google.cloud.bigtable.data.read_modify_write_rules import ( | ||||||||||||||||||
| _MAX_INCREMENT_VALUE, | ||||||||||||||||||
| _MIN_INCREMENT_VALUE, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| # special value for SetCell mutation timestamps. If set, server will assign a timestamp | ||||||||||||||||||
| _SERVER_SIDE_TIMESTAMP = -1 | ||||||||||||||||||
|
|
@@ -169,10 +172,12 @@ def __init__( | |||||||||||||||||
| qualifier = qualifier.encode() if isinstance(qualifier, str) else qualifier | ||||||||||||||||||
| if not isinstance(qualifier, bytes): | ||||||||||||||||||
| raise TypeError("qualifier must be bytes or str") | ||||||||||||||||||
| if isinstance(new_value, bool): | ||||||||||||||||||
| raise TypeError("new_value must be bytes, str, or int") | ||||||||||||||||||
| if isinstance(new_value, str): | ||||||||||||||||||
| new_value = new_value.encode() | ||||||||||||||||||
| elif isinstance(new_value, int): | ||||||||||||||||||
| if abs(new_value) > _MAX_INCREMENT_VALUE: | ||||||||||||||||||
| if not (_MIN_INCREMENT_VALUE <= new_value <= _MAX_INCREMENT_VALUE): | ||||||||||||||||||
| raise ValueError( | ||||||||||||||||||
| "int values must be between -2**63 and 2**63 (64-bit signed int)" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
@@ -223,13 +228,17 @@ class DeleteRangeFromColumn(Mutation): | |||||||||||||||||
| """ | ||||||||||||||||||
|
|
||||||||||||||||||
| family: str | ||||||||||||||||||
| qualifier: bytes | ||||||||||||||||||
| qualifier: bytes | str | ||||||||||||||||||
| # None represents 0 | ||||||||||||||||||
| start_timestamp_micros: int | None = None | ||||||||||||||||||
| # None represents infinity | ||||||||||||||||||
| end_timestamp_micros: int | None = None | ||||||||||||||||||
|
|
||||||||||||||||||
| def __post_init__(self): | ||||||||||||||||||
| if isinstance(self.qualifier, str): | ||||||||||||||||||
| self.qualifier = self.qualifier.encode() | ||||||||||||||||||
| if not isinstance(self.qualifier, bytes): | ||||||||||||||||||
| raise TypeError("qualifier must be bytes or str") | ||||||||||||||||||
| if ( | ||||||||||||||||||
| self.start_timestamp_micros is not None | ||||||||||||||||||
| and self.end_timestamp_micros is not None | ||||||||||||||||||
|
|
@@ -321,11 +330,11 @@ def __init__( | |||||||||||||||||
| qualifier = qualifier.encode() if isinstance(qualifier, str) else qualifier | ||||||||||||||||||
| if not isinstance(qualifier, bytes): | ||||||||||||||||||
| raise TypeError("qualifier must be bytes or str") | ||||||||||||||||||
| if not isinstance(value, int): | ||||||||||||||||||
| if isinstance(value, bool) or not isinstance(value, int): | ||||||||||||||||||
| raise TypeError("value must be int") | ||||||||||||||||||
| if not isinstance(timestamp_micros, int): | ||||||||||||||||||
| if isinstance(timestamp_micros, bool) or not isinstance(timestamp_micros, int): | ||||||||||||||||||
| raise TypeError("timestamp_micros must be int") | ||||||||||||||||||
| if abs(value) > _MAX_INCREMENT_VALUE: | ||||||||||||||||||
| if not (_MIN_INCREMENT_VALUE <= value <= _MAX_INCREMENT_VALUE): | ||||||||||||||||||
| raise ValueError( | ||||||||||||||||||
| "int values must be between -2**63 and 2**63 (64-bit signed int)" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
+337
to
340
Contributor
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. The error message states that integer values must be between
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |||||||||||||||||
| import google.cloud.bigtable_v2.types.data as data_pb | ||||||||||||||||||
|
|
||||||||||||||||||
| # value must fit in 64-bit signed integer | ||||||||||||||||||
| _MIN_INCREMENT_VALUE = -(1 << 63) | ||||||||||||||||||
| _MAX_INCREMENT_VALUE = (1 << 63) - 1 | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -61,9 +62,9 @@ class IncrementRule(ReadModifyWriteRule): | |||||||||||||||||
| """ | ||||||||||||||||||
|
|
||||||||||||||||||
| def __init__(self, family: str, qualifier: bytes | str, increment_amount: int = 1): | ||||||||||||||||||
| if not isinstance(increment_amount, int): | ||||||||||||||||||
| if isinstance(increment_amount, bool) or not isinstance(increment_amount, int): | ||||||||||||||||||
| raise TypeError("increment_amount must be an integer") | ||||||||||||||||||
| if abs(increment_amount) > _MAX_INCREMENT_VALUE: | ||||||||||||||||||
| if not (_MIN_INCREMENT_VALUE <= increment_amount <= _MAX_INCREMENT_VALUE): | ||||||||||||||||||
| raise ValueError( | ||||||||||||||||||
| "increment_amount must be between -2**63 and 2**63 (64-bit signed int)" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
+67
to
70
Contributor
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. The error message states that the increment amount must be between
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
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 error message states that integer values must be between
-2**63and2**63. However, the upper bound2**63is exclusive (the maximum valid 64-bit signed integer is2**63 - 1). To avoid confusion for users hitting the upper boundary, the error message should be updated to specify2**63 - 1as the upper limit.