Skip to content

Commit 579a83e

Browse files
Misc indexing fixes (#3351)
1 parent 84b200a commit 579a83e

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/core/Target.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private List<FieldFilter> getFieldFiltersForPath(FieldPath path) {
160160
case EQUAL:
161161
case IN:
162162
// Encode equality prefix, which is encoded in the index value before the inequality
163-
// (e.g. `a == 'a' && b != 'b' is encoded to 'value != ab').
163+
// (e.g. `a == 'a' && b != 'b'` is encoded to `value != 'ab'`).
164164
values.add(fieldFilter.getValue());
165165
break;
166166
case NOT_IN:
@@ -338,10 +338,6 @@ public Bound getLowerBound(FieldIndex fieldIndex) {
338338
inclusive &= segmentInclusive;
339339
}
340340

341-
if (values.isEmpty()) {
342-
return null;
343-
}
344-
345341
return new Bound(values, inclusive);
346342
}
347343

firebase-firestore/src/main/java/com/google/firebase/firestore/model/Values.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,7 @@ public static Value getLowerBound(Value.ValueTypeCase valueTypeCase) {
500500
}
501501
}
502502

503-
/**
504-
* Returns the largest value for the given value type (exclusive). Returns {@code null} for maps.
505-
*/
503+
/** Returns the largest value for the given value type (exclusive). */
506504
public static Value getUpperBound(Value.ValueTypeCase valueTypeCase) {
507505
switch (valueTypeCase) {
508506
case NULL_VALUE:

firebase-firestore/src/test/java/com/google/firebase/firestore/core/TargetTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void emptyQueryBound() {
4949
verifyBound(lowerBound, true);
5050

5151
Bound upperBound = target.getUpperBound(index);
52-
assertNull(upperBound);
52+
verifyBound(upperBound, true);
5353
}
5454

5555
@Test
@@ -65,7 +65,7 @@ public void equalsQueryBound() {
6565
}
6666

6767
@Test
68-
public void lowerThanQueryBound() {
68+
public void lessThanQueryBound() {
6969
Target target = query("c").filter(filter("foo", "<", "bar")).toTarget();
7070
FieldIndex index = fieldIndex("c", "foo", FieldIndex.Segment.Kind.DESCENDING);
7171

@@ -77,7 +77,7 @@ public void lowerThanQueryBound() {
7777
}
7878

7979
@Test
80-
public void lowerThanOrEqualsQueryBound() {
80+
public void lessThanOrEqualsQueryBound() {
8181
Target target = query("c").filter(filter("foo", "<=", "bar")).toTarget();
8282
FieldIndex index = fieldIndex("c", "foo", FieldIndex.Segment.Kind.ASCENDING);
8383

@@ -124,7 +124,7 @@ public void arrayContainsQueryBound() {
124124
verifyBound(lowerBound, true);
125125

126126
Bound upperBound = target.getUpperBound(index);
127-
assertNull(upperBound);
127+
verifyBound(upperBound, true);
128128
}
129129

130130
@Test
@@ -142,7 +142,7 @@ public void arrayContainsAnyQueryBound() {
142142
verifyBound(lowerBound, true);
143143

144144
Bound upperBound = target.getUpperBound(index);
145-
assertNull(upperBound);
145+
verifyBound(upperBound, true);
146146
}
147147

148148
@Test

firebase-firestore/src/test/java/com/google/firebase/firestore/local/SQLiteIndexManagerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ public void testNotEqualsFilter() {
111111
verifyResults(query, "coll/val1", "coll/val3");
112112
}
113113

114+
@Test
115+
public void testEqualsWithNotEqualsFilter() {
116+
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING, "b", Kind.ASCENDING));
117+
addDoc("coll/val1", map("a", 1, "b", 1));
118+
addDoc("coll/val2", map("a", 1, "b", 2));
119+
addDoc("coll/val3", map("a", 2, "b", 1));
120+
addDoc("coll/val4", map("a", 2, "b", 2));
121+
122+
// Verifies that we apply the filter in the order of the field index
123+
Query query = query("coll").filter(filter("a", "==", 1)).filter(filter("b", "!=", 1));
124+
verifyResults(query, "coll/val2");
125+
126+
query = query("coll").filter(filter("b", "!=", 1)).filter(filter("a", "==", 1));
127+
verifyResults(query, "coll/val2");
128+
}
129+
114130
@Test
115131
public void testLessThanFilter() {
116132
setUpSingleValueFilter();

firebase-firestore/src/test/java/com/google/firebase/firestore/model/ValuesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void testLowerBound() {
254254
}
255255

256256
@Test
257-
public void testNextValue() {
257+
public void testUpperBound() {
258258
new ComparatorTester()
259259
// null first
260260
.addEqualityGroup(wrap((Object) null))

0 commit comments

Comments
 (0)