diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index 25a50a886..c9ba08c34 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -33,6 +33,7 @@ public class PersistentIndexOptions extends IndexOptions protected final IndexType type = IndexType.persistent; private Boolean unique; private Boolean sparse; + private Boolean deduplicate; private Boolean estimates; public PersistentIndexOptions() { @@ -88,6 +89,20 @@ public PersistentIndexOptions sparse(final Boolean sparse) { return this; } + public Boolean getDeduplicate() { + return deduplicate; + } + + /** + * @param deduplicate + * if false, the deduplication of array values is turned off. Default: {@code true} + * @return options + */ + public PersistentIndexOptions deduplicate(final Boolean deduplicate) { + this.deduplicate = deduplicate; + return this; + } + /** * @param estimates * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 9c4ceda2d..f1467ce72 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -1468,6 +1468,7 @@ void createPersistentIndex(ArangoCollection collection) { assertThat(indexResult.getSparse()).isFalse(); assertThat(indexResult.getType()).isEqualTo(IndexType.persistent); assertThat(indexResult.getUnique()).isFalse(); + assertThat(indexResult.getDeduplicate()).isTrue(); } @ParameterizedTest(name = "{index}") @@ -1590,6 +1591,44 @@ void indexEstimatesFalse(ArangoCollection collection) { assertThat(indexResult.getSelectivityEstimate()).isNull(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void indexDeduplicate(ArangoCollection collection) { + assumeTrue(isAtLeastVersion(3, 8)); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.deduplicate(true); + + String f1 = "field-" + rnd(); + String f2 = "field-" + rnd(); + + final Collection fields = Arrays.asList(f1, f2); + final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options); + assertThat(indexResult).isNotNull(); + assertThat(indexResult.getDeduplicate()).isTrue(); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void indexDeduplicateFalse(ArangoCollection collection) { + assumeTrue(isAtLeastVersion(3, 8)); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.deduplicate(false); + + String f1 = "field-" + rnd(); + String f2 = "field-" + rnd(); + + final Collection fields = Arrays.asList(f1, f2); + final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options); + assertThat(indexResult).isNotNull(); + assertThat(indexResult.getDeduplicate()).isFalse(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void createFulltextIndex(ArangoCollection collection) { diff --git a/src/test/java/com/arangodb/async/ArangoCollectionTest.java b/src/test/java/com/arangodb/async/ArangoCollectionTest.java index e3a675f96..541d147ae 100644 --- a/src/test/java/com/arangodb/async/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/async/ArangoCollectionTest.java @@ -1009,6 +1009,7 @@ void createPersistentIndex() throws InterruptedException, ExecutionException { assertThat(indexResult.getSparse()).isEqualTo(false); assertThat(indexResult.getType()).isEqualTo(IndexType.persistent); assertThat(indexResult.getUnique()).isEqualTo(false); + assertThat(indexResult.getDeduplicate()).isTrue(); }) .get(); } @@ -1036,6 +1037,42 @@ void createPersistentIndexWithOptions() throws ExecutionException, InterruptedEx assertThat(indexResult.getName()).isEqualTo("myPersistentIndex"); } + @Test + void indexDeduplicate() throws ExecutionException, InterruptedException { + assumeTrue(isAtLeastVersion(3, 8)); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.deduplicate(true); + + String f1 = "field-" + rnd(); + String f2 = "field-" + rnd(); + + final Collection fields = Arrays.asList(f1, f2); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensurePersistentIndex(fields, options).get(); + assertThat(indexResult).isNotNull(); + assertThat(indexResult.getDeduplicate()).isTrue(); + } + + @Test + void indexDeduplicateFalse() throws ExecutionException, InterruptedException { + assumeTrue(isAtLeastVersion(3, 8)); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.deduplicate(false); + + String f1 = "field-" + rnd(); + String f2 = "field-" + rnd(); + + final Collection fields = Arrays.asList(f1, f2); + final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensurePersistentIndex(fields, options).get(); + assertThat(indexResult).isNotNull(); + assertThat(indexResult.getDeduplicate()).isFalse(); + } + @Test void createFulltextIndex() throws InterruptedException, ExecutionException { final Collection fields = new ArrayList<>();