Skip to content

Commit 5884e27

Browse files
authored
Merge branch 'v6' into v6-weaviate-object
2 parents 56037f0 + e410c07 commit 5884e27

24 files changed

Lines changed: 329 additions & 57 deletions

src/it/java/io/weaviate/containers/Weaviate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ public Builder withApiKeys(String... apiKeys) {
197197
return this;
198198
}
199199

200+
public Builder withGrpcMaxMessageSize(int bytes) {
201+
environment.put("GRPC_MAX_MESSAGE_SIZE", String.valueOf(bytes));
202+
return this;
203+
}
204+
200205
public Builder enableTelemetry(boolean enable) {
201206
environment.put("DISABLE_TELEMETRY", Boolean.toString(!enable));
202207
return this;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ public void test_aliasLifecycle() throws IOException {
4848
.returns(nsColsonBaker, Alias::collection);
4949

5050
// Act: delete Bono alias
51-
client.alias.delete("Bono");
51+
var deleted = client.alias.delete("Bono");
52+
Assertions.assertThat(deleted).as("object was deleted").isTrue();
5253

53-
// Assert
54+
// Act: delete non-existent alias
55+
deleted = client.alias.delete("Bono");
56+
Assertions.assertThat(deleted).as("object wasn't deleted").isFalse();
5457
var paulHewsonAliases = client.alias.list(all -> all.collection(nsPaulHewson));
5558
Assertions.assertThat(paulHewsonAliases)
5659
.as("no aliases once Bono is deleted")

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ public void testCreateGetDelete() throws IOException {
7979
.as("lastUpdateTimeUnix").isNotNull();
8080
});
8181

82-
artists.data.delete(id);
82+
var deleted = artists.data.deleteById(id);
83+
Assertions.assertThat(deleted)
84+
.as("object was deleted").isTrue();
8385
Assertions.assertThat(artists.data.exists(id))
8486
.as("object not exists after deletion").isFalse();
87+
88+
deleted = artists.data.deleteById(id);
89+
// TODO: Change to isFalse() after fixed in Weaviate server
90+
Assertions.assertThat(deleted)
91+
.as("object wasn't deleted").isTrue();
8592
}
8693

8794
@Test

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,30 +206,54 @@ public void test_users_db() throws IOException {
206206
.extracting(Role::name)
207207
.doesNotContain(roleName);
208208

209-
client.users.db.activate(userId);
209+
var deactivated = client.users.db.deactivate(userId);
210+
Assertions.assertThat(deactivated)
211+
.as("user was deactivated")
212+
.isTrue();
213+
Assertions.assertThat(client.users.db.byName(userId)).get()
214+
.as("user is deactivated")
215+
.returns(false, DbUser::active);
216+
217+
deactivated = client.users.db.deactivate(userId);
218+
Assertions.assertThat(deactivated)
219+
.as("user was already deactivated")
220+
.isFalse();
221+
222+
var activated = client.users.db.activate(userId);
223+
Assertions.assertThat(activated)
224+
.as("user was activated")
225+
.isTrue();
210226
Assertions.assertThat(client.users.db.byName(userId)).get()
211227
.as("user is activated")
212228
.returns(true, DbUser::active);
213229

230+
activated = client.users.db.activate(userId);
231+
Assertions.assertThat(activated)
232+
.as("user was already active")
233+
.isFalse();
234+
214235
apiKey = client.users.db.rotateKey(userId);
215236
assertValidApiKey(apiKey);
216237

217-
client.users.db.deactivate(userId);
218-
Assertions.assertThat(client.users.db.byName(userId)).get()
219-
.as("user is deactivated")
220-
.returns(false, DbUser::active);
221-
222238
var all = client.users.db.list(users -> users.includeLastUsedAt(true));
223239
Assertions.assertThat(all)
224240
.as("list users include lastUsedTime ")
225241
.allMatch(user -> user.lastUsedAt() != null)
226242
.extracting(DbUser::id)
227243
.contains(userId, ADMIN_USER);
228244

229-
client.users.db.delete(userId);
245+
var deleted = client.users.db.delete(userId);
246+
Assertions.assertThat(deleted)
247+
.as("user was deleted")
248+
.isTrue();
230249
Assertions.assertThat(client.users.db.byName(userId))
231250
.as("user is deleted")
232251
.isEmpty();
252+
253+
deleted = client.users.db.delete(userId);
254+
Assertions.assertThat(deleted)
255+
.as("user was already deleted")
256+
.isFalse();
233257
}
234258

235259
@Test

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

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.weaviate.integration;
22

