Skip to content

Commit 1079113

Browse files
waralexromMazterQyou
authored andcommitted
Fix an issue where the query with subqueries in SELECT and WHERE won't execute
1 parent e4a6562 commit 1079113

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

datafusion/core/src/physical_plan/planner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ pub fn create_physical_expr(
10331033
let cursors = execution_props.outer_query_cursors.clone();
10341034
let cursor = cursors
10351035
.iter()
1036+
.rev()
10361037
.find(|cur| cur.schema().field_with_name(c.name.as_str()).is_ok())
10371038
.ok_or_else(|| {
10381039
DataFusionError::Execution(format!(

datafusion/core/tests/sql/subquery.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ async fn subquery_where_with_from() -> Result<()> {
104104
}
105105

106106
// TODO: plans but does not execute
107-
#[ignore]
108107
#[tokio::test]
109108
async fn subquery_select_and_where_no_from() -> Result<()> {
110109
let ctx = SessionContext::new();
111110
register_aggregate_simple_csv(&ctx).await?;
112111

113-
let sql = "SELECT c1, (SELECT c1 + 1) FROM aggregate_simple o WHERE (SELECT NOT c3) ORDER BY c1 LIMIT 2";
112+
let sql = "SELECT c1, (SELECT c1 + 1) FROM aggregate_simple o WHERE (SELECT NOT c3) ORDER BY c1 LIMIT 3";
114113
let actual = execute_to_batches(&ctx, sql).await;
115114

116115
let expected = vec![
117116
"+---------+------------------+",
118117
"| c1 | c1 Plus Int64(1) |",
119118
"+---------+------------------+",
120119
"| 0.00002 | 1.00002 |",
120+
"| 0.00002 | 1.00002 |",
121121
"| 0.00004 | 1.00004 |",
122122
"+---------+------------------+",
123123
];
@@ -127,7 +127,6 @@ async fn subquery_select_and_where_no_from() -> Result<()> {
127127
}
128128

129129
// TODO: plans but does not execute
130-
#[ignore]
131130
#[tokio::test]
132131
async fn subquery_select_and_where_with_from() -> Result<()> {
133132
let ctx = SessionContext::new();

0 commit comments

Comments
 (0)