Skip to content

Commit 78d4fe7

Browse files
committed
feat: add data.exists method
1 parent 870c5a4 commit 78d4fe7

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/it/java/io/weaviate/integration/DataITest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public void testCreateGetDelete() throws IOException {
4545
.returnProperties("name")
4646
.returnMetadata(Metadata.ID, Metadata.VECTOR));
4747

48+
Assertions.assertThat(artists.data.exists(id))
49+
.as("object exists after insert").isTrue();
4850
Assertions.assertThat(object)
49-
.as("object exists after insert").get()
51+
.as("object has correct properties").get()
5052
.satisfies(obj -> {
5153
Assertions.assertThat(obj.metadata().uuid())
5254
.as("object id").isEqualTo(id);
@@ -60,8 +62,8 @@ public void testCreateGetDelete() throws IOException {
6062
});
6163

6264
artists.data.delete(id);
63-
object = artists.query.byId(id);
64-
Assertions.assertThat(object).isEmpty().as("object not exists after deletion");
65+
Assertions.assertThat(artists.data.exists(id))
66+
.as("object not exists after deletion").isFalse();
6567
}
6668

6769
@Test
@@ -175,4 +177,12 @@ public void testReferences_AddReplaceDelete() throws IOException {
175177
.asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class))
176178
.isEmpty();
177179
}
180+
181+
@Test
182+
public void testReplace() {
183+
}
184+
185+
@Test
186+
public void testUpdate() {
187+
}
178188
}

src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public CollectionHandle(
2020
CollectionDescriptor<T> collectionDescriptor) {
2121

2222
this.config = new WeaviateConfigClient(collectionDescriptor, restTransport, grpcTransport);
23-
this.data = new WeaviateDataClient<>(collectionDescriptor, restTransport);
2423
this.query = new WeaviateQueryClient<>(collectionDescriptor, grpcTransport);
24+
this.data = new WeaviateDataClient<>(collectionDescriptor, restTransport, this.query);
2525
this.aggregate = new WeaviateAggregateClient(collectionDescriptor, grpcTransport);
2626
}
2727
}

src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public CollectionHandleAsync(
2020
CollectionDescriptor<T> collectionDescriptor) {
2121

2222
this.config = new WeaviateConfigClientAsync(collectionDescriptor, restTransport, grpcTransport);
23-
this.data = new WeaviateDataClientAsync<>(collectionDescriptor, restTransport);
2423
this.query = new WeaviateQueryClientAsync<>(collectionDescriptor, grpcTransport);
24+
this.data = new WeaviateDataClientAsync<>(collectionDescriptor, restTransport, this.query);
2525
this.aggregate = new WeaviateAggregateClientAsync(collectionDescriptor, grpcTransport);
2626
}
2727
}

src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import io.weaviate.client6.v1.api.collections.ObjectMetadata;
77
import io.weaviate.client6.v1.api.collections.WeaviateObject;
8+
import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient;
89
import io.weaviate.client6.v1.internal.ObjectBuilder;
910
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
1011
import io.weaviate.client6.v1.internal.rest.RestTransport;
@@ -13,9 +14,13 @@ public class WeaviateDataClient<T> {
1314
private final RestTransport restTransport;
1415
private final CollectionDescriptor<T> collectionDescriptor;
1516

16-
public WeaviateDataClient(CollectionDescriptor<T> collectionDescriptor, RestTransport restTransport) {
17+
private final WeaviateQueryClient<T> query;
18+
19+
public WeaviateDataClient(CollectionDescriptor<T> collectionDescriptor, RestTransport restTransport,
20+
WeaviateQueryClient<T> query) {
1721
this.restTransport = restTransport;
1822
this.collectionDescriptor = collectionDescriptor;
23+
this.query = query;
1924
}
2025

2126
public WeaviateObject<T, Object, ObjectMetadata> insert(T properties) throws IOException {
@@ -32,6 +37,10 @@ public WeaviateObject<T, Object, ObjectMetadata> insert(InsertObjectRequest<T> r
3237
return this.restTransport.performRequest(request, InsertObjectRequest.endpoint(collectionDescriptor));
3338
}
3439

40+
public boolean exists(String uuid) throws IOException {
41+
return this.query.byId(uuid).isPresent();
42+
}
43+
3544
public void delete(String uuid) throws IOException {
3645
this.restTransport.performRequest(new DeleteObjectRequest(collectionDescriptor.name(), uuid),
3746
DeleteObjectRequest._ENDPOINT);

src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import java.io.IOException;
44
import java.util.Collection;
5+
import java.util.Optional;
56
import java.util.concurrent.CompletableFuture;
67
import java.util.function.Function;
78

89
import io.weaviate.client6.v1.api.collections.ObjectMetadata;
910
import io.weaviate.client6.v1.api.collections.WeaviateObject;
11+
import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClientAsync;
1012
import io.weaviate.client6.v1.internal.ObjectBuilder;
1113
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
1214
import io.weaviate.client6.v1.internal.rest.RestTransport;
@@ -15,9 +17,13 @@ public class WeaviateDataClientAsync<T> {
1517
private final RestTransport restTransport;
1618
private final CollectionDescriptor<T> collectionDescriptor;
1719

18-
public WeaviateDataClientAsync(CollectionDescriptor<T> collectionDescriptor, RestTransport restTransport) {
20+
private final WeaviateQueryClientAsync<T> query;
21+
22+
public WeaviateDataClientAsync(CollectionDescriptor<T> collectionDescriptor, RestTransport restTransport,
23+
WeaviateQueryClientAsync<T> query) {
1924
this.restTransport = restTransport;
2025
this.collectionDescriptor = collectionDescriptor;
26+
this.query = query;
2127
}
2228

2329
public CompletableFuture<WeaviateObject<T, Object, ObjectMetadata>> insert(T properties) throws IOException {
@@ -35,6 +41,10 @@ public CompletableFuture<WeaviateObject<T, Object, ObjectMetadata>> insert(Inser
3541
return this.restTransport.performRequestAsync(request, InsertObjectRequest.endpoint(collectionDescriptor));
3642
}
3743

44+
public CompletableFuture<Boolean> exists(String uuid) {
45+
return this.query.byId(uuid).thenApply(Optional::isPresent);
46+
}
47+
3848
public CompletableFuture<Void> delete(String uuid) {
3949
return this.restTransport.performRequestAsync(new DeleteObjectRequest(collectionDescriptor.name(), uuid),
4050
DeleteObjectRequest._ENDPOINT);

0 commit comments

Comments
 (0)