33
import java.io.IOException;
4+
import java.time.OffsetDateTime;
45
import java.util.Collections;
56
import java.util.Comparator;
67
import java.util.HashMap;
@@ -13,6 +14,7 @@
1314
import org.assertj.core.api.InstanceOfAssertFactories;
1415
import org.junit.BeforeClass;
1516
import org.junit.ClassRule;
17+
import org.junit.Ignore;
1618
import org.junit.Test;
1719
import org.junit.rules.TestRule;
1820

@@ -29,14 +31,14 @@
2931
import io.weaviate.client6.v1.api.collections.generate.GenerativeObject;
3032
import io.weaviate.client6.v1.api.collections.generate.TaskOutput;
3133
import io.weaviate.client6.v1.api.collections.generative.DummyGenerative;
34+
import io.weaviate.client6.v1.api.collections.query.Filter;
3235
import io.weaviate.client6.v1.api.collections.query.GroupBy;
3336
import io.weaviate.client6.v1.api.collections.query.Metadata;
3437
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
3538
import io.weaviate.client6.v1.api.collections.query.QueryResponseGroup;
3639
import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject;
3740
import io.weaviate.client6.v1.api.collections.query.SortBy;
3841
import io.weaviate.client6.v1.api.collections.query.Target;
39-
import io.weaviate.client6.v1.api.collections.query.Filter;
4042
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
4143
import io.weaviate.client6.v1.api.collections.vectorindex.MultiVector;
4244
import io.weaviate.containers.Container;
@@ -671,4 +673,97 @@ public void testGenerative_bm25_groupBy() throws IOException {
671673
.extracting(TaskOutput::text, InstanceOfAssertFactories.STRING)
672674
.isNotBlank();
673675
}
676+
677+
@Test
678+
public void test_filterIsNull() throws IOException {
679+
// Arrange
680+
var nsNulls = ns("Nulls");
681+
682+
var nulls = client.collections.create(nsNulls,
683+
c -> c
684+
.invertedIndex(idx -> idx.indexNulls(true))
685+
.properties(Property.text("never")));
686+
687+
var inserted = nulls.data.insertMany(Map.of(), Map.of("never", "notNull"));
688+
Assertions.assertThat(inserted.errors()).isEmpty();
689+
690+
// Act
691+
var isNull = nulls.query.fetchObjects(q -> q.filters(Filter.property("never").isNull()));
692+
var isNotNull = nulls.query.fetchObjects(q -> q.filters(Filter.property("never").isNotNull()));
693+
694+
// Assert
695+
var isNull_1 = Assertions.assertThat(isNull.objects())
696+
.as("objects WHERE never IS NULL")
697+
.hasSize(1).first().actual();
698+
var isNotNull_1 = Assertions.assertThat(isNotNull.objects())
699+
.as("objects WHERE never IS NOT NULL")
700+
.hasSize(1).first().actual();
701+
Assertions.assertThat(isNull_1).isNotEqualTo(isNotNull_1);
702+
}
703+
704+
@Test
705+
public void test_filterCreateUpdateTime() throws IOException {
706+
// Arrange
707+
var now = OffsetDateTime.now().minusHours(1);
708+
var nsCounter = ns("Counter");
709+
710+
var counter = client.collections.create(nsCounter,
711+
c -> c
712+
.invertedIndex(idx -> idx.indexTimestamps(true))
713+
.properties(Property.integer("count")));
714+
715+
counter.data.insert(Map.of("count", 0));
716+
717+
// Act
718+
var beforeNow = counter.query.fetchObjects(q -> q.filters(Filter.createdAt().lt(now)));
719+
var afterNow = counter.query.fetchObjects(q -> q.filters(Filter.createdAt().gt(now)));
720+
721+
// Assert
722+
Assertions.assertThat(beforeNow.objects()).isEmpty();
723+
Assertions.assertThat(afterNow.objects()).hasSize(1);
724+
}
725+
726+
@Test
727+
public void teset_filterPropertyLength() throws IOException {
728+
// Arrange
729+
var nsStrings = ns("Strings");
730+
731+
var strings = client.collections.create(nsStrings, c -> c
732+
.invertedIndex(idx -> idx.indexPropertyLength(true))
733+
.properties(Property.text("letters")));
734+
strings.data.insertMany(Map.of("letters", "abc"), Map.of("letters", "abcd"), Map.of("letters", "a"));
735+
736+
// Act
737+
var got = strings.query.fetchObjects(q -> q.filters(Filter.propertyLen("letters").gte(3)));
738+
739+
// Assertions
740+
Assertions.assertThat(got.objects()).hasSize(2);
741+
}
742+
743+
/**
744+
* Ensure the client respects server's configuration for max gRPC size:
745+
* we create a server with 1-byte message size and try to send a large payload
746+
* there. If the channel is configured correctly, it will refuse to send it.
747+
*/
748+
@Test
749+
@Ignore("Exception thrown by gRPC transport causes a deadlock")
750+
public void test_maxGrpcMessageSize() throws Exception {
751+
var w = Weaviate.custom().withGrpcMaxMessageSize(1).build();
752+
var nsHugeVectors = ns("HugeVectors");
753+
754+
try (final var _client = w.getClient()) {
755+
var huge = _client.collections.create(nsHugeVectors, c -> c
756+
.vectorConfig(VectorConfig.selfProvided()));
757+
758+
final var vector = randomVector(5000, -.01f, .01f);
759+
final WeaviateObject<Map<String, Object>, Reference, ObjectMetadata> hugeObject = WeaviateObject.of(obj -> obj
760+
.metadata(ObjectMetadata.of(m -> m
761+
.vectors(Vectors.of(vector)))));
762+
763+
Assertions.assertThatThrownBy(() -> {
764+
// insertMany to route this request through gRPC.
765+
huge.data.insertMany(hugeObject);
766+
}).isInstanceOf(io.grpc.StatusRuntimeException.class);
767+
}
768+
}
674769
}

