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: Add support for Sum and Avg aggregation query #437

Merged
merged 21 commits into from
Sep 5, 2023

Conversation

Mariatta
Copy link
Contributor

@Mariatta Mariatta commented May 9, 2023

Add .sum() and .avg() functions to aggregation

Refactor limit to be passed in to the nested query's limit

Unit tests

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@Mariatta Mariatta requested review from a team as code owners May 9, 2023 16:47
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: datastore Issues related to the googleapis/python-datastore API. labels May 9, 2023
Add .sum() and .avg() functions to aggregation

Refactor limit to be passed in to the nested query's limit

Unit tests
@daniel-sanche
Copy link
Contributor

LGTM, but we might want to add some more tests like in googleapis/python-firestore#715

@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 24, 2023
@yoshi-kokoro yoshi-kokoro removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Aug 24, 2023
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 25, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 25, 2023
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 25, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 25, 2023
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 26, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 26, 2023
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 26, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 26, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 26, 2023
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 29, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 29, 2023
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 29, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 29, 2023
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 29, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 29, 2023
tests/system/test_aggregation_query.py Show resolved Hide resolved
@@ -70,54 +70,156 @@ def nested_query(aggregation_query_client, ancestor_key):

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for missing this previously, it looks like transactions will also need to be covered and tested.

Copy link
Contributor

Choose a reason for hiding this comment

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

I added some tests to make sure the transaction id is captured when running a query inside the context of a transaction

Let me know if you had anything else in mind. I'm still trying to get my head around the relationship between transactions and queries, and I'm not seeing any existing tests or samples around this

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there are a few examples here: https://github.com/googleapis/python-datastore/blob/main/tests/system/test_transaction.py, if you want to move them into there instead (I don't have a strong preference)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I was a little unsure which file to put these in since they involves both queries and transactions. I just looked into moving these to test_transaction.py, but all the test fixtures for configuring queries live in this file, so it's probably easiest to keep it here

@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 30, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 30, 2023
When an aggregation query is run in a transaction, the transaction id should be sent with the request.
The result is the same as when it is run outside of a transaction.
"""
import mock
Copy link
Contributor

Choose a reason for hiding this comment

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

linked above, maybe we can make these more in line with https://github.com/googleapis/python-datastore/blob/main/tests/system/test_transaction.py so that we don't have to do any mocking

Copy link
Contributor

Choose a reason for hiding this comment

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

The mock here is used to capture the transaction field sent along with the request, which I don't believe is captured by the other tests.

But yeah, on second thought that part probably doesn't belong here. I broke this test up and moved those parts into the unit tests

@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 31, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 31, 2023
aggregation_pb.alias = self.alias
aggregation_pb.sum = query_pb2.AggregationQuery.Aggregation.Sum()
aggregation_pb.sum.property.name = self.property_ref
aggregation_pb.alias = self.alias
Copy link
Contributor

Choose a reason for hiding this comment

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

is this duplicated? (see line 98)

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch!

@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 31, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 31, 2023
@daniel-sanche daniel-sanche merged commit e99120d into main Sep 5, 2023
15 checks passed
@daniel-sanche daniel-sanche deleted the feat-sum-avg-create-pr branch September 5, 2023 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/python-datastore API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants