Skip to content

Commit 76f1221

Browse files
authored
PYTHON-4206 - QE Range Protocol V2 (mongodb#1670)
1 parent 8c35d1e commit 76f1221

File tree

60 files changed

+1445
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1445
-727
lines changed

pymongo/asynchronous/encryption.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,10 @@ class Algorithm(str, enum.Enum):
456456
457457
.. versionadded:: 4.2
458458
"""
459-
RANGEPREVIEW = "RangePreview"
460-
"""RangePreview.
459+
RANGE = "Range"
460+
"""Range.
461461
462-
.. note:: Support for Range queries is in beta.
463-
Backwards-breaking changes may be made before the final release.
464-
465-
.. versionadded:: 4.4
462+
.. versionadded:: 4.8
466463
"""
467464

468465

@@ -475,11 +472,9 @@ class QueryType(str, enum.Enum):
475472
EQUALITY = "equality"
476473
"""Used to encrypt a value for an equality query."""
477474

478-
RANGEPREVIEW = "rangePreview"
475+
RANGE = "range"
479476
"""Used to encrypt a value for a range query.
480477
481-
.. note:: Support for Range queries is in beta.
482-
Backwards-breaking changes may be made before the final release.
483478
"""
484479

485480

@@ -836,10 +831,14 @@ async def encrypt(
836831
when the algorithm is :attr:`Algorithm.INDEXED`. An integer value
837832
*must* be given when the :attr:`Algorithm.INDEXED` algorithm is
838833
used.
839-
:param range_opts: Experimental only, not intended for public use.
834+
:param range_opts: Index options for `range` queries. See
835+
:class:`RangeOpts` for some valid options.
840836
841837
:return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6.
842838
839+
.. versionchanged:: 4.8
840+
Added the `range_opts` parameter.
841+
843842
.. versionchanged:: 4.7
844843
``key_id`` can now be passed in as a :class:`uuid.UUID`.
845844
@@ -888,10 +887,14 @@ async def encrypt_expression(
888887
when the algorithm is :attr:`Algorithm.INDEXED`. An integer value
889888
*must* be given when the :attr:`Algorithm.INDEXED` algorithm is
890889
used.
891-
:param range_opts: Experimental only, not intended for public use.
890+
:param range_opts: Index options for `range` queries. See
891+
:class:`RangeOpts` for some valid options.
892892
893893
:return: The encrypted expression, a :class:`~bson.RawBSONDocument`.
894894
895+
.. versionchanged:: 4.8
896+
Added the `range_opts` parameter.
897+
895898
.. versionchanged:: 4.7
896899
``key_id`` can now be passed in as a :class:`uuid.UUID`.
897900

pymongo/asynchronous/encryption_options.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,20 @@ def __init__(
231231

232232

233233
class RangeOpts:
234-
"""Options to configure encrypted queries using the rangePreview algorithm."""
234+
"""Options to configure encrypted queries using the range algorithm."""
235235

236236
def __init__(
237237
self,
238238
sparsity: int,
239+
trim_factor: int,
239240
min: Optional[Any] = None,
240241
max: Optional[Any] = None,
241242
precision: Optional[int] = None,
242243
) -> None:
243-
"""Options to configure encrypted queries using the rangePreview algorithm.
244-
245-
.. note:: This feature is experimental only, and not intended for public use.
244+
"""Options to configure encrypted queries using the range algorithm.
246245
247246
:param sparsity: An integer.
247+
:param trim_factor: An integer.
248248
:param min: A BSON scalar value corresponding to the type being queried.
249249
:param max: A BSON scalar value corresponding to the type being queried.
250250
:param precision: An integer, may only be set for double or decimal128 types.
@@ -254,13 +254,15 @@ def __init__(
254254
self.min = min
255255
self.max = max
256256
self.sparsity = sparsity
257+
self.trim_factor = trim_factor
257258
self.precision = precision
258259

259260
@property
260261
def document(self) -> dict[str, Any]:
261262
doc = {}
262263
for k, v in [
263264
("sparsity", int64.Int64(self.sparsity)),
265+
("trimFactor", self.trim_factor),
264266
("precision", self.precision),
265267
("min", self.min),
266268
("max", self.max),

pymongo/synchronous/encryption.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,10 @@ class Algorithm(str, enum.Enum):
454454
455455
.. versionadded:: 4.2
456456
"""
457-
RANGEPREVIEW = "RangePreview"
458-
"""RangePreview.
457+
RANGE = "Range"
458+
"""Range.
459459
460-
.. note:: Support for Range queries is in beta.
461-
Backwards-breaking changes may be made before the final release.
462-
463-
.. versionadded:: 4.4
460+
.. versionadded:: 4.8
464461
"""
465462

466463

@@ -473,11 +470,9 @@ class QueryType(str, enum.Enum):
473470
EQUALITY = "equality"
474471
"""Used to encrypt a value for an equality query."""
475472

476-
RANGEPREVIEW = "rangePreview"
473+
RANGE = "range"
477474
"""Used to encrypt a value for a range query.
478475
479-
.. note:: Support for Range queries is in beta.
480-
Backwards-breaking changes may be made before the final release.
481476
"""
482477

483478

@@ -834,10 +829,14 @@ def encrypt(
834829
when the algorithm is :attr:`Algorithm.INDEXED`. An integer value
835830
*must* be given when the :attr:`Algorithm.INDEXED` algorithm is
836831
used.
837-
:param range_opts: Experimental only, not intended for public use.
832+
:param range_opts: Index options for `range` queries. See
833+
:class:`RangeOpts` for some valid options.
838834
839835
:return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6.
840836
837+
.. versionchanged:: 4.8
838+
Added the `range_opts` parameter.
839+
841840
.. versionchanged:: 4.7
842841
``key_id`` can now be passed in as a :class:`uuid.UUID`.
843842
@@ -886,10 +885,14 @@ def encrypt_expression(
886885
when the algorithm is :attr:`Algorithm.INDEXED`. An integer value
887886
*must* be given when the :attr:`Algorithm.INDEXED` algorithm is
888887
used.
889-
:param range_opts: Experimental only, not intended for public use.
888+
:param range_opts: Index options for `range` queries. See
889+
:class:`RangeOpts` for some valid options.
890890
891891
:return: The encrypted expression, a :class:`~bson.RawBSONDocument`.
892892
893+
.. versionchanged:: 4.8
894+
Added the `range_opts` parameter.
895+
893896
.. versionchanged:: 4.7
894897
``key_id`` can now be passed in as a :class:`uuid.UUID`.
895898

pymongo/synchronous/encryption_options.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,20 @@ def __init__(
231231

232232

233233
class RangeOpts:
234-
"""Options to configure encrypted queries using the rangePreview algorithm."""
234+
"""Options to configure encrypted queries using the range algorithm."""
235235

236236
def __init__(
237237
self,
238238
sparsity: int,
239+
trim_factor: int,
239240
min: Optional[Any] = None,
240241
max: Optional[Any] = None,
241242
precision: Optional[int] = None,
242243
) -> None:
243-
"""Options to configure encrypted queries using the rangePreview algorithm.
244-
245-
.. note:: This feature is experimental only, and not intended for public use.
244+
"""Options to configure encrypted queries using the range algorithm.
246245
247246
:param sparsity: An integer.
247+
:param trim_factor: An integer.
248248
:param min: A BSON scalar value corresponding to the type being queried.
249249
:param max: A BSON scalar value corresponding to the type being queried.
250250
:param precision: An integer, may only be set for double or decimal128 types.
@@ -254,13 +254,15 @@ def __init__(
254254
self.min = min
255255
self.max = max
256256
self.sparsity = sparsity
257+
self.trim_factor = trim_factor
257258
self.precision = precision
258259

259260
@property
260261
def document(self) -> dict[str, Any]:
261262
doc = {}
262263
for k, v in [
263264
("sparsity", int64.Int64(self.sparsity)),
265+
("trimFactor", self.trim_factor),
264266
("precision", self.precision),
265267
("min", self.min),
266268
("max", self.max),

test/client-side-encryption/etc/data/range-encryptedFields-Date.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"path": "encryptedDate",
1111
"bsonType": "date",
1212
"queries": {
13-
"queryType": "rangePreview",
13+
"queryType": "range",
1414
"contention": {
1515
"$numberLong": "0"
1616
},
17+
"trimFactor": {
18+
"$numberInt": "1"
19+
},
1720
"sparsity": {
1821
"$numberLong": "1"
1922
},
@@ -30,4 +33,4 @@
3033
}
3134
}
3235
]
33-
}
36+
}

test/client-side-encryption/etc/data/range-encryptedFields-DecimalNoPrecision.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
"path": "encryptedDecimalNoPrecision",
1111
"bsonType": "decimal",
1212
"queries": {
13-
"queryType": "rangePreview",
13+
"queryType": "range",
1414
"contention": {
1515
"$numberLong": "0"
1616
},
17+
"trimFactor": {
18+
"$numberInt": "1"
19+
},
1720
"sparsity": {
1821
"$numberLong": "1"
1922
}
2023
}
2124
}
2225
]
23-
}
26+
}

test/client-side-encryption/etc/data/range-encryptedFields-DecimalPrecision.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"path": "encryptedDecimalPrecision",
1111
"bsonType": "decimal",
1212
"queries": {
13-
"queryType": "rangePreview",
13+
"queryType": "range",
1414
"contention": {
1515
"$numberLong": "0"
1616
},
17+
"trimFactor": {
18+
"$numberInt": "1"
19+
},
1720
"sparsity": {
1821
"$numberLong": "1"
1922
},
@@ -29,4 +32,4 @@
2932
}
3033
}
3134
]
32-
}
35+
}

