From f9213d14736d44d42d7236e6ef2c9c72ca3eed09 Mon Sep 17 00:00:00 2001 From: Paulo Ferreira Date: Tue, 17 May 2022 15:17:27 -0300 Subject: [PATCH 1/4] deduplicate --- .../model/PersistentIndexOptions.java | 15 +++++++ .../com/arangodb/ArangoCollectionTest.java | 42 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index 25a50a886..3cc1be981 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. + * @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..295cb7485 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -1590,6 +1590,48 @@ void indexEstimatesFalse(ArangoCollection collection) { assertThat(indexResult.getSelectivityEstimate()).isNull(); } + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void indexDeduplicate(ArangoCollection collection) { + assumeTrue(isAtLeastVersion(3, 8)); + assumeTrue(isSingleServer()); + + 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(); + assertThat(indexResult.getSelectivityEstimate()).isNotNull(); + } + + @ParameterizedTest(name = "{index}") + @MethodSource("cols") + void indexDeduplicateFalse(ArangoCollection collection) { + assumeTrue(isAtLeastVersion(3, 8)); + assumeTrue(isSingleServer()); + + 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(); + assertThat(indexResult.getSelectivityEstimate()).isNull(); + } + @ParameterizedTest(name = "{index}") @MethodSource("cols") void createFulltextIndex(ArangoCollection collection) { From ad2c4db85d6bc68b4e594217ec68a44c5763fbc3 Mon Sep 17 00:00:00 2001 From: Paulo Ferreira Date: Wed, 18 May 2022 10:37:56 -0300 Subject: [PATCH 2/4] add Default --- src/main/java/com/arangodb/model/PersistentIndexOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index 3cc1be981..c9ba08c34 100644 --- a/src/main/java/com/arangodb/model/PersistentIndexOptions.java +++ b/src/main/java/com/arangodb/model/PersistentIndexOptions.java @@ -95,7 +95,7 @@ public Boolean getDeduplicate() { /** * @param deduplicate - * if false, the deduplication of array values is turned off. + * if false, the deduplication of array values is turned off. Default: {@code true} * @return options */ public PersistentIndexOptions deduplicate(final Boolean deduplicate) { From 9d9d6f0a818a3b1d8e2b13b4ec1634d53417b0ab Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 18 May 2022 21:20:23 +0200 Subject: [PATCH 3/4] fixed tests --- src/test/java/com/arangodb/ArangoCollectionTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 295cb7485..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}") @@ -1594,7 +1595,6 @@ void indexEstimatesFalse(ArangoCollection collection) { @MethodSource("cols") void indexDeduplicate(ArangoCollection collection) { assumeTrue(isAtLeastVersion(3, 8)); - assumeTrue(isSingleServer()); String name = "persistentIndex-" + rnd(); final PersistentIndexOptions options = new PersistentIndexOptions(); @@ -1608,14 +1608,12 @@ void indexDeduplicate(ArangoCollection collection) { final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options); assertThat(indexResult).isNotNull(); assertThat(indexResult.getDeduplicate()).isTrue(); - assertThat(indexResult.getSelectivityEstimate()).isNotNull(); } @ParameterizedTest(name = "{index}") @MethodSource("cols") void indexDeduplicateFalse(ArangoCollection collection) { assumeTrue(isAtLeastVersion(3, 8)); - assumeTrue(isSingleServer()); String name = "persistentIndex-" + rnd(); final PersistentIndexOptions options = new PersistentIndexOptions(); @@ -1629,7 +1627,6 @@ void indexDeduplicateFalse(ArangoCollection collection) { final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options); assertThat(indexResult).isNotNull(); assertThat(indexResult.getDeduplicate()).isFalse(); - assertThat(indexResult.getSelectivityEstimate()).isNull(); } @ParameterizedTest(name = "{index}") From 14a36f6aeee22086e134b25ecba013cb0f32724c Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Wed, 18 May 2022 21:34:13 +0200 Subject: [PATCH 4/4] async tests --- .../arangodb/async/ArangoCollectionTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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<>();