From 674a7ed46fc94a70edb683642f062dd0605990c3 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:04:52 -0400 Subject: [PATCH 1/4] remove DocumentReference special case --- .../com/google/cloud/firestore/Query.java | 20 ++++--------------- .../com/google/cloud/firestore/QueryTest.java | 18 ----------------- .../cloud/firestore/it/ITSystemTest.java | 4 +++- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 6dd52d8fd..238b289a3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -1111,10 +1111,7 @@ public Query startAt(@Nonnull DocumentSnapshot snapshot) { */ @Nonnull public Query startAt(Object... fieldValues) { - ImmutableList fieldOrders = - fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference - ? createImplicitOrderBy() - : options.getFieldOrders(); + ImmutableList fieldOrders = options.getFieldOrders(); Cursor cursor = createCursor(fieldOrders, fieldValues, true); Builder newOptions = options.toBuilder(); @@ -1197,10 +1194,7 @@ public Query startAfter(@Nonnull DocumentSnapshot snapshot) { * @return The created Query. */ public Query startAfter(Object... fieldValues) { - ImmutableList fieldOrders = - fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference - ? createImplicitOrderBy() - : options.getFieldOrders(); + ImmutableList fieldOrders = options.getFieldOrders(); Cursor cursor = createCursor(fieldOrders, fieldValues, false); Builder newOptions = options.toBuilder(); @@ -1238,10 +1232,7 @@ public Query endBefore(@Nonnull DocumentSnapshot snapshot) { */ @Nonnull public Query endBefore(Object... fieldValues) { - ImmutableList fieldOrders = - fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference - ? createImplicitOrderBy() - : options.getFieldOrders(); + ImmutableList fieldOrders = options.getFieldOrders(); Cursor cursor = createCursor(fieldOrders, fieldValues, true); Builder newOptions = options.toBuilder(); @@ -1259,10 +1250,7 @@ public Query endBefore(Object... fieldValues) { */ @Nonnull public Query endAt(Object... fieldValues) { - ImmutableList fieldOrders = - fieldValues.length == 1 && fieldValues[0] instanceof DocumentReference - ? createImplicitOrderBy() - : options.getFieldOrders(); + ImmutableList fieldOrders = options.getFieldOrders(); Cursor cursor = createCursor(fieldOrders, fieldValues, false); Builder newOptions = options.toBuilder(); diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java index f862b37f1..a15bd5375 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java @@ -19,7 +19,6 @@ import static com.google.cloud.firestore.Filter.*; import static com.google.cloud.firestore.LocalFirestoreHelper.COLLECTION_ID; import static com.google.cloud.firestore.LocalFirestoreHelper.DOCUMENT_NAME; -import static com.google.cloud.firestore.LocalFirestoreHelper.DOCUMENT_PATH; import static com.google.cloud.firestore.LocalFirestoreHelper.SINGLE_FIELD_SNAPSHOT; import static com.google.cloud.firestore.LocalFirestoreHelper.andFilters; import static com.google.cloud.firestore.LocalFirestoreHelper.endAt; @@ -597,23 +596,6 @@ public void withDocumentIdAndDocumentSnapshotCursor() { assertEquals(queryRequest, runQuery.getValue()); } - @Test - public void withDocumentReferenceCursor() { - doAnswer(queryResponse()) - .when(firestoreMock) - .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any()); - - DocumentReference documentCursor = firestoreMock.document(DOCUMENT_PATH); - Value documentValue = reference(DOCUMENT_NAME); - - query.startAt(documentCursor).get(); - - RunQueryRequest queryRequest = - query(order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentValue, true)); - - assertEquals(queryRequest, runQuery.getValue()); - } - @Test public void withExtractedDirectionForDocumentSnapshotCursor() { doAnswer(queryResponse()) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java index 950cbe485..284cfab08 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java @@ -586,7 +586,9 @@ public void startAfterAddsAnImplicitOrderByForDocumentReferences() throws Except doc1.set(map("foo", 1)).get(); doc2.set(map("foo", 1)).get(); - QuerySnapshot querySnapshot = randomColl.startAfter(doc1).get().get(); + DocumentSnapshot docSnap = doc1.get().get(); + + QuerySnapshot querySnapshot = randomColl.startAfter(docSnap).get().get(); assertEquals(1, querySnapshot.size()); Iterator documents = querySnapshot.iterator(); assertEquals(doc2, documents.next().getReference()); From b9c5f983e7d77fa48f9b61dfb8cb9e0afa8aa87a Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:18:19 -0400 Subject: [PATCH 2/4] remove previously added warning message --- .../main/java/com/google/cloud/firestore/Query.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 2e6ee43f6..243e681f8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -72,7 +72,6 @@ import java.util.TreeSet; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.threeten.bp.Duration; @@ -87,8 +86,6 @@ public class Query { final FirestoreRpcContext rpcContext; final QueryOptions options; - private static final Logger LOGGER = Logger.getLogger(Query.class.getName()); - /** The direction of a sort. */ public enum Direction { ASCENDING(StructuredQuery.Direction.ASCENDING), @@ -1291,16 +1288,6 @@ public Query endAt(Object... fieldValues) { return new Query(rpcContext, newOptions.build()); } - private void warningOnSingleDocumentReference(Object... fieldValues) { - if (options.getFieldOrders().isEmpty() - && fieldValues.length == 1 - && fieldValues[0] instanceof DocumentReference) { - LOGGER.warning( - "Warning: Passing DocumentReference into a cursor without orderBy clause is not an intended " - + "behavior. Please use DocumentSnapshot or add an explicit orderBy on document key field."); - } - } - /** * Creates and returns a new Query that ends at the provided document (inclusive). The end * position is relative to the order of the query. The document must contain all of the fields From 24d51c4d60dabf35c8af7383af5caaf31fcef068 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:24:13 -0400 Subject: [PATCH 3/4] import DOCUMENT_PATH --- .../src/test/java/com/google/cloud/firestore/QueryTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java index 1094d8e45..7380305e0 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java @@ -19,6 +19,7 @@ import static com.google.cloud.firestore.Filter.*; import static com.google.cloud.firestore.LocalFirestoreHelper.COLLECTION_ID; import static com.google.cloud.firestore.LocalFirestoreHelper.DOCUMENT_NAME; +import static com.google.cloud.firestore.LocalFirestoreHelper.DOCUMENT_PATH; import static com.google.cloud.firestore.LocalFirestoreHelper.SINGLE_FIELD_SNAPSHOT; import static com.google.cloud.firestore.LocalFirestoreHelper.andFilters; import static com.google.cloud.firestore.LocalFirestoreHelper.endAt; From 186c21f819f79ec399d9d6dc855a0731b2f78242 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:18:37 -0400 Subject: [PATCH 4/4] format --- .../src/main/java/com/google/cloud/firestore/Query.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index c44c71e6b..2ca9f2258 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -63,7 +63,6 @@ import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.Executor; -import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -74,6 +73,7 @@ */ @InternalExtensionOnly public class Query extends StreamableQuery { + static final Comparator DOCUMENT_ID_COMPARATOR = QueryDocumentSnapshot::compareDocumentId; private static final Logger LOGGER = Logger.getLogger(Query.class.getName());