feat: add GlideAggregate (Stats API) support#146
Open
orwellsanimal wants to merge 1 commit into
Open
Conversation
Implements GlideAggregate(Query) wrapping /api/now/stats/{table},
with a client.GlideAggregate(table) factory and a StatsAPI peer.
Refs ServiceNow#145
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements
GlideAggregate, a REST wrapper over/api/now/stats/{table}that mirrors the server-sideGlideAggregate. This picks up the design discussed and approved in #145.Design (per #145)
class GlideAggregate(Query)— inherits the query builder (add_query,add_active_query,add_null_query,add_not_null_query) rather thanGlideRecord, matching theJoinQuery/RLQueryprecedent and avoiding the CRUD surface that doesn't apply to aggregates. Result-cursor methods live on the class because the Stats wire shape (groupby_fields[]+stats{}) differs from a Table record.StatsAPI— added as a peer alongsideTableAPI/AttachmentAPI/BatchAPI, sharingAPI._send(and therefore the 401/403/404 → exception mapping).client.GlideAggregate(table)factory, mirroringclient.GlideRecord(table).Notes from building against a live instance
GlideAggregatesupports it, but the REST Stats API doesn't exposesysparm_stddev_fields(only count/sum/avg/min/max). Left out with a docstring note rather than faked client-side.order_by_aggregateis server-side viasysparm_order_by=AVG^field/COUNT.aggregate^field^operator^value(field required even forCOUNT), multiple clauses joined by,.set_display_value(True)sendssysparm_display_value=all, so both raw (get_value) and label (get_display_value) are available from a single query.Files
pysnc/aggregate.py—GlideAggregate+AggregateTypepysnc/client.py— factory method +StatsAPIpysnc/__init__.py— exporttest/test_snc_aggregate.py— integration tests (mirror thetest_snc_*style)docs/api.rst— document the new classesREADME.md— moved out of "Feature Wants and TODO" + added a Quick StartTest plan
pytest test/test_snc_aggregate.py— 11 integration tests against a live instancemypycleanskipTestwhere they depend on optional demo data (e.g. ITAM assets) so they don't false-fail on instances without itRefs #145