Skip to content

SortOrder

SortOrder is an Expression that represents the following operators in a structured query:

SortOrder is also used to specify the output data ordering requirements and the required child ordering of physical operators.

Creating Instance

SortOrder takes the following to be created:

SortDirection

SortDirection Default Null Ordering SQL
Ascending NullsFirst ASC
Descending NullsLast DESC

NullOrdering

NullOrdering SQL
NullsFirst NULLS FIRST
NullsLast NULLS LAST

Creating SortOrder

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

apply creates a SortOrder (with the defaultNullOrdering of the given SortDirection).


apply is created when:

Catalyst DSL

Catalyst DSL defines the following operators to create SortOrders:

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

Unevaluable

SortOrder is an Unevaluable expression.