-
Notifications
You must be signed in to change notification settings - Fork 624
Add != and NOT_IN queries (not public) #1872
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs; | ||
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore; | ||
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor; | ||
import static com.google.firebase.firestore.testutil.TestUtil.assertArrayEquals; | ||
import static com.google.firebase.firestore.testutil.TestUtil.expectError; | ||
import static com.google.firebase.firestore.testutil.TestUtil.map; | ||
import static java.util.Arrays.asList; | ||
|
@@ -31,6 +32,8 @@ | |
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
import com.google.firebase.firestore.Query.Direction; | ||
import com.google.firebase.firestore.testutil.EventAccumulator; | ||
import com.google.firebase.firestore.testutil.IntegrationTestUtil; | ||
|
@@ -39,6 +42,7 @@ | |
import java.util.Map; | ||
import java.util.concurrent.Semaphore; | ||
import org.junit.After; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
|
@@ -483,6 +487,83 @@ public void testQueriesFireFromCacheWhenOffline() { | |
listener.remove(); | ||
} | ||
|
||
// TODO(ne-queries): Re-enable once emulator support is added to CI. | ||
@Ignore | ||
@Test | ||
public void testQueriesCanUseNotEqualFilters() { | ||
Map<String, Object> docA = map("zip", 98101L); | ||
Map<String, Object> docB = map("zip", 91102L); | ||
Map<String, Object> docC = map("zip", "98101"); | ||
Map<String, Object> docD = map("zip", asList(98101L)); | ||
Map<String, Object> docE = map("zip", asList("98101", map("zip", 98101L))); | ||
Map<String, Object> docF = map("zip", map("code", 500L)); | ||
Map<String, Object> docG = map("zip", asList(98101L, 98102L)); | ||
Map<String, Object> docH = map("code", 500L); | ||
Map<String, Object> docI = map("zip", null); | ||
Map<String, Object> docJ = map("zip", Double.NaN); | ||
|
||
Map<String, Map<String, Object>> allDocs = | ||
map( | ||
"a", docA, "b", docB, "c", docC, "d", docD, "e", docE, "f", docF, "g", docG, "h", docH, | ||
"i", docI, "j", docJ); | ||
CollectionReference collection = testCollectionWithDocs(allDocs); | ||
|
||
// Search for zips not matching 98101. | ||
Map<String, Map<String, Object>> expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("a"); | ||
expectedDocsMap.remove("h"); | ||
expectedDocsMap.remove("i"); | ||
|
||
QuerySnapshot snapshot = waitFor(collection.whereNotEqualTo("zip", 98101L).get()); | ||
assertArrayEquals( | ||
Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
|
||
// With objects. | ||
expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("f"); | ||
expectedDocsMap.remove("h"); | ||
expectedDocsMap.remove("i"); | ||
snapshot = waitFor(collection.whereNotEqualTo("zip", map("code", 500)).get()); | ||
assertArrayEquals( | ||
Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
|
||
// With Null. | ||
expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("h"); | ||
expectedDocsMap.remove("i"); | ||
snapshot = waitFor(collection.whereNotEqualTo("zip", null).get()); | ||
assertArrayEquals( | ||
Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
|
||
// With NaN. | ||
expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("h"); | ||
expectedDocsMap.remove("i"); | ||
expectedDocsMap.remove("j"); | ||
snapshot = waitFor(collection.whereNotEqualTo("zip", Double.NaN).get()); | ||
assertArrayEquals( | ||
Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
} | ||
|
||
// TODO(ne-queries): Re-enable once emulator support is added to CI. | ||
@Ignore | ||
@Test | ||
public void testQueriesCanUseNotEqualFiltersWithDocIds() { | ||
Map<String, String> docA = map("key", "aa"); | ||
Map<String, String> docB = map("key", "ab"); | ||
Map<String, String> docC = map("key", "ba"); | ||
Map<String, String> docD = map("key", "bb"); | ||
Map<String, Map<String, Object>> testDocs = | ||
map( | ||
"aa", docA, | ||
"ab", docB, | ||
"ba", docC, | ||
"bb", docD); | ||
CollectionReference collection = testCollectionWithDocs(testDocs); | ||
QuerySnapshot docs = waitFor(collection.whereNotEqualTo(FieldPath.documentId(), "aa").get()); | ||
assertEquals(asList(docB, docC, docD), querySnapshotToValues(docs)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies for what's going to be an irritating question (since I didn't pick up on this earlier), but why do you To me it seems like either the ordering matters or it doesn't. If ordering of query results is predictable, To my understanding, query results always have a well defined ordering (breaking ties on key ordering). This seems to point to What's your take on this? Why the discrepancy? (The same concern applies to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this actually! I originally ran into an issue where I was converting the snapshots into a HashSet in order to easily remove the unneeded documents, but converting them back into a List resulted in an ordering that didn't match the query snapshots from the query. Instead of trying to create the I took a look at the code, and realized that Using |
||
} | ||
|
||
@Test | ||
public void testQueriesCanUseArrayContainsFilters() { | ||
Map<String, Object> docA = map("array", asList(42L)); | ||
|
@@ -541,6 +622,87 @@ public void testQueriesCanUseInFiltersWithDocIds() { | |
assertEquals(asList(docA, docB), querySnapshotToValues(docs)); | ||
} | ||
|
||
// TODO(ne-queries): Re-enable once emulator support is added to CI. | ||
@Ignore | ||
@Test | ||
public void testQueriesCanUseNotInFilters() { | ||
Map<String, Object> docA = map("zip", 98101L); | ||
Map<String, Object> docB = map("zip", 91102L); | ||
Map<String, Object> docC = map("zip", 98103L); | ||
Map<String, Object> docD = map("zip", asList(98101L)); | ||
Map<String, Object> docE = map("zip", asList("98101", map("zip", 98101L))); | ||
Map<String, Object> docF = map("zip", map("code", 500L)); | ||
Map<String, Object> docG = map("zip", asList(98101L, 98102L)); | ||
Map<String, Object> docH = map("code", 500L); | ||
Map<String, Object> docI = map("zip", null); | ||
Map<String, Object> docJ = map("zip", Double.NaN); | ||
|
||
Map<String, Map<String, Object>> allDocs = | ||
map( | ||
"a", docA, "b", docB, "c", docC, "d", docD, "e", docE, "f", docF, "g", docG, "h", docH, | ||
"i", docI, "j", docJ); | ||
CollectionReference collection = testCollectionWithDocs(allDocs); | ||
|
||
// Search for zips not matching 98101, 98103, or [98101, 98102]. | ||
Map<String, Map<String, Object>> expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("a"); | ||
expectedDocsMap.remove("c"); | ||
expectedDocsMap.remove("g"); | ||
expectedDocsMap.remove("h"); | ||
|
||
QuerySnapshot snapshot = | ||
waitFor(collection.whereNotIn("zip", asList(98101L, 98103L, asList(98101L, 98102L))).get()); | ||
assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
|
||
// With objects. | ||
expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("f"); | ||
expectedDocsMap.remove("h"); | ||
snapshot = waitFor(collection.whereNotIn("zip", asList(map("code", 500L))).get()); | ||
assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
|
||
// With Null. | ||
List<Object> nullArray = new ArrayList<>(); | ||
nullArray.add(null); | ||
snapshot = waitFor(collection.whereNotIn("key", nullArray).get()); | ||
assertEquals(new ArrayList<>(), querySnapshotToValues(snapshot)); | ||
|
||
// With NaN. | ||
expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("h"); | ||
expectedDocsMap.remove("j"); | ||
snapshot = waitFor(collection.whereNotIn("zip", asList(Double.NaN)).get()); | ||
assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
|
||
// With NaN and a number. | ||
expectedDocsMap = Maps.newHashMap(allDocs); | ||
expectedDocsMap.remove("a"); | ||
expectedDocsMap.remove("h"); | ||
expectedDocsMap.remove("j"); | ||
snapshot = waitFor(collection.whereNotIn("zip", asList(Float.NaN, 98101L)).get()); | ||
assertEquals(Lists.newArrayList(expectedDocsMap.values()), querySnapshotToValues(snapshot)); | ||
} | ||
|
||
// TODO(ne-queries): Re-enable once emulator support is added to CI. | ||
@Ignore | ||
@Test | ||
public void testQueriesCanUseNotInFiltersWithDocIds() { | ||
Map<String, String> docA = map("key", "aa"); | ||
Map<String, String> docB = map("key", "ab"); | ||
Map<String, String> docC = map("key", "ba"); | ||
Map<String, String> docD = map("key", "bb"); | ||
Map<String, Map<String, Object>> testDocs = | ||
map( | ||
"aa", docA, | ||
"ab", docB, | ||
"ba", docC, | ||
"bb", docD); | ||
CollectionReference collection = testCollectionWithDocs(testDocs); | ||
QuerySnapshot docs = | ||
waitFor(collection.whereNotIn(FieldPath.documentId(), asList("aa", "ab")).get()); | ||
assertEquals(asList(docC, docD), querySnapshotToValues(docs)); | ||
} | ||
|
||
@Test | ||
public void testQueriesCanUseArrayContainsAnyFilters() { | ||
Map<String, Object> docA = map("array", asList(42L)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted on
assertArrayEquals
, remove thisLists.newArrayList
, here and throughout.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed here and throughout.