java.lang.Object
com.darkcollective.relix.ast.Ordering
A sort ordering — the sequence of (column, direction) keys by which a relation's
rows are ordered. Used to reason about delivered
orderings (what a sub-tree already produces) versus required orderings
(what an operator needs), so a redundant sort can be eliminated.
none() is the empty ordering — no guaranteed row order.
Ordering is a physical-flavoured property (it describes how rows are
produced, not just the set of rows); this Phase-C1 form reasons about it at the
logical level — τ establishes an order and order-preserving operators
carry it — which is enough to remove a redundant τ. Null placement is
deliberately omitted until the merge operators (Phase C2) need it.
Instances are immutable value objects.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanclusters(Collection<String> columns) Whether this ordering clusters every duplicate of a row overcolumnsadjacently — i.e.booleanbooleangroupsBy(Collection<String> groupingKeys) Whether this ordering groups rows bygroupingKeyscontiguously — its leading keys (the firstgroupingKeys.size()) are exactly that set of columns (order and direction among them are irrelevant for grouping).inthashCode()keys()The ordered sort keys of this ordering.static Orderingnone()The empty ordering — no guaranteed order.static Orderingof(List<SortSpecification> keys) An ordering by the given sort keys, in priority order.booleanWhether this (delivered) ordering satisfies therequiredordering — i.e.toString()
-
Method Details
-
none
The empty ordering — no guaranteed order.- Returns:
- the empty ordering; never null
-
of
An ordering by the given sort keys, in priority order.- Parameters:
keys- the ordered sort keys; must not be null (empty yieldsnone())- Returns:
- the ordering; never null
-
keys
The ordered sort keys of this ordering.- Returns:
- an immutable list of sort keys; never null, possibly empty
-
satisfies
Whether this (delivered) ordering satisfies therequiredordering — i.e.requiredis a prefix of this ordering. A relation sorted by(x, y)is also sorted by(x), so it satisfies a requirement for(x); but a relation sorted only by(x)does not satisfy a requirement for(x, y). Direction is compared too: ascending does not satisfy a descending requirement.- Parameters:
required- the ordering that must be satisfied; must not be null- Returns:
trueif this ordering satisfiesrequired
-
clusters
Whether this ordering clusters every duplicate of a row overcolumnsadjacently — i.e. its keys cover all ofcolumns(direction is irrelevant for clustering). When the whole row is covered, fully-equal rows are guaranteed contiguous, so aδ(DISTINCT) can deduplicate in a single linear pass instead of buffering a hash set.- Parameters:
columns- the columns that must all appear among this ordering's keys; must not be null- Returns:
trueif every column incolumnsis an ordering key
-
groupsBy
Whether this ordering groups rows bygroupingKeyscontiguously — its leading keys (the firstgroupingKeys.size()) are exactly that set of columns (order and direction among them are irrelevant for grouping). When this holds, every group of equalgroupingKeysis contiguous, so aγ(GROUP) can aggregate in a single linear pass holding only one group at a time.Empty
groupingKeys(a scalar, whole-relation aggregate) never groups contiguously in this sense — it still has to read the whole input — so this returnsfalse.- Parameters:
groupingKeys- the grouping-key columns; must not be null- Returns:
trueif this ordering's leading keys are exactlygroupingKeys
-
equals
-
hashCode
public int hashCode() -
toString
-