Skip to content

Commit

Permalink
Report offending plan node when In/Exist subquery misused
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Oct 29, 2024
1 parent 132b232 commit 6629a35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion datafusion/optimizer/src/analyzer/subquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ pub fn check_subquery_expr(
| LogicalPlan::Join(_) => Ok(()),
_ => plan_err!(
"In/Exist subquery can only be used in \
Projection, Filter, Window functions, Aggregate and Join plan nodes"
Projection, Filter, Window functions, Aggregate and Join plan nodes, \
but was used in [{}]",
outer_plan.display()
),
}?;
check_correlations_in_subquery(inner_plan)
Expand Down
7 changes: 6 additions & 1 deletion datafusion/sqllogictest/test_files/subquery.slt
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,13 @@ SELECT t1_id, t1_name, t1_int, (select t2_id, t2_name FROM t2 WHERE t2.t2_id = t

#subquery_not_allowed
#In/Exist Subquery is not allowed in ORDER BY clause.
statement error DataFusion error: check_analyzed_plan\ncaused by\nError during planning: In/Exist subquery can only be used in Projection, Filter, Window functions, Aggregate and Join plan nodes
statement error
SELECT t1_id, t1_name, t1_int FROM t1 order by t1_int in (SELECT t2_int FROM t2 WHERE t1.t1_id > t1.t1_int)
----
DataFusion error: check_analyzed_plan
caused by
Error during planning: In/Exist subquery can only be used in Projection, Filter, Window functions, Aggregate and Join plan nodes, but was used in [Sort: t1.t1_int IN (<subquery>) ASC NULLS LAST]


#non_aggregated_correlated_scalar_subquery
statement error DataFusion error: check_analyzed_plan\ncaused by\nError during planning: Correlated scalar subquery must be aggregated to return at most one row
Expand Down

0 comments on commit 6629a35

Please sign in to comment.