Skip to content

Commit 774c180

Browse files
[Feature] Deduplicate in PersistentIndex (#437)
* deduplicate * add Default * fixed tests * async tests Co-authored-by: Michele Rastelli <[email protected]>
1 parent 0bc7227 commit 774c180

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

src/main/java/com/arangodb/model/PersistentIndexOptions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class PersistentIndexOptions extends IndexOptions<PersistentIndexOptions>
3333
protected final IndexType type = IndexType.persistent;
3434
private Boolean unique;
3535
private Boolean sparse;
36+
private Boolean deduplicate;
3637
private Boolean estimates;
3738

3839
public PersistentIndexOptions() {
@@ -88,6 +89,20 @@ public PersistentIndexOptions sparse(final Boolean sparse) {
8889
return this;
8990
}
9091

92+
public Boolean getDeduplicate() {
93+
return deduplicate;
94+
}
95+
96+
/**
97+
* @param deduplicate
98+
* if false, the deduplication of array values is turned off. Default: {@code true}
99+
* @return options
100+
*/
101+
public PersistentIndexOptions deduplicate(final Boolean deduplicate) {
102+
this.deduplicate = deduplicate;
103+
return this;
104+
}
105+
91106
/**
92107
* @param estimates
93108
* This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ void createPersistentIndex(ArangoCollection collection) {
14681468
assertThat(indexResult.getSparse()).isFalse();
14691469
assertThat(indexResult.getType()).isEqualTo(IndexType.persistent);
14701470
assertThat(indexResult.getUnique()).isFalse();
1471+
assertThat(indexResult.getDeduplicate()).isTrue();
14711472
}
14721473

14731474
@ParameterizedTest(name = "{index}")
@@ -1590,6 +1591,44 @@ void indexEstimatesFalse(ArangoCollection collection) {
15901591
assertThat(indexResult.getSelectivityEstimate()).isNull();
15911592
}
15921593

1594+
@ParameterizedTest(name = "{index}")
1595+
@MethodSource("cols")
1596+
void indexDeduplicate(ArangoCollection collection) {
1597+
assumeTrue(isAtLeastVersion(3, 8));
1598+
1599+
String name = "persistentIndex-" + rnd();
1600+
final PersistentIndexOptions options = new PersistentIndexOptions();
1601+
options.name(name);
1602+
options.deduplicate(true);
1603+
1604+
String f1 = "field-" + rnd();
1605+
String f2 = "field-" + rnd();
1606+
1607+
final Collection<String> fields = Arrays.asList(f1, f2);
1608+
final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options);
1609+
assertThat(indexResult).isNotNull();
1610+
assertThat(indexResult.getDeduplicate()).isTrue();
1611+
}
1612+
1613+
@ParameterizedTest(name = "{index}")
1614+
@MethodSource("cols")
1615+
void indexDeduplicateFalse(ArangoCollection collection) {
1616+
assumeTrue(isAtLeastVersion(3, 8));
1617+
1618+
String name = "persistentIndex-" + rnd();
1619+
final PersistentIndexOptions options = new PersistentIndexOptions();
1620+
options.name(name);
1621+
options.deduplicate(false);
1622+
1623+
String f1 = "field-" + rnd();
1624+
String f2 = "field-" + rnd();
1625+
1626+
final Collection<String> fields = Arrays.asList(f1, f2);
1627+
final IndexEntity indexResult = collection.ensurePersistentIndex(fields, options);
1628+
assertThat(indexResult).isNotNull();
1629+
assertThat(indexResult.getDeduplicate()).isFalse();
1630+
}
1631+
15931632
@ParameterizedTest(name = "{index}")
15941633
@MethodSource("cols")
15951634
void createFulltextIndex(ArangoCollection collection) {

src/test/java/com/arangodb/async/ArangoCollectionTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ void createPersistentIndex() throws InterruptedException, ExecutionException {
10091009
assertThat(indexResult.getSparse()).isEqualTo(false);
10101010
assertThat(indexResult.getType()).isEqualTo(IndexType.persistent);
10111011
assertThat(indexResult.getUnique()).isEqualTo(false);
1012+
assertThat(indexResult.getDeduplicate()).isTrue();
10121013
})
10131014
.get();
10141015
}
@@ -1036,6 +1037,42 @@ void createPersistentIndexWithOptions() throws ExecutionException, InterruptedEx
10361037
assertThat(indexResult.getName()).isEqualTo("myPersistentIndex");
10371038
}
10381039

1040+
@Test
1041+
void indexDeduplicate() throws ExecutionException, InterruptedException {
1042+
assumeTrue(isAtLeastVersion(3, 8));
1043+
1044+
String name = "persistentIndex-" + rnd();
1045+
final PersistentIndexOptions options = new PersistentIndexOptions();
1046+
options.name(name);
1047+
options.deduplicate(true);
1048+
1049+
String f1 = "field-" + rnd();
1050+
String f2 = "field-" + rnd();
1051+
1052+
final Collection<String> fields = Arrays.asList(f1, f2);
1053+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensurePersistentIndex(fields, options).get();
1054+
assertThat(indexResult).isNotNull();
1055+
assertThat(indexResult.getDeduplicate()).isTrue();
1056+
}
1057+
1058+
@Test
1059+
void indexDeduplicateFalse() throws ExecutionException, InterruptedException {
1060+
assumeTrue(isAtLeastVersion(3, 8));
1061+
1062+
String name = "persistentIndex-" + rnd();
1063+
final PersistentIndexOptions options = new PersistentIndexOptions();
1064+
options.name(name);
1065+
options.deduplicate(false);
1066+
1067+
String f1 = "field-" + rnd();
1068+
String f2 = "field-" + rnd();
1069+
1070+
final Collection<String> fields = Arrays.asList(f1, f2);
1071+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensurePersistentIndex(fields, options).get();
1072+
assertThat(indexResult).isNotNull();
1073+
assertThat(indexResult.getDeduplicate()).isFalse();
1074+
}
1075+
10391076
@Test
10401077
void createFulltextIndex() throws InterruptedException, ExecutionException {
10411078
final Collection<String> fields = new ArrayList<>();

0 commit comments

Comments
 (0)