Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Visit subqueries in Expr::Alias #4900

Merged
merged 1 commit into from
Jan 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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