You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2023/01/14 11:40:12 UTC
[arrow-datafusion] branch master updated: Visit subqueries in `Expr::Alias` (#4900)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new 42c81be3e Visit subqueries in `Expr::Alias` (#4900)
42c81be3e is described below
commit 42c81be3e1ebd41d55108558afc9fb8e6de988ee
Author: askoa <11...@users.noreply.github.com>
AuthorDate: Sat Jan 14 06:40:07 2023 -0500
Visit subqueries in `Expr::Alias` (#4900)
Co-authored-by: devt <de...@local>
---
datafusion/expr/src/logical_plan/plan.rs | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs
index 576ba161a..5ac8800d5 100644
--- a/datafusion/expr/src/logical_plan/plan.rs
+++ b/datafusion/expr/src/logical_plan/plan.rs
@@ -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);
@@ -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;
@@ -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()?;