Skip to content

Implement startAfter for RTDB queries #2277

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 23 commits into from
Jan 14, 2021
Merged

Implement startAfter for RTDB queries #2277

merged 23 commits into from
Jan 14, 2021

Conversation

jmwski
Copy link
Contributor

@jmwski jmwski commented Dec 21, 2020

go/rtdb-exclusive-query-filters

startAfter(value, key) means:

If key == undefined or null, startAt(value, MAX_NAME), else, startAt(value, key + 1), where + 1 means either the next integer (if the key is parseable as an int), or the lexicographically next key.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 21, 2020

Coverage Report

Affected SDKs

  • firebase-database

    SDK overall coverage changed from 50.37% (4ffbf22) to 50.47% (4219ab20) by +0.10%.

    Filename Base (4ffbf22) Head (4219ab20) Diff
    PushIdGenerator.java 70.37% 84.13% +13.76%
    Query.java 49.70% 46.07% -3.63%
    Validation.java 41.67% 42.67% +1.00%

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (4219ab20) is created by Prow via merging commits: 4ffbf22 6c017d5.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 21, 2020

Binary Size Report

Affected SDKs

  • firebase-database

    Type Base (4ffbf22) Head (4219ab20) Diff
    aar 490 kB 492 kB +1.32 kB (+0.3%)
    apk (release) 1.09 MB 1.09 MB +884 B (+0.1%)

Test Logs

Notes

Head commit (4219ab20) is created by Prow via merging commits: 4ffbf22 6c017d5.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@jmwski jmwski assigned jmwski and unassigned schmidt-sebastian Jan 6, 2021
@jmwski jmwski assigned schmidt-sebastian and unassigned jmwski Jan 6, 2021
@jmwski
Copy link
Contributor Author

jmwski commented Jan 6, 2021

@schmidt-sebastian This is ready for another round of review.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

1 similar comment
@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

ValueExpectationHelper helper = new ValueExpectationHelper();
helper.add(
ref.startAfter("w").endAt("y"),
new MapBuilder().put("d", 4L).put("b", 2L).put("c", 3L).build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why "d" is part of the result set when it has a priority of "w"?

@@ -1150,6 +1567,29 @@ public void startAtEndAtWithPriorityAndNameWorks2()
helper.waitForEvents();
}

@Test
public void startAfterEndAtWithPriorityAndNameWorks2()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a 2 here as a suffix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these didn't really add any value and were just blindly copy/pastes. I'm removed them.

@@ -1174,6 +1614,29 @@ public void startAtEndAtWithPriorityAndNameWorksWithServerData2()
helper.waitForEvents();
}

@Test
public void startAfterEndAtWithPriorityAndNameWorksWithServerData2()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a 2 as a suffix.

@@ -3054,6 +3661,45 @@ public void onCancelled(DatabaseError error) {}
IntegrationTestHelpers.waitFor(done);
}

@Test
public void integerKeysBehaveNumericallyStartAfter1()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another strange suffix. If these are used to distinguish test cases, then we should come up with more specific names.

@@ -3142,6 +3788,46 @@ public void onCancelled(DatabaseError error) {}
IntegrationTestHelpers.waitFor(done);
}

@Test
public void integerKeysBehaveNumerically3StartAfter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please come up with a more specific test name.

@@ -57,6 +65,38 @@ public static synchronized String generatePushChildName(long now) {
return result.toString();
}

public static final String nextAfter(String key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This is usually called a successor.

Comment on lines 28 to 30
private static final char MAX_PUSH_CHAR = 'z';

private static final char MIN_PUSH_CHAR = '-';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Flip assignments for clarity.

You could also refer to PUSH_CHARS and get the values from there (which will be slower and more code, so I am not sure it is actually worth it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of prefer having separate sentinel values for this since they trigger edge-cases in the successor/predecessor code.

@@ -273,4 +273,8 @@ public static boolean equals(@Nullable Object left, @Nullable Object right) {
}
return left.equals(right);
}

public static String next(@Nullable String value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused.

@@ -56,11 +56,11 @@ public boolean isPriorityChildName() {
return this.equals(PRIORITY_CHILD_KEY);
}

protected boolean isInt() {
public boolean isInt() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes don't seem to be needed.

@schmidt-sebastian schmidt-sebastian removed their assignment Jan 7, 2021
@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-database:
error: Added method com.google.firebase.database.Query.startAfter(String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(String,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(boolean,String) [AddedMethod]
error: Added method com.google.firebase.database.Query.startAfter(double,String) [AddedMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@jmwski jmwski removed the WIP label Jan 11, 2021
@jmwski
Copy link
Contributor Author

jmwski commented Jan 11, 2021

@schmidt-sebastian Ready for review.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM(ish), depending on how we handle the "startAfter(null)" case.


ValueExpectationHelper expectations = new ValueExpectationHelper();

expectations.add(ref.startAfter(null).limitToFirst(1), null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk about this offline. My gut feeling is that this should match all results, since they order past null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an explanation here: https://github.com/firebase/firebase-ios-sdk/pull/7209/files#r556060181.

I know this reads funny, but I think it is the intended behavior because we are indexing on priority.

@jmwski
Copy link
Contributor Author

jmwski commented Jan 13, 2021

@schmidt-sebastian The copyright check is failing for an unrelated file. The device-check-changed check runs

./gradlew :firebase-database:firebase-test-labUpload

Which I ran locally on master and it failed in the same way it does here. I'm going to assume these CI checks are not needed.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jmwski and others added 2 commits January 13, 2021 15:20
* Implement `endBefore` for RTDB queries

* cleanup

* Fix bug in prevBefore

* Handle endBefore(..., Integer.MIN_VALUE)

* respect key ordering

* Add more tests, check key order boundary conditions

* Generate api text file

* Unit tests for predecessor

* cleanup
@jmwski jmwski changed the title Implement startAfter for RTDB queries Implement startAfter and endBefore for RTDB queries Jan 14, 2021
@google-oss-bot
Copy link
Contributor

@IanWyszynski: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
device-check-changed 6c017d5 link /test device-check-changed

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@jmwski jmwski merged commit f8e6a90 into master Jan 14, 2021
@firebase firebase locked and limited conversation to collaborators Feb 14, 2021
@jmwski jmwski changed the title Implement startAfter and endBefore for RTDB queries Implement startAfter for RTDB queries Feb 23, 2021
@kaibolay kaibolay deleted the jw/start-after branch September 14, 2022 17:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants