googleapis / python-datastore

Apache License 2.0
80 stars 44 forks source link

feat: implement query profiling #542

Closed daniel-sanche closed 3 months ago

daniel-sanche commented 6 months ago

Added Query Profiling, support, for retrieving information about a query

Query Profiling is configured through the new ExplainOptions dataclass, which can be attached to a Query or AggregationQuery object at init time.

ExplainOptions has one argument: analyze. When analyze is True, it runs the entire query, and returns a set of stats about the execution, and a set of "planning" data detailing the indexes used by the request. If analuze is False, only the planning data is returned, and the query is not executed

For usage details, see the new samples added as part of this PR

snippet-bot[bot] commented 6 months ago

Here is the summary of changes.

You are about to add 4 region tags. - [samples/snippets/snippets.py:397](https://github.com/googleapis/python-datastore/blob/c5d8a760c6e52e74b06ddb58a0a4fd50a575c69e/samples/snippets/snippets.py#L397), tag `datastore_query_explain_analyze_entity` - [samples/snippets/snippets.py:425](https://github.com/googleapis/python-datastore/blob/c5d8a760c6e52e74b06ddb58a0a4fd50a575c69e/samples/snippets/snippets.py#L425), tag `datastore_query_explain_entity` - [samples/snippets/snippets.py:440](https://github.com/googleapis/python-datastore/blob/c5d8a760c6e52e74b06ddb58a0a4fd50a575c69e/samples/snippets/snippets.py#L440), tag `datastore_query_explain_analyze_aggregation` - [samples/snippets/snippets.py:469](https://github.com/googleapis/python-datastore/blob/c5d8a760c6e52e74b06ddb58a0a4fd50a575c69e/samples/snippets/snippets.py#L469), tag `datastore_query_explain_aggregation`

This comment is generated by snippet-bot. If you find problems with this result, please file an issue at: https://github.com/googleapis/repo-automation-bots/issues. To update this comment, add snippet-bot:force-run label or use the checkbox below:

Linchin commented 5 months ago

LGTM, I just added some nit picks.

daniel-sanche commented 5 months ago

Looks like mypy is failing due to a typing error in the gapic generator: https://github.com/googleapis/gapic-generator-python/issues/2044

I'll try to regenerate and pull in the fixes in https://github.com/googleapis/python-datastore/pull/540