Skip to content

Commit 6a2e33c

Browse files
authored
fix: Datetime index creation (#37)
1 parent cf1c3af commit 6a2e33c

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a href="https://github.com/qdrant/java-client/actions/workflows/cd.yml"><img src="https://github.com/qdrant/java-client/actions/workflows/cd.yml/badge.svg?branch=master" alt="Tests"></a>
1515
<a href="https://github.com/qdrant/java-client/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-success" alt="Apache 2.0 License"></a>
1616
<a href="https://qdrant.to/discord"><img src="https://img.shields.io/badge/Discord-Qdrant-5865F2.svg?logo=discord" alt="Discord"></a>
17-
<a href="https://qdrant.to/roadmap"><img src="https://img.shields.io/badge/Roadmap-2023-bc1439.svg" alt="Roadmap 2023"></a>
17+
<a href="https://qdrant.to/roadmap"><img src="https://img.shields.io/badge/Roadmap-2024-bc1439.svg" alt="Roadmap 2024"></a>
1818
</p>
1919

2020
# Qdrant Java Client
@@ -184,4 +184,4 @@ List<ScoredPoint> points = client.searchAsync(SearchPoints.newBuilder()
184184

185185
## ⚖️ LICENSE
186186

187-
Apache 2.0 © [2023](https://github.com/qdrant/java-client/blob/master/LICENSE)
187+
Apache 2.0 © [2024](https://github.com/qdrant/java-client/blob/master/LICENSE)

src/main/java/io/qdrant/client/QdrantClient.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,9 @@ public ListenableFuture<UpdateResult> createPayloadIndexAsync(
22122212
case Bool:
22132213
requestBuilder.setFieldType(FieldType.FieldTypeBool);
22142214
break;
2215+
case Datetime:
2216+
requestBuilder.setFieldType(FieldType.FieldTypeDatetime);
2217+
break;
22152218
default:
22162219
throw new IllegalArgumentException("Invalid schemaType: '" + schemaType + "'");
22172220
}
@@ -2224,8 +2227,22 @@ public ListenableFuture<UpdateResult> createPayloadIndexAsync(
22242227
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
22252228
}
22262229

2227-
logger.debug("Create payload field index for '{}' in '{}'", field, collectionName);
2228-
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).createFieldIndex(requestBuilder.build());
2230+
return createPayloadIndexAsync(requestBuilder.build(), timeout);
2231+
}
2232+
2233+
/**
2234+
* Creates a payload field index in a collection.
2235+
*
2236+
* @param request The create field index request.
2237+
* @param timeout The timeout for the call.
2238+
* @return a new instance of {@link ListenableFuture}
2239+
*/
2240+
public ListenableFuture<UpdateResult> createPayloadIndexAsync(
2241+
CreateFieldIndexCollection request,
2242+
@Nullable Duration timeout
2243+
) {
2244+
logger.debug("Create payload field index for '{}' in '{}'", request.getFieldName(), request.getCollectionName());
2245+
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).createFieldIndex(request);
22292246
addLogFailureCallback(future, "Create payload field index");
22302247
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
22312248
}

src/test/java/io/qdrant/client/PointsTest.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void retrieve() throws ExecutionException, InterruptedException {
9999
assertEquals(1, points.size());
100100
RetrievedPoint point = points.get(0);
101101
assertEquals(id(9), point.getId());
102-
assertEquals(ImmutableSet.of("foo", "bar"), point.getPayloadMap().keySet());
102+
assertEquals(ImmutableSet.of("foo", "bar", "date"), point.getPayloadMap().keySet());
103103
assertEquals(value("goodbye"), point.getPayloadMap().get("foo"));
104104
assertEquals(value(2), point.getPayloadMap().get("bar"));
105105
assertEquals(Vectors.getDefaultInstance(), point.getVectors());
@@ -141,7 +141,7 @@ public void setPayload() throws ExecutionException, InterruptedException {
141141
assertEquals(1, points.size());
142142
RetrievedPoint point = points.get(0);
143143
assertEquals(id(9), point.getId());
144-
assertEquals(ImmutableSet.of("foo", "bar"), point.getPayloadMap().keySet());
144+
assertEquals(ImmutableSet.of("foo", "bar", "date"), point.getPayloadMap().keySet());
145145
assertEquals(value("some bar"), point.getPayloadMap().get("bar"));
146146
assertEquals(value("goodbye"), point.getPayloadMap().get("foo"));
147147
}
@@ -188,7 +188,7 @@ public void deletePayload() throws ExecutionException, InterruptedException {
188188
assertEquals(1, points.size());
189189
RetrievedPoint point = points.get(0);
190190
assertEquals(id(9), point.getId());
191-
assertEquals(ImmutableSet.of("bar"), point.getPayloadMap().keySet());
191+
assertEquals(ImmutableSet.of("bar", "date"), point.getPayloadMap().keySet());
192192
assertEquals(value("some bar"), point.getPayloadMap().get("bar"));
193193
}
194194

@@ -239,6 +239,26 @@ public void createFieldIndex() throws ExecutionException, InterruptedException {
239239
assertEquals(PayloadSchemaType.Integer, collectionInfo.getPayloadSchemaMap().get("bar").getDataType());
240240
}
241241

242+
@Test
243+
public void createDatetimeFieldIndex() throws ExecutionException, InterruptedException {
244+
createAndSeedCollection(testName);
245+
246+
UpdateResult result = client.createPayloadIndexAsync(
247+
testName,
248+
"date",
249+
PayloadSchemaType.Datetime,
250+
null,
251+
null,
252+
null,
253+
null).get();
254+
255+
assertEquals(UpdateStatus.Completed, result.getStatus());
256+
257+
CollectionInfo collectionInfo = client.getCollectionInfoAsync(testName).get();
258+
assertEquals(ImmutableSet.of("date"), collectionInfo.getPayloadSchemaMap().keySet());
259+
assertEquals(PayloadSchemaType.Datetime, collectionInfo.getPayloadSchemaMap().get("date").getDataType());
260+
}
261+
242262
@Test
243263
public void deleteFieldIndex() throws ExecutionException, InterruptedException {
244264
createAndSeedCollection(testName);
@@ -277,7 +297,7 @@ public void search() throws ExecutionException, InterruptedException {
277297
assertEquals(1, points.size());
278298
ScoredPoint point = points.get(0);
279299
assertEquals(id(9), point.getId());
280-
assertEquals(ImmutableSet.of("foo", "bar"), point.getPayloadMap().keySet());
300+
assertEquals(ImmutableSet.of("foo", "bar", "date"), point.getPayloadMap().keySet());
281301
assertEquals(value("goodbye"), point.getPayloadMap().get("foo"));
282302
assertEquals(value(2), point.getPayloadMap().get("bar"));
283303
assertFalse(point.getVectors().hasVector());
@@ -589,15 +609,17 @@ private void createAndSeedCollection(String collectionName) throws ExecutionExce
589609
.setVectors(VectorsFactory.vectors(ImmutableList.of(3.5f, 4.5f)))
590610
.putAllPayload(ImmutableMap.of(
591611
"foo", value("hello"),
592-
"bar", value(1)
612+
"bar", value(1),
613+
"date", value("2021-01-01T00:00:00Z")
593614
))
594615
.build(),
595616
PointStruct.newBuilder()
596617
.setId(id(9))
597618
.setVectors(VectorsFactory.vectors(ImmutableList.of(10.5f, 11.5f)))
598619
.putAllPayload(ImmutableMap.of(
599620
"foo", value("goodbye"),
600-
"bar", value(2)
621+
"bar", value(2),
622+
"date", value("2024-01-02T00:00:00Z")
601623
))
602624
.build()
603625
)).get();

0 commit comments

Comments
 (0)