Skip to content

Commit

Permalink
[Feature] Deduplicate in PersistentIndex (#437)
Browse files Browse the repository at this point in the history
* deduplicate

* add Default

* fixed tests

* async tests

Co-authored-by: Michele Rastelli <[email protected]>
  • Loading branch information
PauloFerreira25 and rashtao authored May 18, 2022
1 parent 0bc7227 commit 774c180
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/arangodb/model/PersistentIndexOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class PersistentIndexOptions extends IndexOptions<PersistentIndexOptions>
protected final IndexType type = IndexType.persistent;
private Boolean unique;
private Boolean sparse;
private Boolean deduplicate;
private Boolean estimates;

public PersistentIndexOptions() {
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/com/arangodb/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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<String> 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<String> 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) {
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/com/arangodb/async/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<String> 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<String> 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<String> fields = new ArrayList<>();
Expand Down

0 comments on commit 774c180

Please sign in to comment.