Documentation
¶
Overview ¶
Package aggregate reads a metric's aggregation, written as pseudocode SQL (TAXONOMY.md D64): one aggregate function over one field or every entry, and an optional condition on the source's own fields.
COUNT(*) WHERE graded_at = 'intake'
SUM(weight_kg) WHERE grade IN ('first', 'second') AND weight_kg > 0
It is not SQL: it names no table, no join and no other source, which belong to the warehouse model behind the source, set outside Cartograph. What it reads it says in words (Reading), lists the names it uses (Names) and renders as a semantic layer measure (Measure).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregation ¶
type Aggregation struct {
// Func is COUNT, SUM, AVG, MIN or MAX.
Func string
// Distinct counts each value of Field once.
Distinct bool
// Field is what is aggregated; empty for every entry, COUNT(*).
Field string
// Where is the condition on the entries counted; nil for all of them.
Where *Node
}
Aggregation is what a text reads as.
func Parse ¶
func Parse(text string) (Aggregation, error)
Parse reads text as an aggregation. A text that does not read as one answers the first problem found.
func (Aggregation) Measure ¶
func (a Aggregation) Measure() (agg, expr string)
Measure is an aggregation as a semantic layer measure: the aggregation in the layer's words (count, count_distinct, sum, average, min, max) and the expression it aggregates, the condition folded in as a CASE WHEN, since a measure has no filter of its own.
func (Aggregation) Names ¶
func (a Aggregation) Names() []string
Names are the fields an aggregation uses, each once, in the order written.
func (Aggregation) Reading ¶
func (a Aggregation) Reading() string
Reading is what an aggregation says, in words.
type Node ¶
type Node struct {
// Op is "and", "or", "not", or a comparison: = != < <= > >= in
// between like null notnull. A comparison negated by NOT IN, NOT
// BETWEEN or NOT LIKE carries Not.
Op string
Not bool
Kids []*Node
Field string
// Values are the comparison's values, as written (a string keeps its
// quotes).
Values []string
}
Node is a condition: an AND, an OR or a NOT of others, or a comparison.