Skip to content

Misc indexing fixes #3351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private List<FieldFilter> getFieldFiltersForPath(FieldPath path) {
case EQUAL:
case IN:
// Encode equality prefix, which is encoded in the index value before the inequality
// (e.g. `a == 'a' && b != 'b' is encoded to 'value != ab').
// (e.g. `a == 'a' && b != 'b'` is encoded to `value != 'ab'`).
values.add(fieldFilter.getValue());
break;
case NOT_IN:
Expand Down Expand Up @@ -338,10 +338,6 @@ public Bound getLowerBound(FieldIndex fieldIndex) {
inclusive &= segmentInclusive;
}

if (values.isEmpty()) {
return null;
}

return new Bound(values, inclusive);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,7 @@ public static Value getLowerBound(Value.ValueTypeCase valueTypeCase) {
}
}

/**
* Returns the largest value for the given value type (exclusive). Returns {@code null} for maps.
*/
/** Returns the largest value for the given value type (exclusive). */
public static Value getUpperBound(Value.ValueTypeCase valueTypeCase) {
switch (valueTypeCase) {
case NULL_VALUE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void emptyQueryBound() {
verifyBound(lowerBound, true);

Bound upperBound = target.getUpperBound(index);
assertNull(upperBound);
verifyBound(upperBound, true);
}

@Test
Expand All @@ -65,7 +65,7 @@ public void equalsQueryBound() {
}

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

Expand All @@ -77,7 +77,7 @@ public void lowerThanQueryBound() {
}

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

Expand Down Expand Up @@ -124,7 +124,7 @@ public void arrayContainsQueryBound() {
verifyBound(lowerBound, true);

Bound upperBound = target.getUpperBound(index);
assertNull(upperBound);
verifyBound(upperBound, true);
}

@Test
Expand All @@ -142,7 +142,7 @@ public void arrayContainsAnyQueryBound() {
verifyBound(lowerBound, true);

Bound upperBound = target.getUpperBound(index);
assertNull(upperBound);
verifyBound(upperBound, true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ public void testNotEqualsFilter() {
verifyResults(query, "coll/val1", "coll/val3");
}

@Test
public void testEqualsWithNotEqualsFilter() {
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING, "b", Kind.ASCENDING));
addDoc("coll/val1", map("a", 1, "b", 1));
addDoc("coll/val2", map("a", 1, "b", 2));
addDoc("coll/val3", map("a", 2, "b", 1));
addDoc("coll/val4", map("a", 2, "b", 2));

// Verifies that we apply the filter in the order of the field index
Query query = query("coll").filter(filter("a", "==", 1)).filter(filter("b", "!=", 1));
verifyResults(query, "coll/val2");

query = query("coll").filter(filter("b", "!=", 1)).filter(filter("a", "==", 1));
verifyResults(query, "coll/val2");
}

@Test
public void testLessThanFilter() {
setUpSingleValueFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void testLowerBound() {
}

@Test
public void testNextValue() {
public void testUpperBound() {
new ComparatorTester()
// null first
.addEqualityGroup(wrap((Object) null))
Expand Down