-
Notifications
You must be signed in to change notification settings - Fork 626
WIP: OR Queries #3185
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
Closed
Closed
WIP: OR Queries #3185
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a31fa87
OR Queries.
ehsannas 005d125
Move the parsing back to firestore/Query.java to avoid having to make…
ehsannas 79958d0
cleanup a bit.
ehsannas 5dbdc4a
Use StructuredQuery.CompositeFilter.Operator.
ehsannas 45e6b22
Add copyright info.
ehsannas 2992489
Add RestrictTo and Update api.txt.
ehsannas 6b45e9c
Move the assertion back to where it was before.
ehsannas 8aed557
Add the code for validating addition of a CompositeFilter to a query.
ehsannas a0f67d6
DNF transform.
ehsannas 0c8242f
Classes that override equals should also override hashCode.
ehsannas cfc31c2
fix formatting.
ehsannas a445976
Add QueryTest unit test for or queries.
ehsannas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
firebase-firestore/src/main/java/com/google/firebase/firestore/Filter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.firestore; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.RestrictTo; | ||
import com.google.firebase.firestore.core.CompositeFilter; | ||
import com.google.firebase.firestore.core.FieldFilter; | ||
import com.google.firebase.firestore.model.Document; | ||
import com.google.firestore.v1.StructuredQuery; | ||
import java.util.Arrays; | ||
|
||
public abstract class Filter { | ||
@NonNull | ||
public static Filter equalTo(@NonNull String field, @Nullable Object value) { | ||
return equalTo(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter equalTo(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.EQUAL, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter notEqualTo(@NonNull String field, @Nullable Object value) { | ||
return notEqualTo(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter notEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.NOT_EQUAL, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter greaterThan(@NonNull String field, @Nullable Object value) { | ||
return greaterThan(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter greaterThan(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create( | ||
fieldPath.getInternalPath(), FieldFilter.Operator.GREATER_THAN, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter greaterThanOrEqualTo(@NonNull String field, @Nullable Object value) { | ||
return greaterThanOrEqualTo(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter greaterThanOrEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create( | ||
fieldPath.getInternalPath(), FieldFilter.Operator.GREATER_THAN_OR_EQUAL, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter lessThan(@NonNull String field, @Nullable Object value) { | ||
return lessThan(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter lessThan(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.LESS_THAN, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter lessThanOrEqualTo(@NonNull String field, @Nullable Object value) { | ||
return lessThanOrEqualTo(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter lessThanOrEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create( | ||
fieldPath.getInternalPath(), FieldFilter.Operator.LESS_THAN_OR_EQUAL, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter arrayContains(@NonNull String field, @Nullable Object value) { | ||
return arrayContains(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter arrayContains(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create( | ||
fieldPath.getInternalPath(), FieldFilter.Operator.ARRAY_CONTAINS, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter arrayContainsAny(@NonNull String field, @Nullable Object value) { | ||
return arrayContainsAny(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter arrayContainsAny(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create( | ||
fieldPath.getInternalPath(), FieldFilter.Operator.ARRAY_CONTAINS_ANY, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter inList(@NonNull String field, @Nullable Object value) { | ||
return inList(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter inList(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.IN, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter notInList(@NonNull String field, @Nullable Object value) { | ||
return notInList(FieldPath.fromDotSeparatedPath(field), value); | ||
} | ||
|
||
@NonNull | ||
public static Filter notInList(@NonNull FieldPath fieldPath, @Nullable Object value) { | ||
return FieldFilter.create(fieldPath.getInternalPath(), FieldFilter.Operator.NOT_IN, value); | ||
} | ||
|
||
@NonNull | ||
public static Filter or(Filter... filters) { | ||
// TODO(ehsann): Change this to Operator.OR once it is available. | ||
return new CompositeFilter( | ||
Arrays.asList(filters), StructuredQuery.CompositeFilter.Operator.OPERATOR_UNSPECIFIED); | ||
} | ||
|
||
@NonNull | ||
public static Filter and(Filter... filters) { | ||
return new CompositeFilter( | ||
Arrays.asList(filters), StructuredQuery.CompositeFilter.Operator.AND); | ||
} | ||
|
||
/** @hide */ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public abstract boolean matches(@NonNull Document doc); | ||
|
||
/** @hide */ | ||
@NonNull | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public abstract String getCanonicalId(); | ||
|
||
/** @hide */ | ||
@NonNull | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public abstract Filter applyAssociativity(); | ||
|
||
/** @hide */ | ||
@NonNull | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public abstract Filter applyDistribution(@Nullable Filter other); | ||
|
||
/** @hide */ | ||
@NonNull | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public abstract Filter computeDnf(); | ||
|
||
/** @hide */ | ||
@NonNull | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public abstract boolean equals(Object o); | ||
|
||
/** @hide */ | ||
@NonNull | ||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
public abstract int hashCode(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I left a comment regarding the naming of this method in the API proposal. This should probably be
inArray
.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.
Acknowledged