Skip to content

Commit

Permalink
Visit subqueries in Expr::Alias (#4900)
Browse files Browse the repository at this point in the history
Co-authored-by: devt <devg@local>
  • Loading branch information
askoa and devt authored Jan 14, 2023
1 parent dee0dd8 commit 42c81be
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ impl LogicalPlan {

fn collect_subqueries(expr: &Expr, sub: &mut Vec<Arc<LogicalPlan>>) {
match expr {
Expr::Alias(expr, ..) => {
Self::collect_subqueries(expr, sub);
}
Expr::BinaryExpr(BinaryExpr { left, right, .. }) => {
Self::collect_subqueries(left, sub);
Self::collect_subqueries(right, sub);
Expand Down Expand Up @@ -1837,7 +1840,7 @@ pub trait ToStringifiedPlan {
mod tests {
use super::*;
use crate::logical_plan::table_scan;
use crate::{col, in_subquery, lit};
use crate::{col, exists, in_subquery, lit};
use arrow::datatypes::{DataType, Field, Schema};
use datafusion_common::DFSchema;
use datafusion_common::Result;
Expand Down Expand Up @@ -1891,6 +1894,26 @@ mod tests {
Ok(())
}

#[test]
fn test_display_subquery_alias() -> Result<()> {
let plan1 = table_scan(Some("employee_csv"), &employee_schema(), Some(vec![3]))?
.build()?;
let plan1 = Arc::new(plan1);

let plan =
table_scan(Some("employee_csv"), &employee_schema(), Some(vec![0, 3]))?
.project(vec![col("id"), exists(plan1).alias("exists")])?
.build();

let expected = "Projection: employee_csv.id, EXISTS (<subquery>) AS exists\
\n Subquery:\
\n TableScan: employee_csv projection=[state]\
\n TableScan: employee_csv projection=[id, state]";

assert_eq!(expected, format!("{}", plan?.display_indent()));
Ok(())
}

#[test]
fn test_display_graphviz() -> Result<()> {
let plan = display_plan()?;
Expand Down

0 comments on commit 42c81be

Please sign in to comment.