Skip to content

Commit

Permalink
Fix an issue where the query with subqueries in SELECT and WHERE won'…
Browse files Browse the repository at this point in the history
…t execute
  • Loading branch information
waralexrom authored and MazterQyou committed Feb 8, 2024
1 parent e4a6562 commit 1079113
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions datafusion/core/src/physical_plan/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ pub fn create_physical_expr(
let cursors = execution_props.outer_query_cursors.clone();
let cursor = cursors
.iter()
.rev()
.find(|cur| cur.schema().field_with_name(c.name.as_str()).is_ok())
.ok_or_else(|| {
DataFusionError::Execution(format!(
Expand Down
5 changes: 2 additions & 3 deletions datafusion/core/tests/sql/subquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ async fn subquery_where_with_from() -> Result<()> {
}

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

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

let expected = vec![
"+---------+------------------+",
"| c1 | c1 Plus Int64(1) |",
"+---------+------------------+",
"| 0.00002 | 1.00002 |",
"| 0.00002 | 1.00002 |",
"| 0.00004 | 1.00004 |",
"+---------+------------------+",
];
Expand All @@ -127,7 +127,6 @@ async fn subquery_select_and_where_no_from() -> Result<()> {
}

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

0 comments on commit 1079113

Please sign in to comment.