name: grouper-design
description: Grouper slot semantics — multi-grouper composition (key product), fused crosstab eligibility, Group.Include inclusion-list, smart defaults per field type. Topical design; per-GROUP detail lives in atomic op-group-* skills.
type: guide
kind: design
applies_to: process, compose, predict
covers: [GROUP, Crosstab, groups]
Grouper design
groups partitions records BEFORE aggregation; each aggregations entry folds inside the bucket.
Slot identity
groups entry: {type, field, interval?, params?, include?}. Output rows carry the bucket key as <field>.
Pipeline: features → filterers → attributes → groups → aggregations → windows → sort; grouping runs AFTER attributes, so attribute labels work as field.
Choosing a grouper
Read the intent first (pulse_skills_get intents): compare_groups, composition, change_over_time, segment or distribution_shape. Manifest components.groupers[] carries each grouper’s intents, accepts_types and params; filter on the field’s type, then decide:
- One bucket per distinct value of a categorical, boolean or low-cardinality field? → the category grouper.
- A number in bands? Fixed-width bands (
"low-high"key or rounded-down floor), or EQUAL-COUNT bands (by rank; equal values may straddle two; buffers the whole input)? - Calendar periods (hour to fiscal year, weekday)? → the date grouper. Custom named periods (campaigns, irregular fiscal quarters)? → the date-ranges grouper.
- Uneven named number bands (train/holdout)? → the numeric-ranges grouper.
- A multi-select field? One bucket per OPTION (fan-out: a record lands in every option it chose) or per exact COMBINATION?
High cardinality. Each distinct key is a bucket; past the instance max_groups the run is refused PULSE_LIMIT_EXCEEDED; pulse_predict flags a dictionary over it in limit_findings.
Composition (key product)
With N ≥ 2 entries a row’s key is the tuple (g0, ..., gN-1); this is the canonical cross-tab mechanism (Request.Crosstab only when margins or normalisation matter — crosstab-guide). Empty groups = one bucket.
- Rows: one per OBSERVED combination (never an empty one), in each grouper’s native key order, outer → inner. Every row carries every grouper’s key column.
- Null key at any position drops the record from every row; each grouper still sees it once, so
n_nullmatches its single-grouper run. - Fan-out groupers multiply: a record lands in each key-set product.
- Fit:
GROUP_QUANTILE/GROUP_KMEANSfit once over the filtered set (params.fitglobal);withinrefits per bucket of the keys before it. - Refused: two entries on one field (
SERVICE_VALIDATION); an extension key containing NUL (PROCESSING_GROUP);OVERLAY_YOYwithout exactly one date grouper (PULSE_OVERLAY_REF_INCOMPATIBLE_WITH_SHAPE). max_groups: predict reports the PRODUCT of per-grouper estimates, an upper bound; the run enforces it on observed ones.- Downstream:
sort,return, windows, post-tests and grouped matrices follow the composite rows. Series overlays (YoY aside) run once per partition: the leading keys (params.partition_by; default all but the last, so put the date grouper last), never crossing a segment (overlay-system).
Smart defaults
When an entry names field but omits type, the engine infers from the schema type:
| Field type | Default grouper |
|---|---|
numeric (u4/u*, f32/f64, decimal128) | GROUP_RANGE (Interval=10) |
categorical_*, packed_bool | GROUP_CATEGORY |
date, datetime | GROUP_DATE (component=day) |
set_* | GROUP_SET_PER_ELEMENT |
Never overrides an explicit type; predict reports filled slots at data.defaults_applied; --no-defaults disables. Table: request-envelope.
Group.Include — inclusion list
Group.Include []string allow-lists bucket keys. An unlisted key (per fan-out key) skips the row, as on null. Empty = no filter. Supported by:
GROUP_CATEGORY— the label string.GROUP_SET_VALUE— the pipe-joined composite key.GROUP_SET_PER_ELEMENT— each fan-out label.GROUP_DATE— the calendar key.GROUP_DATE_RANGES— the range label.
Other groupers refuse it on groups (PROCESSING_CONFIG); filter instead.
Order-significant. A non-empty include also fixes emission order: listed order (grouped Data, the buckets component, each crosstab axis — any grouper). Empty keeps the native key order. Zero-record values drop.
Fused crosstab eligibility
A crosstab builds its grid in one decode pass when every axis grouper keys records one at a time. Every built-in does EXCEPT the equal-count (quantile) grouper, which needs a finalize-time sorted view and forces a buffered crosstab. Fan-out groupers fuse at any axis position. Overlays never prevent fusing.
Components
Every Response.Components.Groupers[i] carries the universal floor total_n (post-filter records partitioned) + n_null (null / skip path) — ALL post-filter records, unlike the aggregator’s non-null n. Operator-specific keys ride operator (manifest.components_schemas.groupers, each atomic skill).
Mergeability is in the manifest: mergeable groupers fold across streaming chunks; a none grouper (equal-count bands) emits at the terminal flush only. With N ≥ 2 there is one entry per slot and groups[].group_key is the tuple.
Gotchas
- Fan-out:
sum(buckets[].count) > total_nis correct; on a crosstab axis its margins are non-additive (a 3-option row counts 3× across row margins, once in the grand total). - Empty-mask
set_*: the combination grouper buckets it under the empty key; the per-option grouper skips it. Neither incrementsn_null. GROUP_DATEday_of_weekbuckets are Monday-first; a sort on a grouper key keeps its order. Only a free-text weekday field lex-sorts.
See
- Recipes:
pulse_examples_search tags=["cross-tabulation"|"survey"]. crosstab-guide(Crosstab shape, margins, normalisation),aggregation-design(what folds inside the bucket),request-envelope(slot keys, smart defaults),time-zones(datetime day buckets,hour,week_start),response-components(grouper floor),streaming-and-watching(streamability).