Skip to content

Commit 9073b31

Browse files
committed
[DE-373] index stored values
(cherry picked from commit 0d1f01a)
1 parent b501a5c commit 9073b31

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
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 final class IndexEntity {
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: 25 additions & 0 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 final class PersistentIndexOptions extends IndexOptions<PersistentIndexOp
3640
private Boolean deduplicate;
3741
private Boolean estimates;
3842
private Boolean cacheEnabled;
43+
private Collection<String> storedValues;
3944

4045
public PersistentIndexOptions() {
4146
super();
@@ -119,6 +124,7 @@ public Boolean getEstimates() {
119124

120125
/**
121126
* @param cacheEnabled enables in-memory caching of index entries
127+
* @return options
122128
* @since ArangoDB 3.10
123129
*/
124130
public PersistentIndexOptions cacheEnabled(final Boolean cacheEnabled) {
@@ -130,4 +136,23 @@ public Boolean getCacheEnabled() {
130136
return cacheEnabled;
131137
}
132138

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+
133158
}

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

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

1517+
@ParameterizedTest(name = "{index}")
1518+
@MethodSource("cols")
1519+
void createPersistentIndexStoredValues(ArangoCollection collection) {
1520+
assumeTrue(isAtLeastVersion(3, 10));
1521+
1522+
String f1 = "field-" + rnd();
1523+
String f2 = "field-" + rnd();
1524+
final Collection<String> fields = Arrays.asList(f1, f2);
1525+
1526+
final IndexEntity indexResult = collection.ensurePersistentIndex(fields, new PersistentIndexOptions().storedValues("v1", "v2"));
1527+
assertThat(indexResult).isNotNull();
1528+
assertThat(indexResult.getConstraint()).isNull();
1529+
assertThat(indexResult.getFields()).contains(f1);
1530+
assertThat(indexResult.getFields()).contains(f2);
1531+
assertThat(indexResult.getId()).startsWith(COLLECTION_NAME);
1532+
assertThat(indexResult.getIsNewlyCreated()).isTrue();
1533+
assertThat(indexResult.getMinLength()).isNull();
1534+
assertThat(indexResult.getSparse()).isFalse();
1535+
assertThat(indexResult.getType()).isEqualTo(IndexType.persistent);
1536+
assertThat(indexResult.getUnique()).isFalse();
1537+
assertThat(indexResult.getDeduplicate()).isTrue();
1538+
assertThat(indexResult.getCacheEnabled()).isFalse();
1539+
assertThat(indexResult.getStoredValues())
1540+
.hasSize(2)
1541+
.contains("v1", "v2");
1542+
}
1543+
15171544
@ParameterizedTest(name = "{index}")
15181545
@MethodSource("cols")
15191546
void createPersistentIndexWithOptions(ArangoCollection collection) {

0 commit comments

Comments
 (0)