-
Notifications
You must be signed in to change notification settings - Fork 946
Make count queries publicly available for use #6608
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
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
b92e492
Mila/count update proto (#6482)
milaGGL 598e948
compile protos and upload the generated json file (#6491)
milaGGL 7f42490
Mila/count add api interface (#6499)
milaGGL 981e6f1
create sample count test cases (#6506)
milaGGL bc61df7
Mila/count implement count query (#6528)
milaGGL c21304b
add test case for terminated firestore
milaGGL a3242ce
Mila/count add tests (#6566)
milaGGL 6da4f4f
Mila/count export aggregate to api (#6575)
milaGGL fe871ce
change int32 to int64 (#6577)
milaGGL 507e984
check client offline state and test (#6579)
milaGGL 98189d5
Mila/count non lite api tests (#6581)
milaGGL 0ebab69
Mila/count update api surface (#6589)
milaGGL 4b273fe
remove DocumentFieldValue
milaGGL a9de825
Merge branch 'master' into mila/count
milaGGL 576d202
fix lint error: Symbol not found for identifier
milaGGL dd693c6
format to pass lint check
milaGGL 83fbc8d
remove the exports of aggregate query functions/types
milaGGL 26a0bd2
Update aggregation.test.ts
milaGGL 9cced28
skip count query test cases if not using emulator
milaGGL f490bfe
update the type of skipTestUnlessUsingEmulator
milaGGL 078d581
roll back to any type for skipTestUnlessUsingEmulator
milaGGL a9ee57a
move aggregation test file into api_internal folder
milaGGL dbbc2f8
resolve comments
milaGGL c12d5a0
reformat to pass lint check
milaGGL 74116a4
add changeset as requested by github
milaGGL de9dd9a
remove the changeset
milaGGL 9438594
Merge branch 'master' into mila/count
milaGGL 3a6cc27
add the changeset back
milaGGL 2380959
export count qury
milaGGL 597d1fb
add changeset
milaGGL 03b9803
Merge branch 'master' into mila/count-export-count-quries
milaGGL e9759c7
Merge remote-tracking branch 'origin/master' into mila/count-export-c…
dconeybe e2cb6a1
update the firestore-client with datastore from client
milaGGL 79670bc
fix circular dependency between count_query_runner.ts and lite-api/ag…
dconeybe c3675d4
fix comments
milaGGL bb87268
Fix document change leads to time travel across multiple tabs (#6619)
wu-hui 2d55fc6
Merge remote-tracking branch 'origin/master' into mila/count-export-c…
dconeybe fa07ffa
update changeset
dconeybe 88d0266
Firestore: Re-write API docs for COUNT API (#6632)
dconeybe 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@firebase/firestore': minor | ||
'firebase': minor | ||
--- | ||
|
||
Added `getCountFromServer()` (`getCount()` in the Lite SDK), which fetches the number of documents in the result set without actually downloading the documents. |
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
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
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
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
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
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,70 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 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. | ||
*/ | ||
|
||
import { AbstractUserDataWriter, Query } from '../api'; | ||
import { | ||
AggregateField, | ||
AggregateQuerySnapshot | ||
} from '../lite-api/aggregate_types'; | ||
import { Value } from '../protos/firestore_proto_api'; | ||
import { Datastore, invokeRunAggregationQueryRpc } from '../remote/datastore'; | ||
import { hardAssert } from '../util/assert'; | ||
|
||
/** | ||
* CountQueryRunner encapsulates the logic needed to run the count aggregation | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* queries. | ||
*/ | ||
export class CountQueryRunner { | ||
constructor( | ||
private readonly query: Query<unknown>, | ||
private readonly datastore: Datastore, | ||
private readonly userDataWriter: AbstractUserDataWriter | ||
) {} | ||
|
||
run(): Promise<AggregateQuerySnapshot<{ count: AggregateField<number> }>> { | ||
return invokeRunAggregationQueryRpc(this.datastore, this.query._query).then( | ||
result => { | ||
hardAssert( | ||
result[0] !== undefined, | ||
'Aggregation fields are missing from result.' | ||
); | ||
|
||
const counts = Object.entries(result[0]) | ||
.filter(([key, value]) => key === 'count_alias') | ||
.map(([key, value]) => | ||
this.userDataWriter.convertValue(value as Value) | ||
); | ||
|
||
const countValue = counts[0]; | ||
|
||
hardAssert( | ||
typeof countValue === 'number', | ||
'Count aggregate field value is not a number: ' + countValue | ||
); | ||
|
||
return Promise.resolve( | ||
new AggregateQuerySnapshot<{ count: AggregateField<number> }>( | ||
this.query, | ||
{ | ||
count: countValue | ||
} | ||
) | ||
); | ||
} | ||
); | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.