test/client-side-encryption/etc/data/range-encryptedFields-DoubleNoPrecision.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
"path": "encryptedDoubleNoPrecision",
1111
"bsonType": "double",
1212
"queries": {
13-
"queryType": "rangePreview",
13+
"queryType": "range",
1414
"contention": {
1515
"$numberLong": "0"
1616
},
17+
"trimFactor": {
18+
"$numberInt": "1"
19+
},
1720
"sparsity": {
1821
"$numberLong": "1"
1922
}
2023
}
2124
}
2225
]
23-
}
26+
}

test/client-side-encryption/etc/data/range-encryptedFields-DoublePrecision.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"path": "encryptedDoublePrecision",
1111
"bsonType": "double",
1212
"queries": {
13-
"queryType": "rangePreview",
13+
"queryType": "range",
1414
"contention": {
1515
"$numberLong": "0"
1616
},
17+
"trimFactor": {
18+
"$numberInt": "1"
19+
},
1720
"sparsity": {
1821
"$numberLong": "1"
1922
},
@@ -29,4 +32,4 @@
2932
}
3033
}
3134
]
32-
}
35+
}

test/client-side-encryption/etc/data/range-encryptedFields-Int.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"path": "encryptedInt",
1111
"bsonType": "int",
1212
"queries": {
13-
"queryType": "rangePreview",
13+
"queryType": "range",
1414
"contention": {
1515
"$numberLong": "0"
1616
},
17+
"trimFactor": {
18+
"$numberInt": "1"
19+
},
1720
"sparsity": {
1821
"$numberLong": "1"
1922
},
@@ -26,4 +29,4 @@
2629
}
2730
}
2831
]
29-
}
32+
}

0 commit comments

Comments
 (0)