Skip to content

Commit

Permalink
Formatting + forgotten pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondop committed Apr 24, 2024
1 parent a0936f6 commit be24f65
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions datafusion/core/src/physical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result<String> {
} else {
Ok(c.flat_name())
}
},
}
Expr::Columns(c) => {
let names:Vec<String> = c.iter().map(|c| c.flat_name()).collect();
let names: Vec<String> = c.iter().map(|c| c.flat_name()).collect();
Ok(names.join(","))
}
Expr::Alias(Alias { name, .. }) => Ok(name.clone()),
Expand Down
9 changes: 4 additions & 5 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<(), _>>()?
)
}
Expr::Columns(c) => Ok(c
.iter()
.map(|column| write!(f, "{},", column))
.collect::<Result<(), _>>()?),
Expr::OuterReferenceColumn(_, c) => write!(f, "outer_ref({c})"),
Expr::ScalarVariable(_, var_names) => write!(f, "{}", var_names.join(".")),
Expr::Literal(v) => write!(f, "{v:?}"),
Expand Down
12 changes: 8 additions & 4 deletions datafusion/expr/src/expr_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -286,7 +287,10 @@ impl ExprSchemable for Expr {

Expr::Column(c) => input_schema.nullable(c),
Expr::Columns(c) => {
let column_nullables:Vec<bool> = c.iter().map(|col| input_schema.nullable(col)).collect::<Result<Vec<_>>>()?;
let column_nullables: Vec<bool> = c
.iter()
.map(|col| input_schema.nullable(col))
.collect::<Result<Vec<_>>>()?;
Ok(column_nullables.iter().any(|&x| x))
}
Expr::OuterReferenceColumn(_, _) => Ok(true),
Expand Down Expand Up @@ -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"
),
Expand Down
2 changes: 1 addition & 1 deletion datafusion/expr/src/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_, _)
Expand Down
7 changes: 7 additions & 0 deletions datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<_, _>>()?;
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())?;
Expand Down

0 comments on commit be24f65

Please sign in to comment.