Record Class AggregationNode
- Record Components:
groupingKeys- the keys to group by; the output columns, in this ordergroupingSets- the grouping sets, as indexes intogroupingKeys; empty for the ordinary grouping by every keyaggregates- the aggregate functions to applyinput- the source relationlocation- the source location of this node; never null
- All Implemented Interfaces:
RelNode
grouping keys and applies aggregate
functions.
A grouping key is a full Operand expression, not merely a column
reference, so a group may be formed over a derived value — e.g.
γ YEAR(occurred_at) → yr, COUNT(id) (Events) — with the common case
γ customer_id, SUM(amount) (Orders) simply grouping over a bare column.
Grouping sets
SQL's ROLLUP, CUBE and GROUPING SETS group the same rows
several ways in one aggregation. Each grouping set is a
list of indexes into groupingKeys(): the rows are grouped by those keys, and
every other key is NULL in the rows the set produces. ROLLUP (region, product)
is the three sets (region, product), (region) and (). An empty
list of sets is the ordinary grouping, by every key at once, and a single set naming
every key is normalised to it.
The sets are held in a canonical shape, so that a node prints as text that parses back to it: each set lists its indexes ascending, and read in order the sets name the keys first in index order. Every key is in at least one set.
-
Constructor Summary
ConstructorsConstructorDescriptionAggregationNode(List<GroupingKey> groupingKeys, List<AggregateFunction> aggregates, RelNode input, SourceLocation location) An ordinary grouping, by every key at once.AggregationNode(List<GroupingKey> groupingKeys, List<List<Integer>> groupingSets, List<AggregateFunction> aggregates, RelNode input, SourceLocation location) Creates an instance of aAggregationNoderecord class.AggregationNode(List<String> groupingColumns, List<AggregateFunction> aggregates, RelNode input) Convenience constructor grouping by bare column names — the classic form, used throughout call sites and tests that group by plain columns. -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(RelNodeVisitor<R> visitor) Returns the value of theaggregatesrecord component.The grouping sets as they are run: the declared ones, or for an ordinary grouping the one set of every key.final booleanIndicates whether some other object is "equal to" this one.groupingIndex(Operand argument) The key aGROUPING(k)argument names: the key whose expression is the same asargumentwherever each was written, or else, for a bare name, the key whose output column it is.static OptionalIntgroupingIndex(List<GroupingKey> groupingKeys, Operand argument) Returns the value of thegroupingKeysrecord component.Returns the value of thegroupingSetsrecord component.booleanWhether this aggregation groups by more than one set of its keys — aROLLUP,CUBEorGROUPING SETS.final inthashCode()Returns a hash code value for this object.booleaninEverySet(int index) Whether keyindexis in every grouping set, so that no row this node produces has it rolled up to NULL.input()Returns the value of theinputrecord component.location()Returns the value of thelocationrecord component.booleanWhether this node produces a row over an empty input.final StringtoString()Returns a string representation of this record class.This aggregation over another input, with the same keys, grouping sets and aggregates.withKeysAndAggregates(List<GroupingKey> keys, List<AggregateFunction> aggregates) This aggregation with other keys and aggregates, keeping its grouping sets and input.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.darkcollective.relix.ast.RelNode
children, mapChildren, materializationMode, prettyPrint, prettyPrint
-
Constructor Details
-
AggregationNode
public AggregationNode(List<GroupingKey> groupingKeys, List<List<Integer>> groupingSets, List<AggregateFunction> aggregates, RelNode input, SourceLocation location) Creates an instance of aAggregationNoderecord class.- Parameters:
groupingKeys- the value for thegroupingKeysrecord componentgroupingSets- the value for thegroupingSetsrecord componentaggregates- the value for theaggregatesrecord componentinput- the value for theinputrecord componentlocation- the value for thelocationrecord component
-
AggregationNode
public AggregationNode(List<GroupingKey> groupingKeys, List<AggregateFunction> aggregates, RelNode input, SourceLocation location) An ordinary grouping, by every key at once.- Parameters:
groupingKeys- the keys to group byaggregates- the aggregate functions to applyinput- the source relationlocation- the source location of this node; never null
-
AggregationNode
public AggregationNode(List<String> groupingColumns, List<AggregateFunction> aggregates, RelNode input) Convenience constructor grouping by bare column names — the classic form, used throughout call sites and tests that group by plain columns. UsesSourceLocation.UNKNOWN. Anullcolumn list is preserved as a null grouping (ungrouped aggregation).
-
-
Method Details
-
withInput
This aggregation over another input, with the same keys, grouping sets and aggregates.- Parameters:
newInput- the input to aggregate- Returns:
- the node over
newInput
-
withKeysAndAggregates
public AggregationNode withKeysAndAggregates(List<GroupingKey> keys, List<AggregateFunction> aggregates) This aggregation with other keys and aggregates, keeping its grouping sets and input. The keys replace the current ones position for position.- Parameters:
keys- the replacement keys, as many as there are nowaggregates- the replacement aggregates- Returns:
- the node with them
-
hasGroupingSets
public boolean hasGroupingSets()Whether this aggregation groups by more than one set of its keys — aROLLUP,CUBEorGROUPING SETS.- Returns:
truefor several grouping sets
-
effectiveGroupingSets
The grouping sets as they are run: the declared ones, or for an ordinary grouping the one set of every key.- Returns:
- the sets, each a list of key indexes ascending
-
inEverySet
public boolean inEverySet(int index) Whether keyindexis in every grouping set, so that no row this node produces has it rolled up to NULL.- Parameters:
index- a key index- Returns:
truewhen every set groups by it
-
producesRowOverEmptyInput
public boolean producesRowOverEmptyInput()Whether this node produces a row over an empty input. It does when one of its grouping sets is empty, as an ungrouped aggregate gives its one row of totals.- Returns:
truewhen an empty input still produces a row
-
groupingIndex
The key aGROUPING(k)argument names: the key whose expression is the same asargumentwherever each was written, or else, for a bare name, the key whose output column it is.- Parameters:
argument- an argument ofGROUPING- Returns:
- the key's index, or empty when it names none
-
groupingIndex
- Parameters:
groupingKeys- the keys of a γargument- an argument ofGROUPING- Returns:
- the key's index, or empty when it names none
-
accept
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
groupingKeys
Returns the value of thegroupingKeysrecord component.- Returns:
- the value of the
groupingKeysrecord component
-
groupingSets
Returns the value of thegroupingSetsrecord component.- Returns:
- the value of the
groupingSetsrecord component
-
aggregates
Returns the value of theaggregatesrecord component.- Returns:
- the value of the
aggregatesrecord component
-
input
Returns the value of theinputrecord component.- Returns:
- the value of the
inputrecord component
-
location
Returns the value of thelocationrecord component.
-