From be24f652a524d4520ff4982ab9ca246ba13e0686 Mon Sep 17 00:00:00 2001 From: Edmondo Porcu Date: Wed, 24 Apr 2024 23:54:29 +0000 Subject: [PATCH] Formatting + forgotten pieces --- datafusion/core/src/physical_planner.rs | 4 ++-- datafusion/expr/src/expr.rs | 9 ++++----- datafusion/expr/src/expr_schema.rs | 12 ++++++++---- datafusion/expr/src/tree_node.rs | 2 +- datafusion/sql/src/unparser/expr.rs | 7 +++++++ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rs index a775273fe21b..26b14974dcdb 100644 --- a/datafusion/core/src/physical_planner.rs +++ b/datafusion/core/src/physical_planner.rs @@ -145,9 +145,9 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result { } else { Ok(c.flat_name()) } - }, + } Expr::Columns(c) => { - let names:Vec = c.iter().map(|c| c.flat_name()).collect(); + let names: Vec = c.iter().map(|c| c.flat_name()).collect(); Ok(names.join(",")) } Expr::Alias(Alias { name, .. }) => Ok(name.clone()), diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index 4de653bf9c13..29708ee29a6d 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -1402,11 +1402,10 @@ impl fmt::Display for Expr { match self { Expr::Alias(Alias { expr, name, .. }) => write!(f, "{expr} AS {name}"), Expr::Column(c) => write!(f, "{c}"), - Expr::Columns(c) => { - Ok( - c.iter().map(|column| write!(f, "{},", column)).collect::>()? - ) - } + Expr::Columns(c) => Ok(c + .iter() + .map(|column| write!(f, "{},", column)) + .collect::>()?), Expr::OuterReferenceColumn(_, c) => write!(f, "outer_ref({c})"), Expr::ScalarVariable(_, var_names) => write!(f, "{}", var_names.join(".")), Expr::Literal(v) => write!(f, "{v:?}"), diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs index c33acdb3678b..67a4c76bbf2c 100644 --- a/datafusion/expr/src/expr_schema.rs +++ b/datafusion/expr/src/expr_schema.rs @@ -28,7 +28,8 @@ use crate::{utils, LogicalPlan, Projection, Subquery}; use arrow::compute::can_cast_types; use arrow::datatypes::{DataType, Field, Fields}; use datafusion_common::{ - internal_err, not_impl_err, plan_datafusion_err, plan_err, Column, DataFusionError, ExprSchema, Result, TableReference + internal_err, not_impl_err, plan_datafusion_err, plan_err, Column, DataFusionError, + ExprSchema, Result, TableReference, }; use std::collections::HashMap; use std::sync::Arc; @@ -286,7 +287,10 @@ impl ExprSchemable for Expr { Expr::Column(c) => input_schema.nullable(c), Expr::Columns(c) => { - let column_nullables:Vec = c.iter().map(|col| input_schema.nullable(col)).collect::>>()?; + let column_nullables: Vec = c + .iter() + .map(|col| input_schema.nullable(col)) + .collect::>>()?; Ok(column_nullables.iter().any(|&x| x)) } Expr::OuterReferenceColumn(_, _) => Ok(true), @@ -337,8 +341,8 @@ impl ExprSchemable for Expr { Expr::Like(Like { expr, pattern, .. }) | Expr::SimilarTo(Like { expr, pattern, .. }) => { Ok(expr.nullable(input_schema)? || pattern.nullable(input_schema)?) - }, - + } + Expr::Wildcard { .. } => internal_err!( "Wildcard expressions are not valid in a logical query plan" ), diff --git a/datafusion/expr/src/tree_node.rs b/datafusion/expr/src/tree_node.rs index 320881c3435d..8c581c6aa1cc 100644 --- a/datafusion/expr/src/tree_node.rs +++ b/datafusion/expr/src/tree_node.rs @@ -69,7 +69,7 @@ impl TreeNode for Expr { Expr::GroupingSet(GroupingSet::GroupingSets(lists_of_exprs)) => { lists_of_exprs.iter().flatten().collect() } - Expr::Column(_) + Expr::Column(_) | Expr::Columns(_) // Treat OuterReferenceColumn as a leaf expression | Expr::OuterReferenceColumn(_, _) diff --git a/datafusion/sql/src/unparser/expr.rs b/datafusion/sql/src/unparser/expr.rs index d091fbe14dbd..3c6fd389cccd 100644 --- a/datafusion/sql/src/unparser/expr.rs +++ b/datafusion/sql/src/unparser/expr.rs @@ -117,6 +117,13 @@ impl Unparser<'_> { )))) } Expr::Column(col) => self.col_to_sql(col), + Expr::Columns(cols) => { + let cols = cols + .iter() + .map(|c| self.col_to_sql(c)) + .collect::>()?; + Ok(ast::Expr::Tuple(cols)) + } Expr::BinaryExpr(BinaryExpr { left, op, right }) => { let l = self.expr_to_sql(left.as_ref())?; let r = self.expr_to_sql(right.as_ref())?;