Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sum and average aggregation queries (#1097)
* Initial sum aggregation This commit introduces the sum aggregation with a simple test to ensure it works * Modify encoding This change modifies the encoding so that the right data reaches the grpc layer * PropertyAggregateField with tests Adds helper functions and a super class so that average and sum can share the same properties. * Improve transaction tests Add sum and average to the transaction tests here to improve test coverage for transactions. * Change the description in the describe block * Change return type to average The return type for this function is wrong. The function returns an Average so we should use Average. * Make alias optional Make alias optional since the query still works without providing an alias. * Fix the transaction tests to fail on rollback The transaction tests should not pass if the transaction is rolled back like they do currently. We must not catch errors and instead let the test fail. * Add additional assertions to existing tests Ensure that the addAggregation function works correctly with an additional assertion check. * Revert "Add additional assertions to existing tests" This reverts commit 970c0f4. * Add describe block for comparing equivalent query This test ensures that all the aggregate queries are actually the same no matter how you build them * Average, sum and count toProto tests Write tests to effectively document the toProto output of the various aggregate fields * Add tests for the sum aggregation Equivalent tests to count are written for sum in system tests and some more tests are written too to meet requirements outlined by team. * Add a test for sum and snapshot reads The test for sum and snapshot reads should look at the database before the data is created and run the tests based on the database in that state * Add two test blocks for special cases Add a test block for a dataset with overflow values and a dataset with NaN values. * Export aggregate field from the client Aggregate field should be exported from the client so that it can be used easily by users. * PR follow-up changes Some idiomatic changes to improve the state of the code in the PR. * Adjust the values so that tests pass Values for sum and average should be different from those of count and these tests provide the right values now. # Conflicts: # system-test/datastore.ts * Add average aggregations Average aggregations regarding appearances have been added in tests and correct values have been assigned * Add snapshot reads for run query and aggregate q The future refactor must implement the TODOs so that there is less repeated code in the codebase. Also, this commit implements snapshot reads for queries and adds a test for the snapshot reads. * Remove Google error and entity filter Remove some unused imports as they do not apply to the code anymore * Should use null for an aggregation query read time Snapshot reads read at a time that there is no data so sums and averages should reflect that accordingly. * Remove tests from a bad cherry pick Tests for sum that have values corresponding to count are still there in the test cases. They should be removed. * Linting fix We don’t care about a loss of precision since the literal value indicated is contained in a test and the loss of precision won’t affect the code. * Do the test on rating instead of appearances At this point the datastore is populated with data about ratings so computations should be done on that instead. * The assertion says the request should have failed An assertion error should be thrown so that the test doesn’t pass if the request is successful. * Add a comment about using limits in test The query with the limit will include all data points with the lowest appearance values. This is likely desired, but also important to document. * Add rollbacks to transaction tests The rollbacks for the transaction tests ensure that if a test fails then the data gets reset to where it was before. * refactor getSharedOptionsOnly Introducing getSharedOptionsOnly allows us to use that function in two different places to avoid a repeated block of code. * Remove test related to snapshot reads This test belongs inside another PR because it is not directly related to sum/avg. * Add a test for multiple types of aggregates A test should be included that looks at multiple aggregations in a single query. * Correct descriptions of two tests on overflow The tests themselves should include the word overflow so that it is clear they are working with an overflow dataset. * Add a comment for setting the alias The comment for setting the alias should not make any mention of count since it is agnostic to the aggregation type. * Add tests to compare various ways to encode alias No matter how alias is encoded, the data structures should store the aggregations the same way inside an aggregate field so as not to create any confusion. * Added tests for when an empty alias is provided Tests for when an empty alias is provided should check that each aggregate query still works. * Add a comment clarifying the use of snapshot reads The sleep function should enable us to test snapshot reads for aggregate queries * Add two tests to explore mixed aggregations alias Two tests should be explored that evaluate what happens when multiple aggregations are used and when too many aggregations are used. * Better names for some internal private functions Shared options functions could be given a better name so that they make more sense to the code that is using them. * Add a comment explaining why the sleep is needed The code must explain why the sleep function is needed in the test because its purpose should be clear. * Add getReadTime function and use for sum/avg A sum/average test uses snapshot reads for an aggregate query. The key here is write code that will guarantee the read time occurs well before all the data is saved in order to ensure the test isn’t flakey. * Rename variable to emptyData emptyData is a more accurate variable name for the datastore save data
- Loading branch information