Class: ForestAdminDatasourceGraphqlHasura::Query::Aggregator
- Inherits:
-
Object
- Object
- ForestAdminDatasourceGraphqlHasura::Query::Aggregator
- Defined in:
- lib/forest_admin_datasource_graphql_hasura/query/aggregator.rb
Overview
Runs Forest aggregations against Hasura on behalf of a collection.
Hasura exposes GROUP BY only through a nested <relation>_aggregate on a
parent object, so a grouped aggregation goes through the parent table and is
reduced here rather than by the database.
Constant Summary collapse
- ForestException =
ForestAdminDatasourceToolkit::Exceptions::ForestException
- PARENT_PAGE =
Parent rows are reduced in Ruby, so they are paginated by PARENT_PAGE and capped at MAX_PARENT_ROWS: past the cap the chart fails with a clear error rather than silently charting a subset.
1000- MAX_PARENT_ROWS =
10_000- DANGLING_KEYS_LIMIT =
At most this many distinct dangling foreign keys get a group of their own; beyond that the data is corrupt enough to deserve an error.
100
Instance Method Summary collapse
-
#initialize(collection) ⇒ Aggregator
constructor
A new instance of Aggregator.
- #run(filter, aggregation, limit) ⇒ Object
Constructor Details
#initialize(collection) ⇒ Aggregator
Returns a new instance of Aggregator.
23 24 25 |
# File 'lib/forest_admin_datasource_graphql_hasura/query/aggregator.rb', line 23 def initialize(collection) @collection = collection end |
Instance Method Details
#run(filter, aggregation, limit) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/forest_admin_datasource_graphql_hasura/query/aggregator.rb', line 27 def run(filter, aggregation, limit) validate(aggregation) @date_field = date_field?(aggregation) if aggregation.groups.nil? || aggregation.groups.empty? simple(filter, aggregation) else grouped(filter, aggregation, limit) end end |