src/main/java/io/weaviate/client6/v1/api/alias/DeleteAliasRequest.java

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

33
import java.util.Collections;
44

5+
import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
56
import io.weaviate.client6.v1.internal.rest.Endpoint;
6-
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
77

88
public record DeleteAliasRequest(String alias) {
9-
public final static Endpoint<DeleteAliasRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect(
9+
public final static Endpoint<DeleteAliasRequest, Boolean> _ENDPOINT = BooleanEndpoint.noBody(
1010
__ -> "DELETE",
1111
request -> "/aliases/" + request.alias,
1212
__ -> Collections.emptyMap());

src/main/java/io/weaviate/client6/v1/api/alias/WeaviateAliasClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ public void update(String alias, String newTargetCollection) throws IOException
117117
* @throws IOException in case the request was not sent successfully
118118
* due to a malformed request, a networking error
119119
* or the server being unavailable.
120+
*
121+
* @return {@code true} if the alias was deleted, {@code false} if there was no
122+
* alias to delete.
120123
*/
121-
public void delete(String alias) throws IOException {
122-
this.restTransport.performRequest(new DeleteAliasRequest(alias), DeleteAliasRequest._ENDPOINT);
124+
public boolean delete(String alias) throws IOException {
125+
return this.restTransport.performRequest(new DeleteAliasRequest(alias), DeleteAliasRequest._ENDPOINT);
123126
}
124127
}

src/main/java/io/weaviate/client6/v1/api/alias/WeaviateAliasClientAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public CompletableFuture<Void> update(String alias, String newTargetCollection)
9494
*
9595
* @return A future holding the server's response.
9696
*/
97-
public CompletableFuture<Void> delete(String alias) {
97+
public CompletableFuture<Boolean> delete(String alias) {
9898
return this.restTransport.performRequestAsync(new DeleteAliasRequest(alias), DeleteAliasRequest._ENDPOINT);
9999
}
100100
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
44
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
5+
import io.weaviate.client6.v1.internal.rest.BooleanEndpoint;
56
import io.weaviate.client6.v1.internal.rest.Endpoint;
6-
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
77

88
public record DeleteObjectRequest(String uuid) {
99

10-
public static final Endpoint<DeleteObjectRequest, Void> endpoint(
10+
public static final Endpoint<DeleteObjectRequest, Boolean> endpoint(
1111
CollectionDescriptor<?> collection,
1212
CollectionHandleDefaults defaults) {
13-
return SimpleEndpoint.sideEffect(
13+
return BooleanEndpoint.noBody(
1414
request -> "DELETE",
1515
request -> "/objects/" + collection.collectionName() + "/" + request.uuid,
1616
request -> defaults.queryParameters());

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ public void replace(
9898
ReplaceObjectRequest.endpoint(collection, defaults));
9999
}
100100

101-
public void delete(String uuid) throws IOException {
102-
this.restTransport.performRequest(new DeleteObjectRequest(uuid),
101+
/**
102+
* Delete an object by its UUID.
103+
*
104+
* @param uuid The UUID of the object to delete.
105+
* @return {@code true} if the object was deleted, {@code false} if there was no object to delete.
106+
* @throws IOException in case the request was not sent successfully.
107+
*/
108+
public boolean deleteById(String uuid) throws IOException {
109+
return this.restTransport.performRequest(new DeleteObjectRequest(uuid),
103110
DeleteObjectRequest.endpoint(collection, defaults));
104111
}
105112

0 commit comments

Comments
 (0)