- Record Components:
groupingAttributes- the partition keys; empty means one global groupsortSpecs- within-group ordering; at least one requiredoffset- rows to skip within each group before takingcountcount- number of rows to keep per group; non-negativeinput- the source relation; never nulllocation- the source location of this node; never null
- All Implemented Interfaces:
RelNode
input by groupingAttributes
and, within each group, keeps the count highest rows by
sortSpecs (after skipping offset rows).
This is the "N highest rows per group" operation — top 3 orders by
amount per customer — that SQL forces into a
ROW_NUMBER() OVER (PARTITION BY … ORDER BY …) ≤ k plus an outer filter,
or a lateral join. Unlike a global LimitNode it cannot push down and
buffers each group; unlike an AggregationNode it returns whole rows.
The output schema is the input schema (it is a windowed filter — a row subset). At least one sort specification is required.
The surface syntax always names a partition key (TOP … PER …), but the
grouping list may be empty: that is the global top-N —
one group containing every row — which the optimizer produces by fusing a
λ over a τ (LIM-003). It has no spelling of its own
because λ/τ already is one.
Example: TOP 3 amount DESC PER customer_id (Orders).
-
Constructor Summary
ConstructorsConstructorDescriptionTopKNode(List<String> groupingAttributes, List<SortSpecification> sortSpecs, long count, RelNode input) Convenience constructor for tests; no offset,SourceLocation.UNKNOWN.TopKNode(List<String> groupingAttributes, List<SortSpecification> sortSpecs, Optional<Long> offset, long count, RelNode input, SourceLocation location) Creates an instance of aTopKNoderecord class. -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(RelNodeVisitor<R> visitor) longcount()Returns the value of thecountrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of thegroupingAttributesrecord component.final inthashCode()Returns a hash code value for this object.input()Returns the value of theinputrecord component.location()Returns the value of thelocationrecord component.offset()Returns the value of theoffsetrecord component.Returns the value of thesortSpecsrecord component.final StringtoString()Returns a string representation of this record class.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
-
Constructor Details
-
TopKNode
public TopKNode(List<String> groupingAttributes, List<SortSpecification> sortSpecs, Optional<Long> offset, long count, RelNode input, SourceLocation location) Creates an instance of aTopKNoderecord class.- Parameters:
groupingAttributes- the value for thegroupingAttributesrecord componentsortSpecs- the value for thesortSpecsrecord componentoffset- the value for theoffsetrecord componentcount- the value for thecountrecord componentinput- the value for theinputrecord componentlocation- the value for thelocationrecord component
-
TopKNode
public TopKNode(List<String> groupingAttributes, List<SortSpecification> sortSpecs, long count, RelNode input) Convenience constructor for tests; no offset,SourceLocation.UNKNOWN.
-
-
Method Details
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
groupingAttributes
Returns the value of thegroupingAttributesrecord component.- Returns:
- the value of the
groupingAttributesrecord component
-
sortSpecs
Returns the value of thesortSpecsrecord component.- Returns:
- the value of the
sortSpecsrecord component
-
offset
Returns the value of theoffsetrecord component.- Returns:
- the value of the
offsetrecord component
-
count
public long count()Returns the value of thecountrecord component.- Returns:
- the value of the
countrecord component
-
input
Returns the value of theinputrecord component.- Returns:
- the value of the
inputrecord component
-
location
Returns the value of thelocationrecord component.
-