Github user kiszk commented on a diff in the pull request:
https://github.com/apache/spark/pull/21021#discussion_r180310339
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
---
@@ -116,47 +116,17 @@ case class MapValues(child: Expression)
}
/**
- * Sorts the input array in ascending / descending order according to the
natural ordering of
- * the array elements and returns it.
+ * Common base class for [[SortArray]] and [[ArraySort]].
*/
-// scalastyle:off line.size.limit
-@ExpressionDescription(
- usage = "_FUNC_(array[, ascendingOrder]) - Sorts the input array in
ascending or descending order according to the natural ordering of the array
elements.",
- examples = """
- Examples:
- > SELECT _FUNC_(array('b', 'd', 'c', 'a'), true);
- ["a","b","c","d"]
- """)
-// scalastyle:on line.size.limit
-case class SortArray(base: Expression, ascendingOrder: Expression)
- extends BinaryExpression with ExpectsInputTypes with CodegenFallback {
-
- def this(e: Expression) = this(e, Literal(true))
+trait ArraySortUtil extends ExpectsInputTypes with CodegenFallback {
+ protected def arrayExpression: Expression
- override def left: Expression = base
- override def right: Expression = ascendingOrder
- override def dataType: DataType = base.dataType
- override def inputTypes: Seq[AbstractDataType] = Seq(ArrayType,
BooleanType)
-
- override def checkInputDataTypes(): TypeCheckResult = base.dataType
match {
- case ArrayType(dt, _) if RowOrdering.isOrderable(dt) =>
- ascendingOrder match {
- case Literal(_: Boolean, BooleanType) =>
- TypeCheckResult.TypeCheckSuccess
- case _ =>
- TypeCheckResult.TypeCheckFailure(
- "Sort order in second argument requires a boolean literal.")
- }
- case ArrayType(dt, _) =>
- TypeCheckResult.TypeCheckFailure(
- s"$prettyName does not support sorting array of type
${dt.simpleString}")
- case _ =>
- TypeCheckResult.TypeCheckFailure(s"$prettyName only supports array
input.")
- }
+ // If -1, place null element at the end of the array
+ protected def placeNullAtEnd: Int = 1
--- End diff --
sure
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]