diff --git a/ChangeLog.md b/ChangeLog.md index 0b8af87bf..5d7c20970 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +- added support for index estimates (ArangoDB v3.8) - added support for ArangoSearch `AQL`, `Pipeline`, `Stopwords`, `GeoJSON`, `GeoPoint` analyzers - fixed active failover behavior for the asynchronous driver - deprecated `ArangoIterable` methods in favour of Java 8 Stream equivalents diff --git a/src/main/java/com/arangodb/entity/IndexEntity.java b/src/main/java/com/arangodb/entity/IndexEntity.java index 5be2d0b87..b359a5146 100644 --- a/src/main/java/com/arangodb/entity/IndexEntity.java +++ b/src/main/java/com/arangodb/entity/IndexEntity.java @@ -41,6 +41,7 @@ public class IndexEntity implements Entity { private Boolean deduplicate; private Integer expireAfter; private Boolean inBackground; + private Boolean estimates; public IndexEntity() { super(); @@ -102,4 +103,8 @@ public Boolean getDeduplicate() { return deduplicate; } + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/main/java/com/arangodb/model/HashIndexOptions.java b/src/main/java/com/arangodb/model/HashIndexOptions.java index 992c79281..20eff1d44 100644 --- a/src/main/java/com/arangodb/model/HashIndexOptions.java +++ b/src/main/java/com/arangodb/model/HashIndexOptions.java @@ -33,6 +33,7 @@ public class HashIndexOptions extends IndexOptions { private Boolean unique; private Boolean sparse; private Boolean deduplicate; + private Boolean estimates; public HashIndexOptions() { super(); @@ -91,11 +92,28 @@ public Boolean getDeduplicate() { } /** - * @param deduplicate if false, the deduplication of array values is turned off. + * @param deduplicate + * if false, the deduplication of array values is turned off. * @return options */ public HashIndexOptions 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 + * true} + * @since ArangoDB 3.8 + */ + public HashIndexOptions estimates(final Boolean estimates) { + this.estimates = estimates; + return this; + } + + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/main/java/com/arangodb/model/PersistentIndexOptions.java b/src/main/java/com/arangodb/model/PersistentIndexOptions.java index 75ab9fa9c..25a50a886 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 estimates; public PersistentIndexOptions() { super(); @@ -78,7 +79,8 @@ public Boolean getSparse() { } /** - * @param sparse if true, then create a sparse index + * @param sparse + * if true, then create a sparse index * @return options */ public PersistentIndexOptions sparse(final Boolean sparse) { @@ -86,4 +88,19 @@ public PersistentIndexOptions sparse(final Boolean sparse) { return this; } + /** + * @param estimates + * This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code + * true} + * @since ArangoDB 3.8 + */ + public PersistentIndexOptions estimates(final Boolean estimates) { + this.estimates = estimates; + return this; + } + + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java index f99676d2f..30d000f59 100644 --- a/src/main/java/com/arangodb/model/SkiplistIndexOptions.java +++ b/src/main/java/com/arangodb/model/SkiplistIndexOptions.java @@ -33,6 +33,7 @@ public class SkiplistIndexOptions extends IndexOptions { private Boolean unique; private Boolean sparse; private Boolean deduplicate; + private Boolean estimates; public SkiplistIndexOptions() { super(); @@ -91,11 +92,28 @@ public Boolean getDeduplicate() { } /** - * @param deduplicate if false, the deduplication of array values is turned off. + * @param deduplicate + * if false, the deduplication of array values is turned off. * @return options */ public SkiplistIndexOptions 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 + * true} + * @since ArangoDB 3.8 + */ + public SkiplistIndexOptions estimates(final Boolean estimates) { + this.estimates = estimates; + return this; + } + + public Boolean getEstimates() { + return estimates; + } + } diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index b4f4cf7d8..275d8fe90 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -20,9 +20,38 @@ package com.arangodb; -import com.arangodb.entity.*; -import com.arangodb.model.*; +import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.BaseEdgeDocument; +import com.arangodb.entity.CollectionEntity; +import com.arangodb.entity.CollectionPropertiesEntity; +import com.arangodb.entity.CollectionRevisionEntity; +import com.arangodb.entity.DocumentCreateEntity; +import com.arangodb.entity.DocumentDeleteEntity; +import com.arangodb.entity.DocumentEntity; +import com.arangodb.entity.DocumentImportEntity; +import com.arangodb.entity.DocumentUpdateEntity; +import com.arangodb.entity.IndexEntity; +import com.arangodb.entity.IndexType; +import com.arangodb.entity.MultiDocumentEntity; +import com.arangodb.entity.Permissions; +import com.arangodb.entity.ShardEntity; +import com.arangodb.model.CollectionCreateOptions; +import com.arangodb.model.CollectionPropertiesOptions; +import com.arangodb.model.DocumentCreateOptions; +import com.arangodb.model.DocumentDeleteOptions; +import com.arangodb.model.DocumentExistsOptions; +import com.arangodb.model.DocumentImportOptions; import com.arangodb.model.DocumentImportOptions.OnDuplicate; +import com.arangodb.model.DocumentReadOptions; +import com.arangodb.model.DocumentReplaceOptions; +import com.arangodb.model.DocumentUpdateOptions; +import com.arangodb.model.FulltextIndexOptions; +import com.arangodb.model.GeoIndexOptions; +import com.arangodb.model.HashIndexOptions; +import com.arangodb.model.OverwriteMode; +import com.arangodb.model.PersistentIndexOptions; +import com.arangodb.model.SkiplistIndexOptions; +import com.arangodb.model.TtlIndexOptions; import com.arangodb.util.MapBuilder; import com.arangodb.velocypack.VPackSlice; import com.fasterxml.jackson.core.JsonProcessingException; @@ -33,7 +62,14 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -1392,6 +1428,46 @@ public void createPersistentIndexWithOptions() { assertThat(indexResult.getName(), is(name)); } + @Test + public void indexEstimates() { + assumeTrue(isAtLeastVersion(3, 8)); + assumeTrue(isSingleServer()); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.estimates(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, is(notNullValue())); + assertThat(indexResult.getEstimates(), is(true)); + assertThat(indexResult.getSelectivityEstimate(), is(notNullValue())); + } + + @Test + public void indexEstimatesFalse() { + assumeTrue(isAtLeastVersion(3, 8)); + assumeTrue(isSingleServer()); + + String name = "persistentIndex-" + rnd(); + final PersistentIndexOptions options = new PersistentIndexOptions(); + options.name(name); + options.estimates(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, is(notNullValue())); + assertThat(indexResult.getEstimates(), is(false)); + assertThat(indexResult.getSelectivityEstimate(), is(nullValue())); + } + @Test public void createFulltextIndex() { String f1 = "field-" + rnd();