Skip to content

Commit f3a1ef0

Browse files
authored
Add Queryable Encryption V2 support (#1445)
- Remove references to "rangePreview" in Javadoc. - Add tests for legacy specifications. - Update prose test to incorporate "Range" algorithm. JAVA-5321
1 parent ab72460 commit f3a1ef0

File tree

68 files changed

+3662
-2687
lines changed

Some content is hidden

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

68 files changed

+3662
-2687
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ext {
5555
zstdVersion = '1.5.5-3'
5656
awsSdkV2Version = '2.18.9'
5757
awsSdkV1Version = '1.12.337'
58-
mongoCryptVersion = '1.10.0-SNAPSHOT'
58+
mongoCryptVersion = '1.11.0-SNAPSHOT'
5959
projectReactorVersion = '2022.0.0'
6060
junitBomVersion = '5.10.2'
6161
logbackVersion = '1.3.14'

driver-core/src/main/com/mongodb/client/model/vault/EncryptOptions.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ public EncryptOptions(final String algorithm) {
5252
* <li>AEAD_AES_256_CBC_HMAC_SHA_512-Random</li>
5353
* <li>Indexed</li>
5454
* <li>Unindexed</li>
55-
* <li>RangePreview</li>
55+
* <li>Range</li>
5656
* </ul>
57+
* Note: The Range algorithm is unstable. It is subject to breaking changes.
5758
*
5859
* @return the encryption algorithm
5960
*/
@@ -116,8 +117,8 @@ public EncryptOptions keyAltName(final String keyAltName) {
116117
/**
117118
* The contention factor.
118119
*
119-
* <p>It is an error to set contentionFactor when algorithm is not "Indexed" or "RangePreview".
120-
* <p>Note: The Range algorithm is experimental only. It is not intended for public use. It is subject to breaking changes.</p>
120+
* <p>It is an error to set contentionFactor when algorithm is not "Indexed" or "Range".
121+
* <p>Note: The Range algorithm is unstable. It is subject to breaking changes.</p>
121122
* @param contentionFactor the contention factor, which must be {@code >= 0} or null.
122123
* @return this
123124
* @since 4.7
@@ -144,9 +145,9 @@ public Long getContentionFactor() {
144145
/**
145146
* The QueryType.
146147
*
147-
* <p>Currently, we support only "equality" or "RangePreview" queryType.</p>
148-
* <p>It is an error to set queryType when the algorithm is not "Indexed" or "RangePreview".</p>
149-
* <p>Note: The Range algorithm is experimental only. It is not intended for public use. It is subject to breaking changes.</p>
148+
* <p>Currently, we support only "equality" or "range" queryType.</p>
149+
* <p>It is an error to set queryType when the algorithm is not "Indexed" or "Range".</p>
150+
* <p>Note: The Range algorithm is unstable. It is subject to breaking changes.</p>
150151
* @param queryType the query type
151152
* @return this
152153
* @since 4.7
@@ -160,7 +161,8 @@ public EncryptOptions queryType(@Nullable final String queryType) {
160161
/**
161162
* Gets the QueryType.
162163
*
163-
* <p>Currently, we support only "equality" or "RangePreview" queryType.</p>
164+
* <p>Currently, we support only "equality" or "range" queryType.</p>
165+
* <p>Note: The Range algorithm is unstable. It is subject to breaking changes.
164166
* @see #queryType(String)
165167
* @return the queryType or null
166168
* @since 4.7
@@ -174,12 +176,12 @@ public String getQueryType() {
174176
/**
175177
* The RangeOptions
176178
*
177-
* <p>It is an error to set RangeOptions when the algorithm is not "RangePreview".
178-
* <p>Note: The Range algorithm is experimental only. It is not intended for public use. It is subject to breaking changes.
179+
* <p>It is an error to set RangeOptions when the algorithm is not "Range".
180+
* <p>Note: The Range algorithm is unstable. It is subject to breaking changes.
179181
* @param rangeOptions the range options
180182
* @return this
181183
* @since 4.9
182-
* @mongodb.server.release 6.2
184+
* @mongodb.server.release 8.0
183185
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
184186
*/
185187
@Beta(Reason.SERVER)
@@ -192,7 +194,7 @@ public EncryptOptions rangeOptions(@Nullable final RangeOptions rangeOptions) {
192194
* Gets the RangeOptions
193195
* @return the range options or null if not set
194196
* @since 4.9
195-
* @mongodb.server.release 6.2
197+
* @mongodb.server.release 8.0
196198
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
197199
*/
198200
@Nullable

driver-core/src/main/com/mongodb/client/model/vault/RangeOptions.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
import org.bson.BsonValue;
2323

2424
/**
25-
* Range options specifies index options for a Queryable Encryption field supporting "rangePreview" queries.
25+
* Range options specifies index options for a Queryable Encryption field supporting "range" queries.
2626
*
2727
* <p>{@code min}, {@code max}, {@code sparsity}, and {@code precision} must match the values set in the {@code encryptedFields}
2828
* of the destination collection.
2929
*
3030
* <p>For {@code double} and {@code decimal128}, {@code min}/{@code max}/{@code precision} must all be set, or all be unset.
3131
*
32-
* <p>Note: The Range algorithm is experimental only. It is not intended for public use. It is subject to breaking changes.
32+
* <p>Note: The "Range" algorithm is unstable. It is subject to breaking changes.
3333
* @since 4.9
3434
* @mongodb.server.release 6.2
3535
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
@@ -39,6 +39,7 @@ public class RangeOptions {
3939

4040
private BsonValue min;
4141
private BsonValue max;
42+
private Integer trimFactor;
4243
private Long sparsity;
4344
private Integer precision;
4445

@@ -76,6 +77,26 @@ public RangeOptions max(@Nullable final BsonValue max) {
7677
return this;
7778
}
7879

80+
/**
81+
* @return the trim factor value if set
82+
* @since 5.2
83+
*/
84+
public Integer getTrimFactor() {
85+
return trimFactor;
86+
}
87+
88+
/**
89+
* Set the number of top-level edges stored per record by setting a trim factor, reducing write conflicts during simultaneous inserts
90+
* and optimizing queries by excluding seldom-used high-level edges.
91+
* @param trimFactor the trim factor
92+
* @return this
93+
* @since 5.2
94+
*/
95+
public RangeOptions setTrimFactor(final Integer trimFactor) {
96+
this.trimFactor = trimFactor;
97+
return this;
98+
}
99+
79100
/**
80101
* @return the maximum value if set
81102
*/
@@ -125,6 +146,7 @@ public String toString() {
125146
return "RangeOptions{"
126147
+ "min=" + min
127148
+ ", max=" + max
149+
+ ", trimFactor=" + trimFactor
128150
+ ", sparsity=" + sparsity
129151
+ ", precision=" + precision
130152
+ '}';

driver-core/src/main/com/mongodb/internal/client/vault/EncryptOptionsHelper.java

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public static MongoExplicitEncryptOptions asMongoExplicitEncryptOptions(final En
6060
if (sparsity != null) {
6161
rangeOptionsBsonDocument.put("sparsity", new BsonInt64(sparsity));
6262
}
63+
Integer trimFactor = rangeOptions.getTrimFactor();
64+
if (trimFactor != null) {
65+
rangeOptionsBsonDocument.put("trimFactor", new BsonInt32(trimFactor));
66+
}
6367
Integer precision = rangeOptions.getPrecision();
6468
if (precision != null) {
6569
rangeOptionsBsonDocument.put("precision", new BsonInt32(precision));

driver-core/src/test/resources/client-side-encryption-data/encryptedFields-Range-Date.json

-33
This file was deleted.

driver-core/src/test/resources/client-side-encryption-data/encryptedFields-Range-Decimal.json

-23
This file was deleted.

driver-core/src/test/resources/client-side-encryption-data/encryptedFields-Range-DecimalPrecision.json

-32
This file was deleted.

driver-core/src/test/resources/client-side-encryption-data/encryptedFields-Range-Double.json

-23
This file was deleted.

driver-core/src/test/resources/client-side-encryption-data/encryptedFields-Range-DoublePrecision.json

-32
This file was deleted.

driver-core/src/test/resources/client-side-encryption-data/encryptedFields-Range-Int.json

-29
This file was deleted.

driver-core/src/test/resources/client-side-encryption-data/encryptedFields-Range-Long.json

-29
This file was deleted.

0 commit comments

Comments
 (0)