Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Datetime index creation #37

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<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>
<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>
<a href="https://qdrant.to/discord"><img src="https://img.shields.io/badge/Discord-Qdrant-5865F2.svg?logo=discord" alt="Discord"></a>
<a href="https://qdrant.to/roadmap"><img src="https://img.shields.io/badge/Roadmap-2023-bc1439.svg" alt="Roadmap 2023"></a>
<a href="https://qdrant.to/roadmap"><img src="https://img.shields.io/badge/Roadmap-2024-bc1439.svg" alt="Roadmap 2024"></a>
</p>

# Qdrant Java Client
Expand Down Expand Up @@ -184,4 +184,4 @@ List<ScoredPoint> 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)
21 changes: 19 additions & 2 deletions src/main/java/io/qdrant/client/QdrantClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,9 @@ public ListenableFuture<UpdateResult> createPayloadIndexAsync(
case Bool:
requestBuilder.setFieldType(FieldType.FieldTypeBool);
break;
case Datetime:
requestBuilder.setFieldType(FieldType.FieldTypeDatetime);
break;
default:
throw new IllegalArgumentException("Invalid schemaType: '" + schemaType + "'");
}
Expand All @@ -2224,8 +2227,22 @@ public ListenableFuture<UpdateResult> createPayloadIndexAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

logger.debug("Create payload field index for '{}' in '{}'", field, collectionName);
ListenableFuture<PointsOperationResponse> 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<UpdateResult> createPayloadIndexAsync(
CreateFieldIndexCollection request,
@Nullable Duration timeout
) {
logger.debug("Create payload field index for '{}' in '{}'", request.getFieldName(), request.getCollectionName());
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).createFieldIndex(request);
addLogFailureCallback(future, "Create payload field index");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
Expand Down
34 changes: 28 additions & 6 deletions src/test/java/io/qdrant/client/PointsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -589,15 +609,17 @@ 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()
.setId(id(9))
.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();
Expand Down
Loading