From 7cc0784c382bc0001b8aa6a48f0d77eab8e697be Mon Sep 17 00:00:00 2001
From: Anush008
Date: Mon, 13 May 2024 12:30:23 +0530
Subject: [PATCH 1/2] fix: Date payload index creation
---
.../java/io/qdrant/client/QdrantClient.java | 21 ++++++++++--
.../java/io/qdrant/client/PointsTest.java | 34 +++++++++++++++----
2 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/src/main/java/io/qdrant/client/QdrantClient.java b/src/main/java/io/qdrant/client/QdrantClient.java
index b311843..5281e52 100644
--- a/src/main/java/io/qdrant/client/QdrantClient.java
+++ b/src/main/java/io/qdrant/client/QdrantClient.java
@@ -2212,6 +2212,9 @@ public ListenableFuture createPayloadIndexAsync(
case Bool:
requestBuilder.setFieldType(FieldType.FieldTypeBool);
break;
+ case Datetime:
+ requestBuilder.setFieldType(FieldType.FieldTypeDatetime);
+ break;
default:
throw new IllegalArgumentException("Invalid schemaType: '" + schemaType + "'");
}
@@ -2224,8 +2227,22 @@ public ListenableFuture createPayloadIndexAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}
- logger.debug("Create payload field index for '{}' in '{}'", field, collectionName);
- ListenableFuture future = getPoints(timeout).createFieldIndex(requestBuilder.build());
+ return createPayloadIndexAsync(requestBuilder.build(), timeout);
+ }
+
+ /**
+ * Creates a payload field index in a collection.
+ *
+ * @param request The create field index request.
+ * @param timeout The timeout for the call.
+ * @return a new instance of {@link ListenableFuture}
+ */
+ public ListenableFuture createPayloadIndexAsync(
+ CreateFieldIndexCollection request,
+ @Nullable Duration timeout
+ ) {
+ logger.debug("Create payload field index for '{}' in '{}'", request.getFieldName(), request.getCollectionName());
+ ListenableFuture future = getPoints(timeout).createFieldIndex(request);
addLogFailureCallback(future, "Create payload field index");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
diff --git a/src/test/java/io/qdrant/client/PointsTest.java b/src/test/java/io/qdrant/client/PointsTest.java
index a2d396e..53f8bbc 100644
--- a/src/test/java/io/qdrant/client/PointsTest.java
+++ b/src/test/java/io/qdrant/client/PointsTest.java
@@ -99,7 +99,7 @@ public void retrieve() throws ExecutionException, InterruptedException {
assertEquals(1, points.size());
RetrievedPoint point = points.get(0);
assertEquals(id(9), point.getId());
- assertEquals(ImmutableSet.of("foo", "bar"), point.getPayloadMap().keySet());
+ assertEquals(ImmutableSet.of("foo", "bar", "date"), point.getPayloadMap().keySet());
assertEquals(value("goodbye"), point.getPayloadMap().get("foo"));
assertEquals(value(2), point.getPayloadMap().get("bar"));
assertEquals(Vectors.getDefaultInstance(), point.getVectors());
@@ -141,7 +141,7 @@ public void setPayload() throws ExecutionException, InterruptedException {
assertEquals(1, points.size());
RetrievedPoint point = points.get(0);
assertEquals(id(9), point.getId());
- assertEquals(ImmutableSet.of("foo", "bar"), point.getPayloadMap().keySet());
+ assertEquals(ImmutableSet.of("foo", "bar", "date"), point.getPayloadMap().keySet());
assertEquals(value("some bar"), point.getPayloadMap().get("bar"));
assertEquals(value("goodbye"), point.getPayloadMap().get("foo"));
}
@@ -188,7 +188,7 @@ public void deletePayload() throws ExecutionException, InterruptedException {
assertEquals(1, points.size());
RetrievedPoint point = points.get(0);
assertEquals(id(9), point.getId());
- assertEquals(ImmutableSet.of("bar"), point.getPayloadMap().keySet());
+ assertEquals(ImmutableSet.of("bar", "date"), point.getPayloadMap().keySet());
assertEquals(value("some bar"), point.getPayloadMap().get("bar"));
}
@@ -239,6 +239,26 @@ public void createFieldIndex() throws ExecutionException, InterruptedException {
assertEquals(PayloadSchemaType.Integer, collectionInfo.getPayloadSchemaMap().get("bar").getDataType());
}
+ @Test
+ public void createDatetimeFieldIndex() throws ExecutionException, InterruptedException {
+ createAndSeedCollection(testName);
+
+ UpdateResult result = client.createPayloadIndexAsync(
+ testName,
+ "date",
+ PayloadSchemaType.Datetime,
+ null,
+ null,
+ null,
+ null).get();
+
+ assertEquals(UpdateStatus.Completed, result.getStatus());
+
+ CollectionInfo collectionInfo = client.getCollectionInfoAsync(testName).get();
+ assertEquals(ImmutableSet.of("date"), collectionInfo.getPayloadSchemaMap().keySet());
+ assertEquals(PayloadSchemaType.Datetime, collectionInfo.getPayloadSchemaMap().get("date").getDataType());
+ }
+
@Test
public void deleteFieldIndex() throws ExecutionException, InterruptedException {
createAndSeedCollection(testName);
@@ -277,7 +297,7 @@ public void search() throws ExecutionException, InterruptedException {
assertEquals(1, points.size());
ScoredPoint point = points.get(0);
assertEquals(id(9), point.getId());
- assertEquals(ImmutableSet.of("foo", "bar"), point.getPayloadMap().keySet());
+ assertEquals(ImmutableSet.of("foo", "bar", "date"), point.getPayloadMap().keySet());
assertEquals(value("goodbye"), point.getPayloadMap().get("foo"));
assertEquals(value(2), point.getPayloadMap().get("bar"));
assertFalse(point.getVectors().hasVector());
@@ -589,7 +609,8 @@ private void createAndSeedCollection(String collectionName) throws ExecutionExce
.setVectors(VectorsFactory.vectors(ImmutableList.of(3.5f, 4.5f)))
.putAllPayload(ImmutableMap.of(
"foo", value("hello"),
- "bar", value(1)
+ "bar", value(1),
+ "date", value("2021-01-01T00:00:00Z")
))
.build(),
PointStruct.newBuilder()
@@ -597,7 +618,8 @@ private void createAndSeedCollection(String collectionName) throws ExecutionExce
.setVectors(VectorsFactory.vectors(ImmutableList.of(10.5f, 11.5f)))
.putAllPayload(ImmutableMap.of(
"foo", value("goodbye"),
- "bar", value(2)
+ "bar", value(2),
+ "date", value("2024-01-02T00:00:00Z")
))
.build()
)).get();
From 849b8dfec7f221a912845390d14da7b553df4f27 Mon Sep 17 00:00:00 2001
From: Anush
Date: Mon, 13 May 2024 12:36:54 +0530
Subject: [PATCH 2/2] Update README.md
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index bd71fd4..73c53b9 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
-
+
# Qdrant Java Client
@@ -184,4 +184,4 @@ List points = client.searchAsync(SearchPoints.newBuilder()
## ⚖️ LICENSE
-Apache 2.0 © [2023](https://github.com/qdrant/java-client/blob/master/LICENSE)
+Apache 2.0 © [2024](https://github.com/qdrant/java-client/blob/master/LICENSE)