Description
Users can trigger an illegal state exception by the SQL statement:
> select (select a from (select 1 as a union all select 2 as a) t) as b
Caused by: java.lang.IllegalStateException: more than one row returned by a subquery used as an expression:
Subquery subquery#242, [id=#100]
+- AdaptiveSparkPlan isFinalPlan=true
+- == Final Plan ==
Union
:- *(1) Project [1 AS a#240]
: +- *(1) Scan OneRowRelation[]
+- *(2) Project [2 AS a#241]
+- *(2) Scan OneRowRelation[]
+- == Initial Plan ==
Union
:- Project [1 AS a#240]
: +- Scan OneRowRelation[]
+- Project [2 AS a#241]
+- Scan OneRowRelation[]
at org.apache.spark.sql.execution.ScalarSubquery.updateResult(subquery.scala:83)
but such kind of exceptions are not supposed to be visible to users. Need to introduce an error class (or re-use an existing one), and replace the IllegalStateException.