Skip to content

[Feature] Deduplicate in PersistentIndex #437

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 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 42 additions & 0 deletions src/test/java/com/arangodb/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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) {
Expand Down