-
Notifications
You must be signed in to change notification settings - Fork 246
DRIVERS-3123 Relaxes requirement on reads of the ignored bits of PACKED_BIT vectors. #1812
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
Changes from all commits
c13784b
2d9565d
f270a25
d7ccb03
ea265ea
87f75e1
9461d62
6cb2457
cae0cc7
4fdbf89
addd597
3431dc4
ed562b3
8d01080
d8db3e1
410ef9c
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 | ||||
---|---|---|---|---|---|---|
|
@@ -55,6 +55,66 @@ MUST assert that the input float array is the same after encoding and decoding. | |||||
- if the canonical_bson field is present, raise an exception when attempting to deserialize it into the corresponding | ||||||
numeric values, as the field contains corrupted data. | ||||||
|
||||||
## Prose Tests | ||||||
|
||||||
### Treatment of non-zero ignored bits | ||||||
|
||||||
All drivers MUST test encoding and decoding behavior according to their design and version. For drivers that haven't | ||||||
been completed, raise exceptions in both cases. For those that have, update to this behavior according to semantic | ||||||
versioning rules, and update tests accordingly. | ||||||
|
||||||
In both cases, [255], a single byte PACKED_BIT vector of length 1 (hence padding of 7) provides a good example to use, | ||||||
as all of its bits are ones. | ||||||
|
||||||
#### 1. Encoding | ||||||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
kevinAlbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- Test encoding with non-zero ignored bits. Use the driver API that validates vector metadata. | ||||||
- If the driver validates ignored bits are zero (preferred), expect an error. Otherwise expect the ignored bits are | ||||||
preserved. | ||||||
|
||||||
```python | ||||||
with pytest.raises(ValueError): | ||||||
Binary.from_vector([0b11111111], BinaryVectorDtype.PACKED_BIT, padding=7) | ||||||
``` | ||||||
|
||||||
### 2. Decoding | ||||||
|
||||||
- Test the behaviour of your driver when one attempts to decode from binary to vector. | ||||||
kevinAlbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- e.g. As of pymongo 4.14, a warning is raised. From 5.0, it will be an exception. | ||||||
|
||||||
```python | ||||||
b = Binary(b'\x10\x07\xff', subtype=9) | ||||||
with pytest.warns(): | ||||||
Binary.as_vector(b) | ||||||
``` | ||||||
|
||||||
Drivers MAY skip this test if they choose not to implement a `Vector` type. | ||||||
|
||||||
### 3. Comparison | ||||||
|
||||||
Once we can guarantee that all ignored bits are non-zero, then equality can be tested on the binary subtype. Until then, | ||||||
equality is ambiguous, and depends on whether one compares by bits (uint1), or uint8. Drivers SHOULD test equality | ||||||
behavior according to their design and version. | ||||||
|
||||||
For example, in `pymongo < 5.0`, we define equality of a BinaryVector by matching padding, dtype, and integer. This | ||||||
means that two single bit vectors in which 7 bits are ignored do not match unless all bits match. This mirrors what the | ||||||
server does. | ||||||
|
||||||
```python | ||||||
b1 = Binary.from_vector([0b10000000], BinaryVectorDtype.PACKED_BIT, padding=7) | ||||||
kevinAlbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
assert b1 == Binary(b'\x10\x07\x80', subtype=9) # This is effectively a roundtrip. | ||||||
v1 = Binary.as_vector(b1) | ||||||
|
||||||
b2 = Binary.from_vector([0b11111111], BinaryVectorDtype.PACKED_BIT, padding=7) | ||||||
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 expect b1 = Binary(b'\x10\x07\x80', subtype=9)
b2 = Binary(b'\x10\x07\xff', subtype=9) 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. Tracked in #1819. |
||||||
assert b2 == Binary(b'\x10\x07\xff', subtype=9) | ||||||
v2 = Binary.as_vector(b2) | ||||||
|
||||||
assert b1 != b2 # Unequal at naive Binary level | ||||||
assert v2 != v1 # Also chosen to be unequal at BinaryVector level as [255] != [128] | ||||||
``` | ||||||
|
||||||
Drivers MAY skip this test if they choose not to implement a `Vector` type. | ||||||
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.
Suggested change
Suggest permitting drivers skip this test if the 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. Tracked in #1819. |
||||||
|
||||||
## FAQ | ||||||
|
||||||
- What MongoDB Server version does this apply to? | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.