Skip to content

Commit e9ee119

Browse files
authored
Feature/named indices (#283)
* added named indices feature for all supported index types * added tests for named indices * added options * changelog
1 parent a5c2c82 commit e9ee119

File tree

8 files changed

+242
-9
lines changed

8 files changed

+242
-9
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
88

99
### Added
1010

11+
- added support for named indices
1112
- added minReplicationAttribute for collections and graphs
1213

1314
## [5.0.7] - 2019-07-19

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
public class IndexEntity implements Entity {
3030

3131
private String id;
32+
private String name;
3233
private IndexType type;
3334
private Collection<String> fields;
3435
private Double selectivityEstimate;
@@ -48,6 +49,10 @@ public String getId() {
4849
return id;
4950
}
5051

52+
public String getName() {
53+
return name;
54+
}
55+
5156
public IndexType getType() {
5257
return type;
5358
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class FulltextIndexOptions {
3333
private Iterable<String> fields;
3434
private final IndexType type = IndexType.fulltext;
3535
private Integer minLength;
36+
private String name;
3637

3738
public FulltextIndexOptions() {
3839
super();
@@ -60,6 +61,20 @@ public Integer getMinLength() {
6061
return minLength;
6162
}
6263

64+
/**
65+
* @param name
66+
* the name of the index
67+
* @return options
68+
*/
69+
public FulltextIndexOptions name(final String name) {
70+
this.name = name;
71+
return this;
72+
}
73+
74+
protected String getName() {
75+
return name;
76+
}
77+
6378
/**
6479
* @param minLength
6580
* Minimum character length of words to index. Will default to a server-defined value if unspecified. It

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class GeoIndexOptions {
3232
private Iterable<String> fields;
3333
private final IndexType type = IndexType.geo;
3434
private Boolean geoJson;
35+
private String name;
3536

3637
public GeoIndexOptions() {
3738
super();
@@ -55,6 +56,20 @@ protected IndexType getType() {
5556
return type;
5657
}
5758

59+
/**
60+
* @param name
61+
* the name of the index
62+
* @return options
63+
*/
64+
public GeoIndexOptions name(final String name) {
65+
this.name = name;
66+
return this;
67+
}
68+
69+
protected String getName() {
70+
return name;
71+
}
72+
5873
public Boolean getGeoJson() {
5974
return geoJson;
6075
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class HashIndexOptions {
3434
private Boolean unique;
3535
private Boolean sparse;
3636
private Boolean deduplicate;
37+
private String name;
3738

3839
public HashIndexOptions() {
3940
super();
@@ -99,4 +100,18 @@ public HashIndexOptions deduplicate(final Boolean deduplicate) {
99100
return this;
100101
}
101102

103+
/**
104+
* @param name
105+
* the name of the index
106+
* @return options
107+
*/
108+
public HashIndexOptions name(final String name) {
109+
this.name = name;
110+
return this;
111+
}
112+
113+
protected String getName() {
114+
return name;
115+
}
116+
102117
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class PersistentIndexOptions {
3232

3333
private Iterable<String> fields;
3434
protected IndexType type = IndexType.persistent;
35+
private String name;
3536
private Boolean unique;
3637
private Boolean sparse;
3738

@@ -71,6 +72,20 @@ public PersistentIndexOptions unique(final Boolean unique) {
7172
return this;
7273
}
7374

75+
/**
76+
* @param name
77+
* the name of the index
78+
* @return options
79+
*/
80+
public PersistentIndexOptions name(final String name) {
81+
this.name = name;
82+
return this;
83+
}
84+
85+
protected String getName() {
86+
return name;
87+
}
88+
7489
public Boolean getSparse() {
7590
return sparse;
7691
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class SkiplistIndexOptions {
3434
private Boolean unique;
3535
private Boolean sparse;
3636
private Boolean deduplicate;
37+
private String name;
3738

3839
public SkiplistIndexOptions() {
3940
super();
@@ -99,4 +100,18 @@ public SkiplistIndexOptions deduplicate(final Boolean deduplicate) {
99100
return this;
100101
}
101102

103+
/**
104+
* @param name
105+
* the name of the index
106+
* @return options
107+
*/
108+
public SkiplistIndexOptions name(final String name) {
109+
this.name = name;
110+
return this;
111+
}
112+
113+
protected String getName() {
114+
return name;
115+
}
116+
102117
}

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

Lines changed: 161 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.HashMap;
4343
import java.util.Map;
4444

45+
import com.arangodb.model.*;
4546
import org.junit.After;
4647
import org.junit.Test;
4748
import org.junit.runner.RunWith;
@@ -63,16 +64,7 @@
6364
import com.arangodb.entity.MultiDocumentEntity;
6465
import com.arangodb.entity.Permissions;
6566
import com.arangodb.entity.ServerRole;
66-
import com.arangodb.model.CollectionCreateOptions;
67-
import com.arangodb.model.CollectionPropertiesOptions;
68-
import com.arangodb.model.DocumentCreateOptions;
69-
import com.arangodb.model.DocumentDeleteOptions;
70-
import com.arangodb.model.DocumentExistsOptions;
71-
import com.arangodb.model.DocumentImportOptions;
7267
import com.arangodb.model.DocumentImportOptions.OnDuplicate;
73-
import com.arangodb.model.DocumentReadOptions;
74-
import com.arangodb.model.DocumentReplaceOptions;
75-
import com.arangodb.model.DocumentUpdateOptions;
7668
import com.arangodb.velocypack.VPackSlice;
7769

7870
/**
@@ -1044,6 +1036,35 @@ public void createHashIndex() {
10441036
assertThat(indexResult.getUnique(), is(false));
10451037
}
10461038

1039+
@Test
1040+
public void createHashIndexWithOptions() {
1041+
if (!requireVersion(3, 5)) {
1042+
return;
1043+
}
1044+
1045+
final HashIndexOptions options = new HashIndexOptions();
1046+
options.name("myHashIndex");
1047+
1048+
final Collection<String> fields = new ArrayList<String>();
1049+
fields.add("a");
1050+
fields.add("b");
1051+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureHashIndex(fields, options);
1052+
assertThat(indexResult, is(notNullValue()));
1053+
assertThat(indexResult.getConstraint(), is(nullValue()));
1054+
assertThat(indexResult.getFields(), hasItem("a"));
1055+
assertThat(indexResult.getFields(), hasItem("b"));
1056+
assertThat(indexResult.getId(), startsWith(COLLECTION_NAME));
1057+
assertThat(indexResult.getIsNewlyCreated(), is(true));
1058+
assertThat(indexResult.getMinLength(), is(nullValue()));
1059+
if (arangoDB.getRole() == ServerRole.SINGLE) {
1060+
assertThat(indexResult.getSelectivityEstimate(), is(1.));
1061+
}
1062+
assertThat(indexResult.getSparse(), is(false));
1063+
assertThat(indexResult.getType(), is(IndexType.hash));
1064+
assertThat(indexResult.getUnique(), is(false));
1065+
assertThat(indexResult.getName(), is("myHashIndex"));
1066+
}
1067+
10471068
@Test
10481069
public void createGeoIndex() {
10491070
final Collection<String> fields = new ArrayList<String>();
@@ -1063,6 +1084,33 @@ public void createGeoIndex() {
10631084
}
10641085
}
10651086

1087+
@Test
1088+
public void createGeoIndexWithOptions() {
1089+
if (!requireVersion(3, 5)) {
1090+
return;
1091+
}
1092+
1093+
final GeoIndexOptions options = new GeoIndexOptions();
1094+
options.name("myGeoIndex1");
1095+
1096+
final Collection<String> fields = new ArrayList<String>();
1097+
fields.add("a");
1098+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureGeoIndex(fields, options);
1099+
assertThat(indexResult, is(notNullValue()));
1100+
assertThat(indexResult.getFields(), hasItem("a"));
1101+
assertThat(indexResult.getId(), startsWith(COLLECTION_NAME));
1102+
assertThat(indexResult.getIsNewlyCreated(), is(true));
1103+
assertThat(indexResult.getMinLength(), is(nullValue()));
1104+
assertThat(indexResult.getSparse(), is(true));
1105+
assertThat(indexResult.getUnique(), is(false));
1106+
if (requireVersion(3, 4)) {
1107+
assertThat(indexResult.getType(), is(IndexType.geo));
1108+
} else {
1109+
assertThat(indexResult.getType(), is(IndexType.geo1));
1110+
}
1111+
assertThat(indexResult.getName(), is("myGeoIndex1"));
1112+
}
1113+
10661114
@Test
10671115
public void createGeo2Index() {
10681116
final Collection<String> fields = new ArrayList<String>();
@@ -1084,6 +1132,35 @@ public void createGeo2Index() {
10841132
}
10851133
}
10861134

1135+
@Test
1136+
public void createGeo2IndexWithOptions() {
1137+
if (!requireVersion(3, 5)) {
1138+
return;
1139+
}
1140+
1141+
final GeoIndexOptions options = new GeoIndexOptions();
1142+
options.name("myGeoIndex2");
1143+
1144+
final Collection<String> fields = new ArrayList<String>();
1145+
fields.add("a");
1146+
fields.add("b");
1147+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureGeoIndex(fields, options);
1148+
assertThat(indexResult, is(notNullValue()));
1149+
assertThat(indexResult.getFields(), hasItem("a"));
1150+
assertThat(indexResult.getFields(), hasItem("b"));
1151+
assertThat(indexResult.getId(), startsWith(COLLECTION_NAME));
1152+
assertThat(indexResult.getIsNewlyCreated(), is(true));
1153+
assertThat(indexResult.getMinLength(), is(nullValue()));
1154+
assertThat(indexResult.getSparse(), is(true));
1155+
assertThat(indexResult.getUnique(), is(false));
1156+
if (requireVersion(3, 4)) {
1157+
assertThat(indexResult.getType(), is(IndexType.geo));
1158+
} else {
1159+
assertThat(indexResult.getType(), is(IndexType.geo2));
1160+
}
1161+
assertThat(indexResult.getName(), is("myGeoIndex2"));
1162+
}
1163+
10871164
@Test
10881165
public void createSkiplistIndex() {
10891166
final Collection<String> fields = new ArrayList<String>();
@@ -1102,6 +1179,32 @@ public void createSkiplistIndex() {
11021179
assertThat(indexResult.getUnique(), is(false));
11031180
}
11041181

1182+
@Test
1183+
public void createSkiplistIndexWithOptions() {
1184+
if (!requireVersion(3, 5)) {
1185+
return;
1186+
}
1187+
1188+
final SkiplistIndexOptions options = new SkiplistIndexOptions();
1189+
options.name("mySkiplistIndex");
1190+
1191+
final Collection<String> fields = new ArrayList<String>();
1192+
fields.add("a");
1193+
fields.add("b");
1194+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureSkiplistIndex(fields, options);
1195+
assertThat(indexResult, is(notNullValue()));
1196+
assertThat(indexResult.getConstraint(), is(nullValue()));
1197+
assertThat(indexResult.getFields(), hasItem("a"));
1198+
assertThat(indexResult.getFields(), hasItem("b"));
1199+
assertThat(indexResult.getId(), startsWith(COLLECTION_NAME));
1200+
assertThat(indexResult.getIsNewlyCreated(), is(true));
1201+
assertThat(indexResult.getMinLength(), is(nullValue()));
1202+
assertThat(indexResult.getSparse(), is(false));
1203+
assertThat(indexResult.getType(), is(IndexType.skiplist));
1204+
assertThat(indexResult.getUnique(), is(false));
1205+
assertThat(indexResult.getName(), is("mySkiplistIndex"));
1206+
}
1207+
11051208
@Test
11061209
public void createPersistentIndex() {
11071210
final Collection<String> fields = new ArrayList<String>();
@@ -1120,6 +1223,32 @@ public void createPersistentIndex() {
11201223
assertThat(indexResult.getUnique(), is(false));
11211224
}
11221225

1226+
@Test
1227+
public void createPersistentIndexWithOptions() {
1228+
if (!requireVersion(3, 5)) {
1229+
return;
1230+
}
1231+
1232+
final PersistentIndexOptions options = new PersistentIndexOptions();
1233+
options.name("myPersistentIndex");
1234+
1235+
final Collection<String> fields = new ArrayList<String>();
1236+
fields.add("a");
1237+
fields.add("b");
1238+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensurePersistentIndex(fields, options);
1239+
assertThat(indexResult, is(notNullValue()));
1240+
assertThat(indexResult.getConstraint(), is(nullValue()));
1241+
assertThat(indexResult.getFields(), hasItem("a"));
1242+
assertThat(indexResult.getFields(), hasItem("b"));
1243+
assertThat(indexResult.getId(), startsWith(COLLECTION_NAME));
1244+
assertThat(indexResult.getIsNewlyCreated(), is(true));
1245+
assertThat(indexResult.getMinLength(), is(nullValue()));
1246+
assertThat(indexResult.getSparse(), is(false));
1247+
assertThat(indexResult.getType(), is(IndexType.persistent));
1248+
assertThat(indexResult.getUnique(), is(false));
1249+
assertThat(indexResult.getName(), is("myPersistentIndex"));
1250+
}
1251+
11231252
@Test
11241253
public void createFulltextIndex() {
11251254
final Collection<String> fields = new ArrayList<String>();
@@ -1135,6 +1264,29 @@ public void createFulltextIndex() {
11351264
assertThat(indexResult.getUnique(), is(false));
11361265
}
11371266

1267+
@Test
1268+
public void createFulltextIndexWithOptions() {
1269+
if (!requireVersion(3, 5)) {
1270+
return;
1271+
}
1272+
1273+
final FulltextIndexOptions options = new FulltextIndexOptions();
1274+
options.name("myFulltextIndex");
1275+
1276+
final Collection<String> fields = new ArrayList<String>();
1277+
fields.add("a");
1278+
final IndexEntity indexResult = db.collection(COLLECTION_NAME).ensureFulltextIndex(fields, options);
1279+
assertThat(indexResult, is(notNullValue()));
1280+
assertThat(indexResult.getConstraint(), is(nullValue()));
1281+
assertThat(indexResult.getFields(), hasItem("a"));
1282+
assertThat(indexResult.getId(), startsWith(COLLECTION_NAME));
1283+
assertThat(indexResult.getIsNewlyCreated(), is(true));
1284+
assertThat(indexResult.getSparse(), is(true));
1285+
assertThat(indexResult.getType(), is(IndexType.fulltext));
1286+
assertThat(indexResult.getUnique(), is(false));
1287+
assertThat(indexResult.getName(), is("myFulltextIndex"));
1288+
}
1289+
11381290
@Test
11391291
public void getIndexes() {
11401292
final Collection<String> fields = new ArrayList<String>();

0 commit comments

Comments
 (0)