Skip to content

Commit 0d1f01a

Browse files
committed
[DE-373] index stored values
1 parent b926685 commit 0d1f01a

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

src/main/java/com/arangodb/entity/IndexEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class IndexEntity implements Entity {
4343
private Boolean inBackground;
4444
private Boolean estimates;
4545
private Boolean cacheEnabled;
46+
private Collection<String> storedValues;
4647
private Boolean legacyPolygons;
4748

4849
public IndexEntity() {
@@ -113,6 +114,10 @@ public Boolean getCacheEnabled() {
113114
return cacheEnabled;
114115
}
115116

117+
public Collection<String> getStoredValues() {
118+
return storedValues;
119+
}
120+
116121
public Boolean getLegacyPolygons() {
117122
return legacyPolygons;
118123
}

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
import com.arangodb.entity.IndexType;
2424

25+
import java.util.Collection;
26+
import java.util.Collections;
27+
import java.util.HashSet;
28+
2529
/**
2630
* @author Mark Vollmary
2731
* @see <a href="https://www.arangodb.com/docs/stable/http/indexes-persistent.html#create-a-persistent-index">API
@@ -36,6 +40,7 @@ public class PersistentIndexOptions extends IndexOptions<PersistentIndexOptions>
3640
private Boolean deduplicate;
3741
private Boolean estimates;
3842
private Boolean cacheEnabled;
43+
private Collection<String> storedValues;
3944

4045
public PersistentIndexOptions() {
4146
super();
@@ -81,8 +86,7 @@ public Boolean getSparse() {
8186
}
8287

8388
/**
84-
* @param sparse
85-
* if true, then create a sparse index
89+
* @param sparse if true, then create a sparse index
8690
* @return options
8791
*/
8892
public PersistentIndexOptions sparse(final Boolean sparse) {
@@ -95,8 +99,7 @@ public Boolean getDeduplicate() {
9599
}
96100

97101
/**
98-
* @param deduplicate
99-
* if false, the deduplication of array values is turned off. Default: {@code true}
102+
* @param deduplicate if false, the deduplication of array values is turned off. Default: {@code true}
100103
* @return options
101104
*/
102105
public PersistentIndexOptions deduplicate(final Boolean deduplicate) {
@@ -105,9 +108,9 @@ public PersistentIndexOptions deduplicate(final Boolean deduplicate) {
105108
}
106109

107110
/**
108-
* @param estimates
109-
* This attribute controls whether index selectivity estimates are maintained for the index. Default: {@code
110-
* true}
111+
* @param estimates This attribute controls whether index selectivity estimates are maintained for the index.
112+
* Default: {@code
113+
* true}
111114
* @since ArangoDB 3.8
112115
*/
113116
public PersistentIndexOptions estimates(final Boolean estimates) {
@@ -121,6 +124,7 @@ public Boolean getEstimates() {
121124

122125
/**
123126
* @param cacheEnabled enables in-memory caching of index entries
127+
* @return options
124128
* @since ArangoDB 3.10
125129
*/
126130
public PersistentIndexOptions cacheEnabled(final Boolean cacheEnabled) {
@@ -132,4 +136,23 @@ public Boolean getCacheEnabled() {
132136
return cacheEnabled;
133137
}
134138

139+
public Collection<String> getStoredValues() {
140+
return storedValues;
141+
}
142+
143+
/**
144+
* @param storedValues (optional) array of paths to additional attributes to store in the index. These additional
145+
* attributes cannot be used for index lookups or for sorting, but they can be used for
146+
* projections. This allows an index to fully cover more queries and avoid extra document
147+
* lookups. The maximum number of attributes in `storedValues` is 32.
148+
* @return options
149+
*/
150+
public PersistentIndexOptions storedValues(final String... storedValues) {
151+
if (this.storedValues == null) {
152+
this.storedValues = new HashSet<>();
153+
}
154+
Collections.addAll(this.storedValues, storedValues);
155+
return this;
156+
}
157+
135158
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,33 @@ void createPersistentIndexCacheEnabled(ArangoCollection collection) {
15351535
assertThat(indexResult.getCacheEnabled()).isTrue();
15361536
}
15371537

1538+
@ParameterizedTest(name = "{index}")
1539+
@MethodSource("cols")
1540+
void createPersistentIndexStoredValues(ArangoCollection collection) {
1541+
assumeTrue(isAtLeastVersion(3, 10));
1542+
1543+
String f1 = "field-" + rnd();
1544+
String f2 = "field-" + rnd();
1545+
final Collection<String> fields = Arrays.asList(f1, f2);
1546+
1547+
final IndexEntity indexResult = collection.ensurePersistentIndex(fields, new PersistentIndexOptions().storedValues("v1", "v2"));
1548+
assertThat(indexResult).isNotNull();
1549+
assertThat(indexResult.getConstraint()).isNull();
1550+
assertThat(indexResult.getFields()).contains(f1);
1551+
assertThat(indexResult.getFields()).contains(f2);
1552+
assertThat(indexResult.getId()).startsWith(COLLECTION_NAME);
1553+
assertThat(indexResult.getIsNewlyCreated()).isTrue();
1554+
assertThat(indexResult.getMinLength()).isNull();
1555+
assertThat(indexResult.getSparse()).isFalse();
1556+
assertThat(indexResult.getType()).isEqualTo(IndexType.persistent);
1557+
assertThat(indexResult.getUnique()).isFalse();
1558+
assertThat(indexResult.getDeduplicate()).isTrue();
1559+
assertThat(indexResult.getCacheEnabled()).isFalse();
1560+
assertThat(indexResult.getStoredValues())
1561+
.hasSize(2)
1562+
.contains("v1", "v2");
1563+
}
1564+
15381565
@ParameterizedTest(name = "{index}")
15391566
@MethodSource("cols")
15401567
void createPersistentIndexWithOptions(ArangoCollection collection) {

0 commit comments

Comments
 (0)