Skip to content

Tighten the query bounds #2979

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 11 commits into from
Sep 16, 2021
Merged

Tighten the query bounds #2979

merged 11 commits into from
Sep 16, 2021

Conversation

schmidt-sebastian
Copy link
Contributor

This PR implements type clamping. A query for foo < 3 should only return integers, so we know both a min value and a max value.

This PR implements type clamping. A query for foo < 3 should only return integers, so we know both a min value and a max value.
@googlebot googlebot added the cla: yes Override cla label Sep 15, 2021
@@ -34,7 +34,7 @@
public static final int INDEX_TYPE_BOOLEAN = 10;
public static final int INDEX_TYPE_NAN = 13;
public static final int INDEX_TYPE_NUMBER = 15;
public static final int INDEX_TYPE_TIMESTAMP = 10;
public static final int INDEX_TYPE_TIMESTAMP = 20;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a typo.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 15, 2021

Coverage Report

Affected SDKs

  • firebase-firestore

    SDK overall coverage changed from 42.85% (da62838) to 43.12% (0dcb09f8) by +0.26%.

    Filename Base (da62838) Head (0dcb09f8) Diff
    DatabaseId.java 69.23% 70.37% +1.14%
    FirestoreIndexValueWriter.java 30.99% 43.66% +12.68%
    OrderedCodeWriter.java 30.77% 44.87% +14.10%
    Target.java 96.73% 97.06% +0.33%
    Value.java 45.65% 46.44% +0.79%
    Values.java 96.50% 94.21% -2.29%

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 (0dcb09f8) is created by Prow via merging commits: da62838 82f497f.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 15, 2021

Binary Size Report

Affected SDKs

  • firebase-firestore

    Type Base (da62838) Head (0dcb09f8) Diff
    aar 1.20 MB 1.20 MB +1.13 kB (+0.1%)
    apk (release) 3.24 MB 3.24 MB +264 B (+0.0%)

Test Logs

Notes

Head commit (0dcb09f8) is created by Prow via merging commits: da62838 82f497f.

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

lgtm with some small suggestions

for (Filter filter : filters) {
if (filter.getField().equals(segment.getFieldPath())) {
FieldFilter fieldFilter = (FieldFilter) filter;

Value newValue = null;

Choose a reason for hiding this comment

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

optional: s/new/current for here and below?

When looking at newValue, I initially thought that this value was going to be assigned because of the new, but it seems like it's only evaluated to be compared to the outer lowestValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will update.

@@ -432,4 +457,64 @@ public static Value refValue(DatabaseId databaseId, DocumentKey key) {
.build();
return value;
}

public static Value getFirstValue(Value.ValueTypeCase valueTypeCase) {

Choose a reason for hiding this comment

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

s/getFirstValue/getLowestValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will rename.

}
}

public static @Nullable Value getNextValue(Value.ValueTypeCase valueTypeCase) {

Choose a reason for hiding this comment

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

s/getNextValue/getHighestValue or getHighestPossibleValue?

NextValue is a bit confusing here. Alternatively, just add some code comments please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I forgot to push the commit with the comments. I agree that this is not a great name - however this method returns an exclusive value, i.e. one higher than the max. Do you have a name suggestion that conveys that? I need your input here :)

Choose a reason for hiding this comment

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

Some ideas: getHighestValueExclusive, getUpperBoundExclusive, getExclusiveUpperBound

I think pairing "exclusive" with a "bound" makes more sense. Or you can leave the current name and just have comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to getLowerBound() and getUpperBound(). The comments still state whether it is exclusive or not.

@@ -143,14 +143,14 @@ public void testStartAfterFilter() {
}

@Test
public void testEndAtFilter() {
public void testEndBeforeFilter() {

Choose a reason for hiding this comment

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

I'm a little confused about the before in Bound. Based on the naming of this test, if before == true, Bound does not include the endAt value? However, it seems like it's flipped for startAt and startAfter.

I find a it harder to reason about before/after since it's flipped for whether it's a startAt, or endAt. Is it possible to change it before to an inclusive/exclusive model instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's super confusing, but it uses the existing backend terminology:

startAt => before is true (cursor starts right before the provided value)
startAfter => before is false (cursor starts right after the provided value)
endBefore => before is false (cursor stops right before the provided value)
endAt => before is true (cursor stops right after the provided value)

I am confused by this myself, hence the test name here is wrong.

Choose a reason for hiding this comment

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

oh man this still doesn't make too much sense... Still can't wrap my mind around how endBefore has before set to false in order to mean that the cursor stops before??

Is this documented anywhere? optional nice thing you can do is encapsulate the before bound stuff into some tester objects :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will clean up in a follow up.

Base automatically changed from mrschmidt/indexencoding to master September 16, 2021 15:16
@schmidt-sebastian schmidt-sebastian merged commit c30a15a into master Sep 16, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/typeclamping branch September 16, 2021 16:11
@firebase firebase locked and limited conversation to collaborators Oct 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants