Skip to content
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

Merged
merged 13 commits into from
Mar 6, 2023
Merged

feat: OR Queries #1800

merged 13 commits into from
Mar 6, 2023

Conversation

MarkDuckworth
Copy link
Contributor

@MarkDuckworth MarkDuckworth commented Nov 23, 2022

Adding support for OR queries

@MarkDuckworth MarkDuckworth requested review from a team as code owners November 23, 2022 17:44
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: firestore Issues related to the googleapis/nodejs-firestore API. labels Nov 23, 2022
@MarkDuckworth MarkDuckworth changed the title Composite operators for OR Queries. refactor: Internal implementation of composite operators for OR Queries. Nov 23, 2022
dev/src/filter.ts Outdated Show resolved Hide resolved
dev/src/filter.ts Outdated Show resolved Hide resolved
dev/src/filter.ts Outdated Show resolved Hide resolved
dev/src/filter.ts Outdated Show resolved Hide resolved
dev/src/filter.ts Outdated Show resolved Hide resolved
dev/src/reference.ts Show resolved Hide resolved
dev/src/reference.ts Outdated Show resolved Hide resolved
dev/system-test/firestore.ts Outdated Show resolved Hide resolved
dev/test/query.ts Outdated Show resolved Hide resolved
dev/test/query.ts Show resolved Hide resolved
@ehsannas ehsannas assigned MarkDuckworth and unassigned ehsannas Nov 29, 2022
Copy link
Contributor

@ehsannas ehsannas left a comment

Choose a reason for hiding this comment

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

Thanks!

@MarkDuckworth MarkDuckworth added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jan 9, 2023
MarkDuckworth and others added 2 commits February 17, 2023 07:48
* 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]>
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Feb 17, 2023
@MarkDuckworth MarkDuckworth changed the title refactor: Internal implementation of composite operators for OR Queries. feat: OR Queries Feb 18, 2023
@MarkDuckworth MarkDuckworth requested review from ehsannas and removed request for ehsannas February 22, 2023 17:33
Copy link
Contributor

@ehsannas ehsannas left a 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.

Comment on lines 2171 to 2183
expectDocs(
await collection
.where(
Filter.or(
Filter.where('a', '==', 2),
Filter.where('b', 'in', [2, 3])
)
)
.get(),
'doc3',
'doc4',
'doc6'
);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split this. Thanks.

@MarkDuckworth MarkDuckworth added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Mar 3, 2023
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Mar 3, 2023
@ehsannas ehsannas removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 3, 2023
Copy link

@danieljbruce danieljbruce left a 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 {

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.

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 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 {

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.

Copy link
Contributor Author

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) {

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.

Copy link
Contributor Author

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> {

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

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'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'

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?

@MarkDuckworth
Copy link
Contributor Author

First look. I notice that the .d.ts files are included here, but aren't these files usually generated?

@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

@ehsannas ehsannas merged commit 983a477 into main Mar 6, 2023
@ehsannas ehsannas deleted the markduckworth/or-queries branch March 6, 2023 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants