Record Class SortSpecification
- Record Components:
expression- the value to order by; never nulldirection- ascending or descending; never nullnulls- where NULLs land in the output; never null
Operand expression to order by, the direction
(SortDirection.ASC / SortDirection.DESC), and where its
NULLs go.
The expression is a full scalar expression, not merely a column reference,
so a relation may be ordered by a derived value — e.g.
τ to_timestamp(logged) DESC (RawLogs). The common case
τ name (Users) is simply an ordering by a bare AttributeOperand.
nulls is where a missing value lands in the output, whichever way the key
runs: NullPlacement.NULLS_LAST puts NULLs after every value, and
NullPlacement.NULLS_FIRST before them. SQL's NULLS FIRST and
NULLS LAST set it. A key written without either sorts NULL as the largest
value, as PostgreSQL and Oracle do: last ascending and first descending
(defaultNulls(SortDirection)), so writing the default out builds an equal
key.
-
Constructor Summary
ConstructorsConstructorDescriptionSortSpecification(Operand expression, SortDirection direction) A sort key with the default placement, NULL as the largest value: last ascending and first descending.SortSpecification(Operand expression, SortDirection direction, NullPlacement nulls) Creates an instance of aSortSpecificationrecord class.SortSpecification(String attribute, SortDirection direction) Convenience constructor for a sort key over a bare column — wrapsattributeas anAttributeOperand. -
Method Summary
Modifier and TypeMethodDescriptionThe input column name this key orders by, iff the key is a bare attribute reference; empty for a derived expression.static NullPlacementdefaultNulls(SortDirection direction) Where a key runningdirectionputs its NULLs when it does not say: NULL is the largest value, as in PostgreSQL and Oracle, soNullPlacement.NULLS_LASTascending andNullPlacement.NULLS_FIRSTdescending.Returns the value of thedirectionrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theexpressionrecord component.final inthashCode()Returns a hash code value for this object.nulls()Returns the value of thenullsrecord component.TheNULLSclause that writes this key's placement, when it is not the default for its direction:" NULLS FIRST"on an ascending key that says so," NULLS LAST"on such a descending one, and""otherwise.render()This sort key as Relix text, as aτwrites it: the expression, thenDESCfor a descending key and theNULLS clausefor one whose placement is not its direction's default.This sort key as Relix text, as aτwrites it: the expression asOperand.prettyPrint(Spelling)renders it, thenDESCfor a descending key and theNULLS clausefor one whose placement is not its direction's default.final StringtoString()Returns a string representation of this record class.withExpression(Operand expression) This key withexpressionin place of its own, keeping its direction and NULL placement.
-
Constructor Details
-
SortSpecification
Creates an instance of aSortSpecificationrecord class.- Parameters:
expression- the value for theexpressionrecord componentdirection- the value for thedirectionrecord componentnulls- the value for thenullsrecord component
-
SortSpecification
A sort key with the default placement, NULL as the largest value: last ascending and first descending.- Parameters:
expression- the value to order by; never nulldirection- ascending or descending; never null
-
SortSpecification
Convenience constructor for a sort key over a bare column — wrapsattributeas anAttributeOperand. Keeps the many call sites (and tests) that sort by a plain column name unchanged.
-
-
Method Details
-
defaultNulls
Where a key runningdirectionputs its NULLs when it does not say: NULL is the largest value, as in PostgreSQL and Oracle, soNullPlacement.NULLS_LASTascending andNullPlacement.NULLS_FIRSTdescending. MySQL, SQL Server and SQLite take NULL as the smallest, the other way in both directions.- Parameters:
direction- ascending or descending; never null- Returns:
- the placement a key without
NULLS FIRSTorNULLS LASThas - Since:
- 1.0
-
nullsClause
TheNULLSclause that writes this key's placement, when it is not the default for its direction:" NULLS FIRST"on an ascending key that says so," NULLS LAST"on such a descending one, and""otherwise. Each printer of a key appends it, so the text parses back to an equal key.- Returns:
- the clause with its leading space, or
""; never null - Since:
- 1.0
-
columnName
The input column name this key orders by, iff the key is a bare attribute reference; empty for a derived expression. Ordering-property reasoning andORDER BYpushdown use this to distinguish a plain column from a computed key.- Returns:
- the unqualified column name, or empty for an expression key
-
render
This sort key as Relix text, as aτwrites it: the expression, thenDESCfor a descending key and theNULLS clausefor one whose placement is not its direction's default. The same asrender(Spelling.GLYPHS).- Returns:
- the key as
.relixtext, such asprice * qty DESC; never null - Since:
- 1.0
-
render
This sort key as Relix text, as aτwrites it: the expression asOperand.prettyPrint(Spelling)renders it, thenDESCfor a descending key and theNULLS clausefor one whose placement is not its direction's default. An ascending key is written without a direction, which is what aτreads as ascending, soSORT <key> (T)parses back to an equal key.- Parameters:
spelling- glyphs or ASCII keywords for a condition the expression holds; must not be null- Returns:
- the key as
.relixtext, such asprice * qty DESC; never null - Since:
- 1.0
-
withExpression
This key withexpressionin place of its own, keeping its direction and NULL placement.- Parameters:
expression- the value to order by; never null- Returns:
- the key
- Since:
- 1.0
-
nullPlacement
Where NULLs go in this key's ascending comparator, the one a descending key reverses:nulls()for an ascending key, and the other placement for a descending one, so that reversing it lands NULLs wherenulls()says.A comparator built from it and then reversed for
SortDirection.DESCorders exactly as this key does; the sort executor and the merge-join comparator both build theirs that way.- Returns:
- the placement before the direction is applied; never null
-
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). -
expression
Returns the value of theexpressionrecord component.- Returns:
- the value of the
expressionrecord component
-
direction
Returns the value of thedirectionrecord component.- Returns:
- the value of the
directionrecord component
-
nulls
Returns the value of thenullsrecord component.- Returns:
- the value of the
nullsrecord component
-