-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Added range index support for queryable encryption #1069
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7f2277
Added range index support for queryable encryption
rozza f6929a5
Codereview updates
rozza 5c418e5
Update driver-core/src/main/com/mongodb/client/model/vault/RangeOptio…
rozza cede950
Update mongoCryptVersion to 1.7.0
rozza 82de7b2
Update mongoCryptVersion to 1.7.1
rozza 02b0df8
Do not double wrap MongoClientExceptions
rozza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
driver-core/src/main/com/mongodb/client/model/vault/RangeOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.mongodb.client.model.vault; | ||
|
||
import com.mongodb.annotations.Beta; | ||
import com.mongodb.lang.Nullable; | ||
import org.bson.BsonValue; | ||
|
||
/** | ||
* Range options specifies index options for a Queryable Encryption field supporting "rangePreview" queries. | ||
* | ||
* <p>{@code min}, {@code max}, {@code sparsity}, and {@code range} must match the values set in the {@code encryptedFields} | ||
rozza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* of the destination collection. | ||
* | ||
* <p>For {@code double} and {@code decimal128}, {@code min}/{@code max}/{@code precision} must all be set, or all be unset. | ||
* | ||
* <p>Note: The Range algorithm is experimental only. It is not intended for public use. It is subject to breaking changes. | ||
* @since 4.9 | ||
* @mongodb.server.release 6.2 | ||
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption | ||
*/ | ||
@Beta(Beta.Reason.SERVER) | ||
public class RangeOptions { | ||
|
||
private BsonValue min; | ||
private BsonValue max; | ||
private Long sparsity; | ||
private Integer precision; | ||
|
||
/** | ||
* Construct a new instance | ||
*/ | ||
public RangeOptions() { | ||
} | ||
|
||
/** | ||
* Set the minimum value set in the encryptedFields of the destination collection. | ||
* @param min the minimum value | ||
* @return this | ||
*/ | ||
public RangeOptions min(@Nullable final BsonValue min) { | ||
this.min = min; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return the minimum value if set | ||
*/ | ||
@Nullable | ||
public BsonValue getMin() { | ||
return min; | ||
} | ||
|
||
/** | ||
* Set the maximum value set in the encryptedFields of the destination collection. | ||
* @param max the maximum value | ||
* @return this | ||
*/ | ||
public RangeOptions max(@Nullable final BsonValue max) { | ||
this.max = max; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return the maximum value if set | ||
*/ | ||
@Nullable | ||
public BsonValue getMax() { | ||
return max; | ||
} | ||
|
||
/** | ||
* Set the Queryable Encryption range hypergraph sparsity factor | ||
* @param sparsity the sparsity | ||
* @return this | ||
*/ | ||
public RangeOptions sparsity(@Nullable final Long sparsity) { | ||
this.sparsity = sparsity; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return the sparsity value if set | ||
*/ | ||
@Nullable | ||
public Long getSparsity() { | ||
return sparsity; | ||
} | ||
|
||
/** | ||
* Set the precision of double or decimal128 values in the encryptedFields of the destination collection. | ||
* @param precision the precision | ||
* @return this | ||
*/ | ||
public RangeOptions precision(@Nullable final Integer precision) { | ||
this.precision = precision; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return the precision value if set | ||
*/ | ||
@Nullable | ||
public Integer getPrecision() { | ||
return precision; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RangeOptions{" | ||
+ "min=" + min | ||
+ ", max=" + max | ||
+ ", sparsity=" + sparsity | ||
+ ", precision=" + precision | ||
+ '}'; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
driver-core/src/main/com/mongodb/internal/client/vault/EncryptOptionsHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.internal.client.vault; | ||
|
||
import com.mongodb.client.model.vault.EncryptOptions; | ||
import com.mongodb.client.model.vault.RangeOptions; | ||
import com.mongodb.crypt.capi.MongoExplicitEncryptOptions; | ||
import org.bson.BsonDocument; | ||
import org.bson.BsonInt32; | ||
import org.bson.BsonInt64; | ||
import org.bson.BsonValue; | ||
|
||
public final class EncryptOptionsHelper { | ||
|
||
public static MongoExplicitEncryptOptions asMongoExplicitEncryptOptions(final EncryptOptions options) { | ||
MongoExplicitEncryptOptions.Builder encryptOptionsBuilder = MongoExplicitEncryptOptions.builder() | ||
.algorithm(options.getAlgorithm()); | ||
|
||
if (options.getKeyId() != null) { | ||
encryptOptionsBuilder.keyId(options.getKeyId()); | ||
} | ||
|
||
if (options.getKeyAltName() != null) { | ||
encryptOptionsBuilder.keyAltName(options.getKeyAltName()); | ||
} | ||
|
||
if (options.getContentionFactor() != null) { | ||
encryptOptionsBuilder.contentionFactor(options.getContentionFactor()); | ||
} | ||
|
||
if (options.getQueryType() != null) { | ||
encryptOptionsBuilder.queryType(options.getQueryType()); | ||
} | ||
|
||
RangeOptions rangeOptions = options.getRangeOptions(); | ||
if (rangeOptions != null) { | ||
BsonDocument rangeOptionsBsonDocument = new BsonDocument(); | ||
BsonValue min = rangeOptions.getMin(); | ||
if (min != null) { | ||
rangeOptionsBsonDocument.put("min", min); | ||
} | ||
BsonValue max = rangeOptions.getMax(); | ||
if (max != null) { | ||
rangeOptionsBsonDocument.put("max", max); | ||
} | ||
Long sparsity = rangeOptions.getSparsity(); | ||
if (sparsity != null) { | ||
rangeOptionsBsonDocument.put("sparsity", new BsonInt64(sparsity)); | ||
} | ||
Integer precision = rangeOptions.getPrecision(); | ||
if (precision != null) { | ||
rangeOptionsBsonDocument.put("precision", new BsonInt32(precision)); | ||
} | ||
encryptOptionsBuilder.rangeOptions(rangeOptionsBsonDocument); | ||
} | ||
return encryptOptionsBuilder.build(); | ||
} | ||
private EncryptOptionsHelper() { | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
driver-core/src/main/com/mongodb/internal/client/vault/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* This package contains classes that manage binding to MongoDB servers for various operations. | ||
*/ | ||
|
||
@NonNullApi | ||
package com.mongodb.internal.client.vault; | ||
|
||
import com.mongodb.lang.NonNullApi; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a temp change. Will revert once libmongocrypt 1.7.0 binding have been pushed.