Skip to content

Commit

Permalink
v1.8.0 (#26)
Browse files Browse the repository at this point in the history
* v1.8.0

* chore: StartFromFactory

* chore: bump to v1.8.0

* chore: resolve imports
  • Loading branch information
Anush008 authored Mar 6, 2024
1 parent 1678c56 commit 23cfac0
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ tasks.register('downloadProtos') {
def outputDirectory = outputs.files.singleFile.toPath().toString()
def protoFileRegex = Pattern.compile(".*?lib/api/src/grpc/proto/.*?.proto")
try (def httpClient = HttpClients.createDefault()) {
def url = "https://api.github.com/repos/qdrant/qdrant/tarball/refs/tags/${qdrantProtosVersion}"
def url = "https://api.github.com/repos/qdrant/qdrant/tarball/${qdrantProtosVersion}"
logger.debug("downloading protos from {}", url)
def response = httpClient.execute(new HttpGet(url))
try (InputStream tarballStream = response.getEntity().getContent()) {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The version of qdrant to use to download protos
qdrantProtosVersion=v1.7.0
qdrantProtosVersion=v1.8.0

# The version of qdrant docker image to run integration tests against
qdrantVersion=v1.7.0
qdrantVersion=v1.8.0

# The version of the client to generate
packageVersion=1.7.2
packageVersion=1.8.0
18 changes: 18 additions & 0 deletions src/main/java/io/qdrant/client/ConditionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import io.qdrant.client.grpc.Points.Condition;
import io.qdrant.client.grpc.Points.DatetimeRange;
import io.qdrant.client.grpc.Points.FieldCondition;
import io.qdrant.client.grpc.Points.Filter;
import io.qdrant.client.grpc.Points.GeoBoundingBox;
Expand Down Expand Up @@ -370,4 +371,21 @@ public static Condition filter(Filter filter) {
.setFilter(filter)
.build();
}

/**
* Matches records where the given field has a datetime value within the
* specified range
*
* @param field The name of the field.
* @param datetimeRange The datetime range to match.
* @return a new instance of {@link Condition}
*/
public static Condition datetimeRange(String field, DatetimeRange datetimeRange) {
return Condition.newBuilder()
.setField(FieldCondition.newBuilder()
.setKey(field)
.setDatetimeRange(datetimeRange)
.build())
.build();
}
}
100 changes: 100 additions & 0 deletions src/main/java/io/qdrant/client/QdrantClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.qdrant.client.grpc.Collections.AliasOperations;
import io.qdrant.client.grpc.Collections.ChangeAliases;
import io.qdrant.client.grpc.Collections.CollectionDescription;
import io.qdrant.client.grpc.Collections.CollectionExistsRequest;
import io.qdrant.client.grpc.Collections.CollectionExistsResponse;
import io.qdrant.client.grpc.Collections.CollectionInfo;
import io.qdrant.client.grpc.Collections.CollectionOperationResponse;
import io.qdrant.client.grpc.Collections.CreateAlias;
Expand Down Expand Up @@ -476,6 +478,33 @@ public ListenableFuture<CollectionOperationResponse> updateCollectionAsync(Updat
}, MoreExecutors.directExecutor());
}

/**
* Check if a collection exists
*
* @param collectionName The name of the collection.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<Boolean> collectionExistsAsync(String collectionName) {
return collectionExistsAsync(collectionName, null);
}

/**
* Check if a collection exists
*
* @param collectionName The name of the collection.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<Boolean> collectionExistsAsync(String collectionName, @Nullable Duration timeout) {
Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
logger.debug("Collection exists '{}'", collectionName);

ListenableFuture<CollectionExistsResponse> future = getCollections(timeout)
.collectionExists(CollectionExistsRequest.newBuilder().setCollectionName(collectionName).build());
addLogFailureCallback(future, "Collection exists");
return Futures.transform(future, response -> response.getResult().getExists(), MoreExecutors.directExecutor());
}

//endregion

//region Alias Management
Expand Down Expand Up @@ -1515,6 +1544,38 @@ public ListenableFuture<UpdateResult> setPayloadAsync(
@Nullable Boolean wait,
@Nullable WriteOrderingType ordering,
@Nullable Duration timeout
) {
return setPayloadAsync(
collectionName,
payload,
pointsSelector,
wait,
null,
ordering,
timeout
);
}

/**
* Sets the payload for the points.
*
* @param collectionName The name of the collection.
* @param payload New payload values
* @param pointsSelector Selector for the points whose payloads are to be set.
* @param wait Whether to wait until the changes have been applied. Defaults to <code>true</code>.
* @param key The key for which to set the payload if nested
* @param ordering Write ordering guarantees.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<UpdateResult> setPayloadAsync(
String collectionName,
Map<String, Value> payload,
@Nullable PointsSelector pointsSelector,
@Nullable Boolean wait,
@Nullable String key,
@Nullable WriteOrderingType ordering,
@Nullable Duration timeout
) {
SetPayloadPoints.Builder requestBuilder = SetPayloadPoints.newBuilder()
.setCollectionName(collectionName)
Expand All @@ -1529,6 +1590,10 @@ public ListenableFuture<UpdateResult> setPayloadAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

if (key != null) {
requestBuilder.setKey(key);
}

return setPayloadAsync(requestBuilder.build(), timeout);
}

Expand Down Expand Up @@ -1687,6 +1752,38 @@ public ListenableFuture<UpdateResult> overwritePayloadAsync(
@Nullable Boolean wait,
@Nullable WriteOrderingType ordering,
@Nullable Duration timeout
) {
return overwritePayloadAsync(
collectionName,
payload,
pointsSelector,
wait,
null,
ordering,
timeout
);
}

/**
* Overwrites the payload for the points.
*
* @param collectionName The name of the collection.
* @param payload New payload values
* @param pointsSelector Selector for the points whose payloads are to be overwritten.
* @param wait Whether to wait until the changes have been applied. Defaults to <code>true</code>.
* @param key The key for which to overwrite the payload if nested
* @param ordering Write ordering guarantees.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<UpdateResult> overwritePayloadAsync(
String collectionName,
Map<String, Value> payload,
@Nullable PointsSelector pointsSelector,
@Nullable Boolean wait,
@Nullable String key,
@Nullable WriteOrderingType ordering,
@Nullable Duration timeout
) {
SetPayloadPoints.Builder requestBuilder = SetPayloadPoints.newBuilder()
.setCollectionName(collectionName)
Expand All @@ -1701,6 +1798,9 @@ public ListenableFuture<UpdateResult> overwritePayloadAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

if (key != null)
requestBuilder.setKey(key);

return overwritePayloadAsync(requestBuilder.build(), timeout);
}

Expand Down
65 changes: 65 additions & 0 deletions src/main/java/io/qdrant/client/StartFromFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.qdrant.client;

import java.time.Instant;

import com.google.protobuf.Timestamp;

import io.qdrant.client.grpc.Points.StartFrom;

/**
* Convenience methods for constructing {@link StartFrom}
*/
public final class StartFromFactory {
private StartFromFactory() {
}

/**
* Creates a {@link StartFrom} value from a {@link float}
*
* @param value The value
* @return a new instance of {@link StartFrom}
*/
public static StartFrom startFrom(float value) {
return StartFrom.newBuilder().setFloat(value).build();
}

/**
* Creates a {@link StartFrom} value from a {@link int}
*
* @param value The value
* @return a new instance of {@link StartFrom}
*/
public static StartFrom startFrom(int value) {
return StartFrom.newBuilder().setInteger(value).build();
}

/**
* Creates a {@link StartFrom} value from a {@link String} timestamp
*
* @param value The value
* @return a new instance of {@link StartFrom}
*/
public static StartFrom startFrom(String value) {
return StartFrom.newBuilder().setDatetime(value).build();
}

/**
* Creates a {@link StartFrom} value from a {@link Timestamp}
*
* @param value The value
* @return a new instance of {@link StartFrom}
*/
public static StartFrom startFrom(Timestamp value) {
return StartFrom.newBuilder().setTimestamp(value).build();
}

/**
* Creates a {@link StartFrom} value from a {@link Timestamp}
*
* @param value The value
* @return a new instance of {@link StartFrom}
*/
public static StartFrom startFrom(Instant value) {
return StartFrom.newBuilder().setTimestamp(Timestamp.newBuilder().setSeconds(value.getEpochSecond())).build();
}
}
13 changes: 13 additions & 0 deletions src/test/java/io/qdrant/client/CollectionsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.qdrant.client;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -180,6 +181,18 @@ public void getCollectionInfo_with_missing_collection() {
assertEquals(Status.Code.NOT_FOUND, underlyingException.getStatus().getCode());
}

@Test
public void collectionExists() throws ExecutionException, InterruptedException {
assertFalse(client.collectionExistsAsync(testName).get());

CreateCollection createCollection = getCreateCollection(testName);
client.createCollectionAsync(createCollection).get();
assertTrue(client.collectionExistsAsync(testName).get());

client.deleteCollectionAsync(testName).get();
assertFalse(client.collectionExistsAsync(testName).get());
}

@Test
public void createAlias() throws ExecutionException, InterruptedException {
CreateCollection createCollection = getCreateCollection(testName);
Expand Down

0 comments on commit 23cfac0

Please sign in to comment.