Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ case class TakeOrderedAndProjectExec(
projectList.map(_.toAttribute)
}

override def executeCollect(): Array[InternalRow] = {
override def executeCollect(): Array[InternalRow] = executeQuery {
val orderingSatisfies = SortOrder.orderingSatisfies(child.outputOrdering, sortOrder)
val ord = new LazilyGeneratedOrdering(sortOrder, child.output)
val limited = if (orderingSatisfies) {
Expand Down
24 changes: 24 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2711,4 +2711,28 @@ class SubquerySuite extends QueryTest
checkAnswer(df, Row(1, "foo", 1, "foo"))
}
}

test("SPARK-45584: subquery execution should not fail with ORDER BY and LIMIT") {
withTable("t1") {
sql(
"""
|CREATE TABLE t1 USING PARQUET
|AS SELECT * FROM VALUES
|(1, "a"),
|(2, "a"),
|(3, "a") t(id, value)
|""".stripMargin)
val df = sql(
"""
|WITH t2 AS (
| SELECT * FROM t1 ORDER BY id
|)
|SELECT *, (SELECT COUNT(*) FROM t2) FROM t2 LIMIT 10
|""".stripMargin)
// This should not fail with IllegalArgumentException.
checkAnswer(
df,
Row(1, "a", 3) :: Row(2, "a", 3) :: Row(3, "a", 3) :: Nil)
}
}
}