Skip to content
Snippets Groups Projects
Commit 6aceaf3d authored by Josh Rosen's avatar Josh Rosen
Browse files

[SPARK-9295] Analysis should detect sorting on unsupported column types

This patch extends CheckAnalysis to throw errors for queries that try to sort on unsupported column types, such as ArrayType.

Author: Josh Rosen <joshrosen@databricks.com>

Closes #7633 from JoshRosen/SPARK-9295 and squashes the following commits:

23b2fbf [Josh Rosen] Embed function in foreach
bfe1451 [Josh Rosen] Update to allow sorting by null literals
2f1b802 [Josh Rosen] Add analysis rule to detect sorting on unsupported column types (SPARK-9295)
parent e2531245
No related branches found
No related tags found
No related merge requests found
......@@ -103,6 +103,16 @@ trait CheckAnalysis {
aggregateExprs.foreach(checkValidAggregateExpression)
case Sort(orders, _, _) =>
orders.foreach { order =>
order.dataType match {
case t: AtomicType => // OK
case NullType => // OK
case t =>
failAnalysis(s"Sorting is not supported for columns of type ${t.simpleString}")
}
}
case _ => // Fallbacks to the following checks
}
......
......@@ -113,6 +113,11 @@ class AnalysisErrorSuite extends SparkFunSuite with BeforeAndAfter {
testRelation.select(Literal(1).cast(BinaryType).as('badCast)),
"cannot cast" :: Literal(1).dataType.simpleString :: BinaryType.simpleString :: Nil)
errorTest(
"sorting by unsupported column types",
listRelation.orderBy('list.asc),
"sorting" :: "type" :: "array<int>" :: Nil)
errorTest(
"non-boolean filters",
testRelation.where(Literal(1)),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment