Skip to content

Commit 0f99d4e

Browse files
authored
[DE-80] zkd indexes (#417)
* zkd indexes * fixed zkd indexes tests * fixed merge issue
1 parent 8c7b665 commit 0f99d4e

13 files changed

+259
-22
lines changed

src/main/java/com/arangodb/ArangoCollection.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,19 @@ <T> MultiDocumentEntity<DocumentDeleteEntity<T>> deleteDocuments(
528528
*/
529529
IndexEntity ensureTtlIndex(Iterable<String> fields, TtlIndexOptions options) throws ArangoDBException;
530530

531+
/**
532+
* Creates a ZKD multi-dimensional index for the collection, if it does not already exist.
533+
* Note that zkd indexes are an experimental feature in ArangoDB 3.9.
534+
*
535+
* @param fields A list of attribute paths
536+
* @param options Additional options, can be null
537+
* @return information about the index
538+
* @throws ArangoDBException
539+
* @see <a href="https://www.arangodb.com/docs/stable/http/indexes-multi-dim.html">API Documentation</a>
540+
* @since ArangoDB 3.9
541+
*/
542+
IndexEntity ensureZKDIndex(Iterable<String> fields, ZKDIndexOptions options) throws ArangoDBException;
543+
531544
/**
532545
* Fetches a list of all indexes on this collection.
533546
*

src/main/java/com/arangodb/async/ArangoCollectionAsync.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ <T> CompletableFuture<DocumentUpdateEntity<T>> updateDocument(
270270
* to patch (the patch document). All attributes from the patch document will be added to the existing document if
271271
* they do not yet exist, and overwritten in the existing document if they do exist there.
272272
*
273-
* @param key The key of the document
274-
* @param value A representation of a single document (POJO, VPackSlice or String for Json)
275-
* @param options Additional options, can be null
276-
* @param returnType Type of the returned newDocument and/or oldDocument
273+
* @param key The key of the document
274+
* @param value A representation of a single document (POJO, VPackSlice or String for Json)
275+
* @param options Additional options, can be null
276+
* @param returnType Type of the returned newDocument and/or oldDocument
277277
* @return information about the document
278278
* @see <a href="https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#update-document">API
279279
* Documentation</a>
@@ -497,6 +497,18 @@ CompletableFuture<IndexEntity> ensureFulltextIndex(
497497
*/
498498
CompletableFuture<IndexEntity> ensureTtlIndex(Iterable<String> fields, TtlIndexOptions options);
499499

500+
/**
501+
* Creates a ZKD multi-dimensional index for the collection, if it does not already exist.
502+
* Note that zkd indexes are an experimental feature in ArangoDB 3.9.
503+
*
504+
* @param fields A list of attribute paths
505+
* @param options Additional options, can be null
506+
* @return information about the index
507+
* @see <a href="https://www.arangodb.com/docs/stable/http/indexes-multi-dim.html">API Documentation</a>
508+
* @since ArangoDB 3.9
509+
*/
510+
CompletableFuture<IndexEntity> ensureZKDIndex(final Iterable<String> fields, final ZKDIndexOptions options);
511+
500512
/**
501513
* Returns all indexes of the collection
502514
*

src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ public CompletableFuture<IndexEntity> ensureTtlIndex(Iterable<String> fields, Tt
301301
return executor.execute(createTtlIndexRequest(fields, options), IndexEntity.class);
302302
}
303303

304+
@Override
305+
public CompletableFuture<IndexEntity> ensureZKDIndex(
306+
final Iterable<String> fields,
307+
final ZKDIndexOptions options) {
308+
return executor.execute(createZKDIndexRequest(fields, options), IndexEntity.class);
309+
}
310+
304311
@Override
305312
public CompletableFuture<Collection<IndexEntity>> getIndexes() {
306313
return executor.execute(getIndexesRequest(), getIndexesResponseDeserializer());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
* @author Heiko Kernbach
2626
*/
2727
public enum IndexType {
28-
primary, hash, skiplist, persistent, geo, geo1, geo2, fulltext, edge, ttl
28+
primary, hash, skiplist, persistent, geo, geo1, geo2, fulltext, edge, ttl, zkd
2929
}

src/main/java/com/arangodb/internal/ArangoCollectionImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ public IndexEntity ensureTtlIndex(final Iterable<String> fields, final TtlIndexO
295295
return executor.execute(createTtlIndexRequest(fields, options), IndexEntity.class);
296296
}
297297

298+
@Override
299+
public IndexEntity ensureZKDIndex(final Iterable<String> fields, final ZKDIndexOptions options)
300+
throws ArangoDBException {
301+
return executor.execute(createZKDIndexRequest(fields, options), IndexEntity.class);
302+
}
303+
298304
@Override
299305
public Collection<IndexEntity> getIndexes() throws ArangoDBException {
300306
return executor.execute(getIndexesRequest(), getIndexesResponseDeserializer());

src/main/java/com/arangodb/internal/InternalArangoCollection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,15 @@ protected Request createTtlIndexRequest(final Iterable<String> fields, final Ttl
596596
return request;
597597
}
598598

599+
protected Request createZKDIndexRequest(
600+
final Iterable<String> fields, final ZKDIndexOptions options) {
601+
final Request request = request(db.dbName(), RequestType.POST, PATH_API_INDEX);
602+
request.putQueryParam(COLLECTION, name);
603+
request.setBody(util().serialize(OptionsBuilder.build(options != null ? options :
604+
new ZKDIndexOptions().fieldValueTypes(ZKDIndexOptions.FieldValueTypes.DOUBLE), fields)));
605+
return request;
606+
}
607+
599608
protected Request getIndexesRequest() {
600609
final Request request = request(db.dbName(), RequestType.GET, PATH_API_INDEX);
601610
request.putQueryParam(COLLECTION, name);

src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.arangodb.entity.arangosearch.analyzer.StopwordsAnalyzer;
5757
import com.arangodb.entity.arangosearch.analyzer.TextAnalyzer;
5858
import com.arangodb.model.CollectionSchema;
59+
import com.arangodb.model.ZKDIndexOptions;
5960
import com.arangodb.velocypack.VPackDeserializer;
6061
import com.arangodb.velocypack.VPackParser;
6162
import com.arangodb.velocypack.VPackSlice;
@@ -332,4 +333,8 @@ protected static FieldLink deserializeField(final Entry<String, VPackSlice> fiel
332333
return collectionValidation;
333334
};
334335

336+
public static final VPackDeserializer<ZKDIndexOptions.FieldValueTypes> ZKD_FIELD_VALUE_TYPES =
337+
(parent, vpack, context) -> ZKDIndexOptions.FieldValueTypes.valueOf(vpack.getAsString().toUpperCase(Locale.ENGLISH));
338+
339+
335340
}

src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.arangodb.internal.velocystream.internal.JwtAuthenticationRequest;
3131
import com.arangodb.model.CollectionSchema;
3232
import com.arangodb.model.TraversalOptions;
33+
import com.arangodb.model.ZKDIndexOptions;
3334
import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions;
3435
import com.arangodb.velocypack.VPackModule;
3536
import com.arangodb.velocypack.VPackParserModule;
@@ -70,6 +71,7 @@ public <C extends VPackSetupContext<C>> void setup(final C context) {
7071
context.registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES);
7172
context.registerSerializer(ConsolidationType.class, VPackSerializers.CONSOLIDATE_TYPE);
7273
context.registerSerializer(CollectionSchema.class, VPackSerializers.COLLECTION_VALIDATION);
74+
context.registerSerializer(ZKDIndexOptions.FieldValueTypes.class, VPackSerializers.ZKD_FIELD_VALUE_TYPES);
7375

7476
context.registerDeserializer(Response.class, VPackDeserializers.RESPONSE);
7577
context.registerDeserializer(CollectionType.class, VPackDeserializers.COLLECTION_TYPE);
@@ -89,6 +91,7 @@ public <C extends VPackSetupContext<C>> void setup(final C context) {
8991
context.registerDeserializer(ArangoSearchPropertiesEntity.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES_ENTITY);
9092
context.registerDeserializer(ConsolidationPolicy.class, VPackDeserializers.CONSOLIDATE);
9193
context.registerDeserializer(CollectionSchema.class, VPackDeserializers.COLLECTION_VALIDATION);
94+
context.registerDeserializer(ZKDIndexOptions.FieldValueTypes.class, VPackDeserializers.ZKD_FIELD_VALUE_TYPES);
9295
}
9396

9497
@Override

src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.arangodb.model.CollectionSchema;
4343
import com.arangodb.model.TraversalOptions;
4444
import com.arangodb.model.TraversalOptions.Order;
45+
import com.arangodb.model.ZKDIndexOptions;
4546
import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions;
4647
import com.arangodb.velocypack.VPackBuilder;
4748
import com.arangodb.velocypack.VPackParser;
@@ -285,4 +286,7 @@ private static void serializeFieldLinks(final VPackBuilder builder, final Collec
285286
context.serialize(builder, attribute, doc);
286287
};
287288

289+
public static final VPackSerializer<ZKDIndexOptions.FieldValueTypes> ZKD_FIELD_VALUE_TYPES =
290+
(builder, attribute, value, context) -> builder.add(attribute, value.name().toLowerCase(Locale.ENGLISH));
291+
288292
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public static TtlIndexOptions build(final TtlIndexOptions options, final Iterabl
6565
return options.fields(fields);
6666
}
6767

68+
public static ZKDIndexOptions build(final ZKDIndexOptions options, final Iterable<String> fields) {
69+
return options.fields(fields);
70+
}
71+
6872
public static CollectionCreateOptions build(final CollectionCreateOptions options, final String name) {
6973
return options.name(name);
7074
}

0 commit comments

Comments
 (0)