-
Notifications
You must be signed in to change notification settings - Fork 149
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
feat: OR Queries #1800
feat: OR Queries #1800
Conversation
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.
Thanks!
…rkduckworth/or-queries
* OR operator support and integration tests. * Updating documentation and member visibility. * Remove usage of OPERATOR_UNSPECIFIED standing in for OR. * Removing private and internal tags from OR query public API members. * Ensure that new OR Query features are in firestore.d.ts and are exported from the main entry point. * Update documentation for OR query features to match android PR 4274. * Removing CompositeFilter and UnaryFilter from the type definitions and JS doc. * Corrected the descending order test for OR queries. * fix: update generated proto types; fix the update script (#1825) * Adding OR enum value for composit filter operator. --------- Co-authored-by: Alexander Fenster <[email protected]>
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.
Thanks for the update. Looks good, but 1 case can be changed.
dev/system-test/firestore.ts
Outdated
expectDocs( | ||
await collection | ||
.where( | ||
Filter.or( | ||
Filter.where('a', '==', 2), | ||
Filter.where('b', 'in', [2, 3]) | ||
) | ||
) | ||
.get(), | ||
'doc3', | ||
'doc4', | ||
'doc6' | ||
); |
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.
This one doesn't need a composite index.
so you can break it to 2 tests
supports OR queries with in
--> doesn't need composite index (because it doesn't have inequality)
supports OR queries with not-in
--> needs composite index.
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.
Split this. Thanks.
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.
First look. I notice that the .d.ts
files are included here, but aren't these files usually generated?
* }); | ||
* ``` | ||
*/ | ||
public static or(...filters: Filter[]): Filter { |
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 implemented these static functions outside of the filter class so that they could be used without prefixing with Filter.or
or Filter.and
for instance.
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.
This came up in API design review and we decided to go with this approach because it is more consistent with existing static functions in the nodejs-firestore SDK. See for example, the FieldValue class.
* @private | ||
* @internal | ||
*/ | ||
export class UnaryFilter extends Filter { |
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 think we want to call this a PropertyFilter
to be consistent with the documentation.
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.
UnaryFilter was ported from Android, which I need to stay consistent with. This class is not public, so we could conceivably change the name in the future.
} | ||
|
||
public toProto(): api.StructuredQuery.IFilter { | ||
if (this.filters.length === 1) { |
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.
Just a note here that for the datastore PR, we still use an AND
filter with one element because it fits in naturally with the way that the code already is.
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.
That sounds good. I think that's also acceptable. This particular implementation was done to be consistent with other Firestore SDK implementations (ported from Android SDK).
where( | ||
fieldPathOrFilter: string | firestore.FieldPath | Filter, | ||
opStr?: firestore.WhereFilterOp, | ||
value?: unknown | ||
): Query<T> { |
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.
Just a note that this is like the .filter
function in datastore
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'm not sure on the history, but I agree the naming conventions deviate between Firestore and Datastore.
} | ||
return new CompositeFilterInternal( | ||
parsedFilters, | ||
compositeFilterData._getOperator() === 'AND' ? 'AND' : 'OR' |
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.
Should we throw an error here instead if OR
or AND
is not provided?
@danieljbruce I'm not sure of the history of this, but I have an open ticket to modify this SDK so that we use the generated d.ts files. See b/269761436 |
Adding support for OR queries