Skip to content

SortOrder Unevaluable Unary Expression

SortOrder is a <> that represents the following operators in a logical plan:

  • AstBuilder is requested to <>

  • <>, <>, <>, <>, <>, and <> operators are used

SortOrder is used to specify the <> of a physical operator.

SortOrder is an unevaluable expression.

[[foldable]] SortOrder is never <> (as an unevaluable expression with no evaluation).

[[catalyst-dsl]] TIP: Use <>, <>, <> or <> operators from the Catalyst DSL to create a SortOrder expression, e.g. for testing or Spark SQL internals exploration.

NOTE: <>, <>, <> and <> default to <> sort direction.

=== [[apply]] Creating SortOrder Instance -- apply Factory Method

[source, scala]

apply( child: Expression, direction: SortDirection, sameOrderExpressions: Set[Expression] = Set.empty): SortOrder


apply is a convenience method to create a <> with the defaultNullOrdering of the <>.

NOTE: apply is used exclusively in spark-sql-functions-datetime.md#window[window] function.

=== [[asc]][[asc_nullsLast]][[desc]][[desc_nullsFirst]] Catalyst DSL -- asc, asc_nullsLast, desc and desc_nullsFirst Operators

[source, scala]

asc: SortOrder asc_nullsLast: SortOrder desc: SortOrder desc_nullsFirst: SortOrder


asc, asc_nullsLast, desc and desc_nullsFirst <> a SortOrder expression with the Ascending or Descending sort direction, respectively.

[source, scala]

import org.apache.spark.sql.catalyst.dsl.expressions._ val sortNullsLast = 'id.asc_nullsLast scala> println(sortNullsLast.sql) id ASC NULLS LAST


=== [[creating-instance]] Creating SortOrder Instance

SortOrder takes the following when created:

  • [[child]] Child <>
  • [[direction]] <>
  • [[nullOrdering]] NullOrdering
  • [[sameOrderExpressions]] "Same Order" <>

=== [[SortDirection]] SortDirection Contract

SortDirection is the <> of <>.

[[SortDirection-contract]] .SortDirection Contract [cols="1m,2",options="header",width="100%"] |=== | Method | Description

| defaultNullOrdering a| [[defaultNullOrdering]]

[source, scala]

defaultNullOrdering: NullOrdering

Used when...FIXME

| sql a| [[sql]]

[source, scala]

sql: String

Used when...FIXME |===

==== [[SortDirection-extensions]][[Ascending]][[Descending]] Ascending and Descending Sort Directions

There are two <> available, i.e. Ascending and Descending.


Last update: 2021-02-18
Back to top