From 1e3304b3880f040f23b3ac6f4f98b78ff42090d2 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Fri, 3 Oct 2025 13:14:43 +0200 Subject: [PATCH 1/2] test: drop flaky part of the Sort test --- .../io/weaviate/integration/SearchITest.java | 35 ++----------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/it/java/io/weaviate/integration/SearchITest.java b/src/it/java/io/weaviate/integration/SearchITest.java index 418fb3189..f757b72ad 100644 --- a/src/it/java/io/weaviate/integration/SearchITest.java +++ b/src/it/java/io/weaviate/integration/SearchITest.java @@ -269,9 +269,9 @@ public void testFetchObjectsWithSort() throws Exception { var numbers = client.collections.use(nsNumbers); - var one = numbers.data.insert(Map.of("value", 1L)); - var two = numbers.data.insert(Map.of("value", 2L)); - var three = numbers.data.insert(Map.of("value", 3L)); + numbers.data.insert(Map.of("value", 1L)); + numbers.data.insert(Map.of("value", 2L)); + numbers.data.insert(Map.of("value", 3L)); // Act: sort ascending var asc = numbers.query.fetchObjects( @@ -294,35 +294,6 @@ public void testFetchObjectsWithSort() throws Exception { .extracting(WeaviateObject::properties) .extracting(object -> object.get("value")) .containsExactly(3L, 2L, 1L); - - // Act: sort by creation time asc - var created = numbers.query.fetchObjects( - q -> q.sort(SortBy.creationTime())); - - Assertions.assertThat(created.objects()) - .as("create time asc") - .hasSize(3) - .extracting(WeaviateObject::uuid) - .containsExactly(one.uuid(), two.uuid(), three.uuid()); - - // Act: sort by updated time desc - numbers.data.update(one.uuid(), upd -> upd.properties(Map.of("value", -1L))); - Thread.sleep(10); - numbers.data.update(two.uuid(), upd -> upd.properties(Map.of("value", -2L))); - Thread.sleep(10); - numbers.data.update(three.uuid(), upd -> upd.properties(Map.of("value", -3L))); - - var updated = numbers.query.fetchObjects( - q -> q.sort( - // Both sort operators imply ordering 3-2-1 - SortBy.lastUpdateTime().desc(), - SortBy.property("value").asc())); - - Assertions.assertThat(updated.objects()) - .as("last update time desc + value asc") - .hasSize(3) - .extracting(WeaviateObject::uuid) - .containsExactly(three.uuid(), two.uuid(), one.uuid()); } @Test From f5df7a3fd02bf255c1932623f827ba125531de9f Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Fri, 3 Oct 2025 13:23:31 +0200 Subject: [PATCH 2/2] feat: add a helper for sorting by object's UUID --- .../v1/api/collections/query/SortBy.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/SortBy.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/SortBy.java index 6c9d38179..cf8118002 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/SortBy.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/SortBy.java @@ -12,6 +12,23 @@ public static SortBy property(String property) { return new SortBy(List.of(property), true); } + /** + * Sort by object's UUID. Ascending order by default. + * + *

+ * Sorting by UUID may be useful if objects are assigned + * custom UUIDv7 at ingestion, as those are "time-ordered". + * + *

+ * It may be less useful for the auto-generated UUIDs, + * which will produce an essentialy random, albeit stable, order. + * + * @see #desc() to sort in descending order. + */ + public static SortBy uuid() { + return property(ById.ID_PROPERTY); + } + /** * Sort by object creation time. Ascending order by default. *