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: Sum and average aggregation queries #1097

Merged
merged 44 commits into from Sep 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ce9413f
Initial sum aggregation
danieljbruce Mar 27, 2023
cadb0cc
Modify encoding
danieljbruce Mar 27, 2023
274c606
PropertyAggregateField with tests
danieljbruce Mar 27, 2023
a87e277
Improve transaction tests
danieljbruce Apr 27, 2023
7548e81
Change the description in the describe block
danieljbruce Apr 28, 2023
aaaff65
Change return type to average
danieljbruce Apr 28, 2023
02f0f7d
Make alias optional
danieljbruce Apr 28, 2023
256a4d8
Fix the transaction tests to fail on rollback
danieljbruce Apr 28, 2023
970c0f4
Add additional assertions to existing tests
danieljbruce Apr 28, 2023
ba7aef8
Revert "Add additional assertions to existing tests"
danieljbruce Apr 28, 2023
3a204f5
Add describe block for comparing equivalent query
danieljbruce Apr 28, 2023
b403185
Average, sum and count toProto tests
danieljbruce Apr 28, 2023
8312db7
Add tests for the sum aggregation
danieljbruce May 1, 2023
035df48
Add a test for sum and snapshot reads
danieljbruce May 1, 2023
6a44483
Add two test blocks for special cases
danieljbruce May 2, 2023
cfd745e
Export aggregate field from the client
danieljbruce May 2, 2023
d74c158
Merge branch 'main' of https://github.com/googleapis/nodejs-datastore…
danieljbruce Jun 9, 2023
a67b34b
PR follow-up changes
danieljbruce Jun 9, 2023
4d58133
Adjust the values so that tests pass
danieljbruce Aug 9, 2023
e3b2c62
Add average aggregations
danieljbruce Aug 9, 2023
5164596
Add snapshot reads for run query and aggregate q
danieljbruce Aug 10, 2023
7db60c1
Remove Google error and entity filter
danieljbruce Aug 10, 2023
8868bbb
Should use null for an aggregation query read time
danieljbruce Aug 11, 2023
ff2cd79
Remove tests from a bad cherry pick
danieljbruce Aug 11, 2023
e3b6841
Merge branch 'main' of https://github.com/googleapis/nodejs-datastore…
danieljbruce Aug 11, 2023
6acfb77
Linting fix
danieljbruce Aug 11, 2023
530df2c
Do the test on rating instead of appearances
danieljbruce Aug 11, 2023
eea8602
The assertion says the request should have failed
danieljbruce Aug 11, 2023
8c4db96
Add a comment about using limits in test
danieljbruce Aug 16, 2023
c7de99c
Add rollbacks to transaction tests
danieljbruce Aug 16, 2023
a57c4a8
refactor getSharedOptionsOnly
danieljbruce Aug 17, 2023
8ee7061
Remove test related to snapshot reads
danieljbruce Aug 18, 2023
4f01c43
Add a test for multiple types of aggregates
danieljbruce Aug 18, 2023
5be7d69
Correct descriptions of two tests on overflow
danieljbruce Aug 18, 2023
0ed5509
Merge branch 'main' into sum-avg
danieljbruce Aug 18, 2023
3b53859
Add a comment for setting the alias
danieljbruce Aug 25, 2023
af55599
Add tests to compare various ways to encode alias
danieljbruce Aug 25, 2023
98afdd6
Added tests for when an empty alias is provided
danieljbruce Aug 28, 2023
15840dd
Add a comment clarifying the use of snapshot reads
danieljbruce Aug 28, 2023
bbff19f
Add two tests to explore mixed aggregations alias
danieljbruce Aug 28, 2023
2b66bae
Better names for some internal private functions
danieljbruce Aug 28, 2023
6d882a3
Add a comment explaining why the sleep is needed
danieljbruce Aug 30, 2023
f7a6873
Add getReadTime function and use for sum/avg
danieljbruce Aug 31, 2023
3681c06
Rename variable to emptyData
danieljbruce Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions system-test/datastore.ts
Expand Up @@ -48,6 +48,26 @@ describe('Datastore', () => {
// TODO/DX ensure indexes before testing, and maybe? cleanup indexes after
// possible implications with kokoro project

// Gets the read time of the latest save so that the test isn't flakey due to race condition.
async function getReadTime(path: [{kind: string; name: string}]) {
const projectId = await datastore.getProjectId();
const request = {
keys: [
{
path,
partitionId: {namespaceId: datastore.namespace},
},
],
projectId,
};
const dataClient = datastore.clients_.get('DatastoreClient');
let results: any;
if (dataClient) {
results = await dataClient['lookup'](request);
}
return parseInt(results[0].readTime.seconds) * 1000;
}

after(async () => {
async function deleteEntities(kind: string) {
const query = datastore.createQuery(kind).select('__key__');
Expand Down Expand Up @@ -689,8 +709,16 @@ describe('Datastore', () => {
data: characters[index],
};
});
timeBeforeDataCreation = Date.now();
await sleep(1000);
// Save for a key so that a read time can be accessed for snapshot reads.
const dummyData = Object.assign(Object.assign({}, keysToSave[0]), {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to "emptyData"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

data: {},
});
await datastore.save(dummyData);
timeBeforeDataCreation = await getReadTime([
{kind: 'Character', name: 'Rickard'},
]);
// Sleep for 3 seconds so that any future reads will be later than timeBeforeDataCreation.
await sleep(3000);
await datastore.save(keysToSave);
});

Expand Down