Skip to content

Commit c954002

Browse files
committed
Fix bundle query resume issue
1 parent 02b3365 commit c954002

File tree

3 files changed

+54
-30
lines changed

3 files changed

+54
-30
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleSerializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.firebase.firestore.core.Filter;
2323
import com.google.firebase.firestore.core.OrderBy;
2424
import com.google.firebase.firestore.core.Query;
25-
import com.google.firebase.firestore.core.Target;
2625
import com.google.firebase.firestore.model.DocumentKey;
2726
import com.google.firebase.firestore.model.FieldPath;
2827
import com.google.firebase.firestore.model.MutableDocument;
@@ -154,7 +153,9 @@ private BundledQuery decodeBundledQuery(JSONObject bundledQuery) throws JSONExce
154153
Query.LimitType limitType = decodeLimitType(bundledQuery);
155154

156155
return new BundledQuery(
157-
new Target(parent, collectionGroup, filters, orderBys, limit, startAt, endAt), limitType);
156+
new Query(parent, collectionGroup, filters, orderBys, limit, limitType, startAt, endAt)
157+
.toTarget(),
158+
limitType);
158159
}
159160

160161
private int decodeLimit(JSONObject structuredQuery) {

firebase-firestore/src/test/java/com/google/firebase/firestore/bundle/BundleReaderTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static org.junit.Assert.assertThrows;
2525

2626
import com.google.firebase.firestore.core.Query;
27-
import com.google.firebase.firestore.core.Target;
2827
import com.google.firebase.firestore.model.DatabaseId;
2928
import com.google.firebase.firestore.model.ObjectValue;
3029
import com.google.firebase.firestore.model.ResourcePath;
@@ -57,28 +56,32 @@ public class BundleReaderTest {
5756
new NamedQuery(
5857
"limitQuery",
5958
new BundledQuery(
60-
new Target(
61-
ResourcePath.fromString("foo"),
62-
null,
63-
Collections.emptyList(),
64-
Collections.singletonList(orderBy("sort")),
65-
1,
66-
null,
67-
null),
59+
new Query(
60+
ResourcePath.fromString("foo"),
61+
null,
62+
Collections.emptyList(),
63+
Collections.singletonList(orderBy("sort")),
64+
1,
65+
Query.LimitType.LIMIT_TO_FIRST,
66+
null,
67+
null)
68+
.toTarget(),
6869
Query.LimitType.LIMIT_TO_FIRST),
6970
version(1590011379000001L));
7071
public static final NamedQuery LIMIT_TO_LAST_QUERY =
7172
new NamedQuery(
7273
"limitToLastQuery",
7374
new BundledQuery(
74-
new Target(
75-
ResourcePath.fromString("foo"),
76-
null,
77-
Collections.emptyList(),
78-
Collections.singletonList(orderBy("sort")),
79-
1,
80-
null,
81-
null),
75+
new Query(
76+
ResourcePath.fromString("foo"),
77+
null,
78+
Collections.emptyList(),
79+
Collections.singletonList(orderBy("sort")),
80+
1,
81+
Query.LimitType.LIMIT_TO_LAST,
82+
null,
83+
null)
84+
.toTarget(),
8285
Query.LimitType.LIMIT_TO_LAST),
8386
version(1590011379000002L));
8487
public static final BundledDocumentMetadata DELETED_DOC_METADATA =

firebase-firestore/src/test/java/com/google/firebase/firestore/bundle/BundleSerializerTest.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
@RunWith(RobolectricTestRunner.class)
5252
@Config(manifest = Config.NONE)
5353
public class BundleSerializerTest {
54-
// Note: This tests uses single-quoted JSON strings, which are accepted by org.json.JSONObject.
55-
// While they are invalid JSON, they allow us to no use non-escaped quotes in the test file.
54+
// Note: This tests uses single-quoted JSON strings, which are accepted by
55+
// org.json.JSONObject.
56+
// While they are invalid JSON, they allow us to no use non-escaped quotes in
57+
// the test file.
5658

5759
private static String TEST_PROJECT = "projects/project/databases/(default)/documents";
5860
private static String TEST_DOCUMENT = TEST_PROJECT + "/coll/doc";
@@ -672,6 +674,32 @@ public void testDecodesBundledDocumentMetadata() throws JSONException {
672674
assertEquals(expectedMetadata, actualMetadata);
673675
}
674676

677+
@Test
678+
public void testDecodesTargetWithoutImplicitOrderByOnName() throws JSONException {
679+
String json =
680+
"{\"name\":\"myNamedQuery\",\"bundledQuery\":{\"parent\":\"projects/project/databases"
681+
+ "/(default)/documents\",\"structuredQuery\":{\"from\":[{\"collectionId\":\"foo\"}],"
682+
+ "\"limit\":{\"value\":10}},\"limitType\":\"FIRST\"},"
683+
+ "\"readTime\":{\"seconds\":\"1679674432\",\"nanos\":579934000}}";
684+
NamedQuery query = serializer.decodeNamedQuery(new JSONObject(json));
685+
assertEquals(
686+
TestUtil.query("foo").limitToFirst(10).toTarget(), query.getBundledQuery().getTarget());
687+
assertEquals(Query.LimitType.LIMIT_TO_FIRST, query.getBundledQuery().getLimitType());
688+
}
689+
690+
@Test
691+
public void testDecodesLimitToLastTargetWithoutImplicitOrderByOnName() throws JSONException {
692+
String json =
693+
"{\"name\":\"myNamedQuery\",\"bundledQuery\":{\"parent\":\"projects/project/databases"
694+
+ "/(default)/documents\",\"structuredQuery\":{\"from\":[{\"collectionId\":\"foo\"}],"
695+
+ "\"limit\":{\"value\":10}},\"limitType\":\"LAST\"},"
696+
+ "\"readTime\":{\"seconds\":\"1679674432\",\"nanos\":579934000}}";
697+
NamedQuery query = serializer.decodeNamedQuery(new JSONObject(json));
698+
assertEquals(
699+
TestUtil.query("foo").limitToLast(10).toTarget(), query.getBundledQuery().getTarget());
700+
assertEquals(Query.LimitType.LIMIT_TO_LAST, query.getBundledQuery().getLimitType());
701+
}
702+
675703
private void assertDecodesValue(String json, Value proto) throws JSONException {
676704
String documentJson =
677705
"{\n"
@@ -719,15 +747,7 @@ private void assertDecodesNamedQuery(String json, Query query) throws JSONExcept
719747
+ "}";
720748
NamedQuery actualNamedQuery = serializer.decodeNamedQuery(new JSONObject(queryJson));
721749

722-
Target target =
723-
new Target(
724-
query.getPath(),
725-
query.getCollectionGroup(),
726-
query.getFilters(),
727-
query.getExplicitOrderBy(),
728-
query.getLimit(),
729-
query.getStartAt(),
730-
query.getEndAt());
750+
Target target = query.toTarget();
731751
BundledQuery bundledQuery =
732752
new BundledQuery(
733753
target,

0 commit comments

Comments
 (0)