Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion firebase-firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Unreleased

* [fixed] Fixed the `null` value handling in `whereNotEqualTo` and `whereNotIn` filters.

# 25.1.3
* [fixed] Use lazy encoding in UTF-8 encoded byte comparison for strings to solve performance issues. [#6706](//github.com/firebase/firebase-android-sdk/pull/6706)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1630,4 +1630,56 @@ public void testOrderByEquality() {
Query query2 = collection.where(inArray("a", asList(2, 3))).orderBy("a");
checkOnlineAndOfflineResultsMatch(query2, "doc6", "doc3");
}

@Test
public void testSDKUsesNotEqualFiltersSameAsServer() {
Map<String, Map<String, Object>> testDocs =
map(
"a", map("zip", Double.NaN),
"b", map("zip", 91102L),
"c", map("zip", 98101L),
"d", map("zip", "98101"),
"e", map("zip", asList(98101L)),
"f", map("zip", asList(98101L, 98102L)),
"g", map("zip", asList("98101", map("zip", 98101L))),
"h", map("zip", map("code", 500L)),
"i", map("zip", null),
"j", map("code", 500L));
CollectionReference collection = testCollectionWithDocs(testDocs);

// populate cache with all documents first to ensure getDocsFromCache() scans all docs
waitFor(testCollectionWithDocs(testDocs).get());

Query query = collection.whereNotEqualTo("zip", 98101L);
checkOnlineAndOfflineResultsMatch(query, "a", "b", "d", "e", "f", "g", "h");

query = collection.whereNotEqualTo("zip", Double.NaN);
checkOnlineAndOfflineResultsMatch(query, "b", "c", "d", "e", "f", "g", "h");
}

@Test
public void testSDKUsesNotInFiltersSameAsServer() {
Map<String, Map<String, Object>> testDocs =
map(
"a", map("zip", Double.NaN),
"b", map("zip", 91102L),
"c", map("zip", 98101L),
"d", map("zip", "98101"),
"e", map("zip", asList(98101L)),
"f", map("zip", asList(98101L, 98102L)),
"g", map("zip", asList("98101", map("zip", 98101L))),
"h", map("zip", map("code", 500L)),
"i", map("zip", null),
"j", map("code", 500L));
CollectionReference collection = testCollectionWithDocs(testDocs);

// populate cache with all documents first to ensure getDocsFromCache() scans all docs
waitFor(testCollectionWithDocs(testDocs).get());

Query query = collection.whereNotIn("zip", asList(98101L, 98103L, asList(98101L, 98102L)));
checkOnlineAndOfflineResultsMatch(query, "a", "b", "d", "e", "g", "h");

query = collection.whereNotIn("zip", nullList());
checkOnlineAndOfflineResultsMatch(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public boolean matches(Document doc) {
Value other = doc.getField(field);
// Types do not have to match in NOT_EQUAL filters.
if (operator == Operator.NOT_EQUAL) {
return other != null && this.matchesComparison(Values.compare(other, value));
return other != null
&& !other.hasNullValue()
&& this.matchesComparison(Values.compare(other, value));
}
// Only compare types with matching backend order (such as double and int).
return other != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public boolean matches(Document doc) {
return false;
}
Value other = doc.getField(getField());
return other != null && !Values.contains(getValue().getArrayValue(), other);
return other != null
&& !other.hasNullValue()
&& !Values.contains(getValue().getArrayValue(), other);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void testNotInFilters() {

// Null match.
document = doc("collection/1", 0, map("zip", null));
assertTrue(query.matches(document));
assertFalse(query.matches(document));

// NaN match.
document = doc("collection/1", 0, map("zip", Double.NaN));
Expand Down Expand Up @@ -333,7 +333,7 @@ public void testNaNFilter() {
assertTrue(query.matches(doc3));
assertTrue(query.matches(doc4));
assertTrue(query.matches(doc5));
assertTrue(query.matches(doc6));
assertFalse(query.matches(doc6));
}

@Test
Expand Down
Loading