Skip to content

Commit

Permalink
cargo fmt clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmedal committed Aug 5, 2024
1 parent 63ce513 commit 59cf620
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion datafusion/expr/src/expr_rewriter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn coerce_exprs_for_schema(
Expr::Alias(Alias { expr, name, .. }) => {
Ok(expr.cast_to(new_type, src_schema)?.alias(name))
}
Expr::Wildcard {..} => Ok(expr),
Expr::Wildcard { .. } => Ok(expr),
_ => expr.cast_to(new_type, src_schema),
}
} else {
Expand Down
17 changes: 10 additions & 7 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,13 +1977,16 @@ impl Projection {
input: Arc<LogicalPlan>,
schema: DFSchemaRef,
) -> Result<Self> {
let expr_len: usize = expr.iter().map(|e| match e {
Expr::Wildcard { qualifier: None } => schema.fields().len(),
Expr::Wildcard { qualifier: Some(qualifier)} => {
schema.fields_with_qualified(qualifier).len()
}
_ => 1,
}).sum();
let expr_len: usize = expr
.iter()
.map(|e| match e {
Expr::Wildcard { qualifier: None } => schema.fields().len(),
Expr::Wildcard {
qualifier: Some(qualifier),
} => schema.fields_with_qualified(qualifier).len(),
_ => 1,
})
.sum();
if expr_len != schema.fields().len() {
return plan_err!("Projection has mismatch between number of expressions ({}) and number of fields in schema ({})", expr_len, schema.fields().len());
}
Expand Down
42 changes: 25 additions & 17 deletions datafusion/expr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ use datafusion_common::tree_node::{
Transformed, TransformedResult, TreeNode, TreeNodeRecursion,
};
use datafusion_common::utils::get_at_indices;
use datafusion_common::{internal_err, plan_datafusion_err, plan_err, Column, DFSchema, DFSchemaRef, Result, ScalarValue, TableReference};
use datafusion_common::{
internal_err, plan_datafusion_err, plan_err, Column, DFSchema, DFSchemaRef, Result,
ScalarValue, TableReference,
};

use sqlparser::ast::{ExceptSelectItem, ExcludeSelectItem, WildcardAdditionalOptions};

Expand Down Expand Up @@ -728,24 +731,29 @@ pub fn exprlist_to_fields<'a>(
) -> Result<Vec<(Option<TableReference>, Arc<Field>)>> {
// look for exact match in plan's output schema
let input_schema = &plan.schema();
exprs.into_iter().flat_map(|e| {
match e {
Expr::Wildcard { qualifier } => {
match qualifier {
None => (0..input_schema.fields().len())
.map(|i| Ok(input_schema.qualified_field(i))
.map(|(qualifier, field)| (qualifier.cloned(), Arc::new(field.to_owned()))))
.collect::<Vec<_>>(),
Some(qualifier) => input_schema
.fields_with_qualified(qualifier)
.into_iter()
.map(|field| Ok((Some(qualifier.clone()), Arc::new(field.to_owned()))))
.collect::<Vec<_>>(),
}.into_iter()
exprs
.into_iter()
.flat_map(|e| match e {
Expr::Wildcard { qualifier } => match qualifier {
None => (0..input_schema.fields().len())
.map(|i| {
Ok(input_schema.qualified_field(i)).map(|(qualifier, field)| {
(qualifier.cloned(), Arc::new(field.to_owned()))
})
})
.collect::<Vec<_>>(),
Some(qualifier) => input_schema
.fields_with_qualified(qualifier)
.into_iter()
.map(|field| {
Ok((Some(qualifier.clone()), Arc::new(field.to_owned())))
})
.collect::<Vec<_>>(),
}
.into_iter(),
_ => vec![e.to_field(input_schema).map_err(Into::into)].into_iter(),
}
}).collect()
})
.collect()
}

/// Convert an expression into Column expression if it's already provided as input plan.
Expand Down

0 comments on commit 59cf620

Please sign in to comment.