Apache DataFusion SQL Query Engine
minor: remove redundant `DataFusionError` and fix `clippy` (#5669)
jakevin9d60e1415b4a
diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rsindex 92cdab3ebb..49dff0c06c 100644--- a/datafusion/common/src/scalar.rs+++ b/datafusion/common/src/scalar.rs@@ -857,7 +857,7 @@ fn ts_sub_to_interval(lhs_tz: &Option<String>,rhs_tz: &Option<String>,mode: IntervalMode,-) -> Result<ScalarValue, DataFusionError> {+) -> Result<ScalarValue> {let lhs_dt = with_timezone_to_naive_datetime(lhs_ts, lhs_tz, mode)?;let rhs_dt = with_timezone_to_naive_datetime(rhs_ts, rhs_tz, mode)?;let delta_secs = lhs_dt.signed_duration_since(rhs_dt);@@ -892,7 +892,7 @@ fn with_timezone_to_naive_datetime(ts: i64,tz: &Option<String>,mode: IntervalMode,-) -> Result<NaiveDateTime, DataFusionError> {+) -> Result<NaiveDateTime> {let datetime = if let IntervalMode::Milli = mode {ticks_to_naive_datetime::<1_000_000>(ts)} else {@@ -4953,8 +4953,8 @@ mod tests {for (lhs, rhs, expected) in cases.iter() {let result = lhs.add(rhs).unwrap();let result_commute = rhs.add(lhs).unwrap();- assert_eq!(*expected, result, "lhs:{:?} + rhs:{:?}", lhs, rhs);- assert_eq!(*expected, result_commute, "lhs:{:?} + rhs:{:?}", rhs, lhs);+ assert_eq!(*expected, result, "lhs:{lhs:?} + rhs:{rhs:?}");+ assert_eq!(*expected, result_commute, "lhs:{rhs:?} + rhs:{lhs:?}");}}@@ -5009,7 +5009,7 @@ mod tests {];for (lhs, rhs, expected) in cases.iter() {let result = lhs.sub(rhs).unwrap();- assert_eq!(*expected, result, "lhs:{:?} - rhs:{:?}", lhs, rhs);+ assert_eq!(*expected, result, "lhs:{lhs:?} - rhs:{rhs:?}");}}@@ -5043,20 +5043,14 @@ mod tests {assert_eq!(intervals[idx],timestamp2.sub(ts1).unwrap(),- "index:{}, operands: {:?} (-) {:?}",- idx,- timestamp2,- ts1+ "index:{idx}, operands: {timestamp2:?} (-) {ts1:?}");} else {let timestamp2 = ts1.sub(intervals[idx].clone()).unwrap();assert_eq!(intervals[idx],ts1.sub(timestamp2.clone()).unwrap(),- "index:{}, operands: {:?} (-) {:?}",- idx,- ts1,- timestamp2+ "index:{idx}, operands: {ts1:?} (-) {timestamp2:?}");};}diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rsindex 397f4109b6..378159c26b 100644--- a/datafusion/core/src/execution/context.rs+++ b/datafusion/core/src/execution/context.rs@@ -330,8 +330,7 @@ impl SessionContext {provider.insert_into(&self.state(), &input).await?;} else {return Err(DataFusionError::Execution(format!(- "Table '{}' does not exist",- table_name+ "Table '{table_name}' does not exist")));}self.return_empty_dataframe()diff --git a/datafusion/core/src/physical_plan/aggregates/mod.rs b/datafusion/core/src/physical_plan/aggregates/mod.rsindex 90a19a3b6e..c41cc438c8 100644--- a/datafusion/core/src/physical_plan/aggregates/mod.rs+++ b/datafusion/core/src/physical_plan/aggregates/mod.rs@@ -508,7 +508,7 @@ fn create_schema(aggr_expr: &[Arc<dyn AggregateExpr>],contains_null_expr: bool,mode: AggregateMode,-) -> datafusion_common::Result<Schema> {+) -> Result<Schema> {let mut fields = Vec::with_capacity(group_expr.len() + aggr_expr.len());for (expr, name) in group_expr {fields.push(Field::new(@@ -552,7 +552,7 @@ fn aggregate_expressions(aggr_expr: &[Arc<dyn AggregateExpr>],mode: &AggregateMode,col_idx_base: usize,-) -> datafusion_common::Result<Vec<Vec<Arc<dyn PhysicalExpr>>>> {+) -> Result<Vec<Vec<Arc<dyn PhysicalExpr>>>> {match mode {AggregateMode::Partial => {Ok(aggr_expr.iter().map(|agg| agg.expressions()).collect())@@ -567,7 +567,7 @@ fn aggregate_expressions(col_idx_base += exprs.len();Ok(exprs)})- .collect::<datafusion_common::Result<Vec<_>>>()?)+ .collect::<Result<Vec<_>>>()?)}}}@@ -595,16 +595,16 @@ pub(crate) type RowAccumulatorItem = Box<dyn RowAccumulator>;fn create_accumulators(aggr_expr: &[Arc<dyn AggregateExpr>],-) -> datafusion_common::Result<Vec<AccumulatorItem>> {+) -> Result<Vec<AccumulatorItem>> {aggr_expr.iter().map(|expr| expr.create_accumulator())- .collect::<datafusion_common::Result<Vec<_>>>()+ .collect::<Result<Vec<_>>>()}fn create_row_accumulators(aggr_expr: &[Arc<dyn AggregateExpr>],-) -> datafusion_common::Result<Vec<RowAccumulatorItem>> {+) -> Result<Vec<RowAccumulatorItem>> {let mut state_index = 0;aggr_expr.iter()@@ -613,7 +613,7 @@ fn create_row_accumulators(state_index += expr.state_fields().unwrap().len();result})- .collect::<datafusion_common::Result<Vec<_>>>()+ .collect::<Result<Vec<_>>>()}/// returns a vector of ArrayRefs, where each entry corresponds to either the@@ -621,7 +621,7 @@ fn create_row_accumulators(fn finalize_aggregation(accumulators: &[AccumulatorItem],mode: &AggregateMode,-) -> datafusion_common::Result<Vec<ArrayRef>> {+) -> Result<Vec<ArrayRef>> {match mode {AggregateMode::Partial => {// build the vector of states@@ -633,7 +633,7 @@ fn finalize_aggregation(e.iter().map(|v| v.to_array()).collect::<Vec<ArrayRef>>()})})- .collect::<datafusion_common::Result<Vec<_>>>()?;+ .collect::<Result<Vec<_>>>()?;Ok(a.iter().flatten().cloned().collect::<Vec<_>>())}AggregateMode::Final | AggregateMode::FinalPartitioned => {@@ -641,7 +641,7 @@ fn finalize_aggregation(accumulators.iter().map(|accumulator| accumulator.evaluate().map(|v| v.to_array()))- .collect::<datafusion_common::Result<Vec<ArrayRef>>>()+ .collect::<Result<Vec<ArrayRef>>>()}}}diff --git a/datafusion/core/src/physical_plan/aggregates/row_hash.rs b/datafusion/core/src/physical_plan/aggregates/row_hash.rsindex b778b5f036..612b707cc1 100644--- a/datafusion/core/src/physical_plan/aggregates/row_hash.rs+++ b/datafusion/core/src/physical_plan/aggregates/row_hash.rs@@ -46,7 +46,7 @@ use arrow::compute::cast;use arrow::datatypes::{DataType, Schema, UInt32Type};use arrow::{array::ArrayRef, compute};use arrow::{datatypes::SchemaRef, record_batch::RecordBatch};-use datafusion_common::{DataFusionError, Result, ScalarValue};+use datafusion_common::{Result, ScalarValue};use datafusion_expr::Accumulator;use datafusion_row::accessor::RowAccessor;use datafusion_row::layout::RowLayout;@@ -503,9 +503,7 @@ impl GroupedHashAggregateStream {.and({group_state.indices.clear();Ok(())- })?;-- Ok::<(), DataFusionError>(())+ })})?;}allocated += selfdiff --git a/datafusion/core/src/test_util/mod.rs b/datafusion/core/src/test_util/mod.rsindex b2a561458a..982a7a8300 100644--- a/datafusion/core/src/test_util/mod.rs+++ b/datafusion/core/src/test_util/mod.rs@@ -296,7 +296,7 @@ impl TableProviderFactory for TestTableFactory {&self,_: &SessionState,cmd: &CreateExternalTable,- ) -> datafusion_common::Result<Arc<dyn TableProvider>> {+ ) -> Result<Arc<dyn TableProvider>> {Ok(Arc::new(TestTableProvider {url: cmd.location.to_string(),schema: Arc::new(cmd.schema.as_ref().into()),@@ -334,7 +334,7 @@ impl TableProvider for TestTableProvider {_projection: Option<&Vec<usize>>,_filters: &[Expr],_limit: Option<usize>,- ) -> datafusion_common::Result<Arc<dyn ExecutionPlan>> {+ ) -> Result<Arc<dyn ExecutionPlan>> {unimplemented!("TestTableProvider is a stub for testing.")}}@@ -516,7 +516,7 @@ pub async fn test_create_unbounded_sorted_file(ctx: &SessionContext,file_path: PathBuf,table_name: &str,-) -> datafusion_common::Result<()> {+) -> Result<()> {// Create schema:let schema = Arc::new(Schema::new(vec![Field::new("a1", DataType::UInt32, false),diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rsindex 01860ae7d4..2806683ab8 100644--- a/datafusion/expr/src/expr.rs+++ b/datafusion/expr/src/expr.rs@@ -839,7 +839,7 @@ impl fmt::Debug for Expr {match self {Expr::Alias(expr, alias) => write!(f, "{expr:?} AS {alias}"),Expr::Column(c) => write!(f, "{c}"),- Expr::OuterReferenceColumn(_, c) => write!(f, "outer_ref({})", c),+ Expr::OuterReferenceColumn(_, c) => write!(f, "outer_ref({c})"),Expr::ScalarVariable(_, var_names) => write!(f, "{}", var_names.join(".")),Expr::Literal(v) => write!(f, "{v:?}"),Expr::Case(case) => {diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rsindex 512926cc8b..05a7c2e320 100644--- a/datafusion/expr/src/logical_plan/plan.rs+++ b/datafusion/expr/src/logical_plan/plan.rs@@ -666,7 +666,7 @@ impl LogicalPlan {.inputs().into_iter().map(|inp| inp.replace_params_with_values(param_values))- .collect::<Result<Vec<_>, DataFusionError>>()?;+ .collect::<Result<Vec<_>>>()?;from_plan(self, &new_exprs, &new_inputs_with_values)}@@ -682,10 +682,7 @@ impl LogicalPlan {}impl ExpressionVisitor for ExprParamTypeVisitor {- fn pre_visit(- mut self,- expr: &Expr,- ) -> datafusion_common::Result<Recursion<Self>>+ fn pre_visit(mut self, expr: &Expr) -> Result<Recursion<Self>>whereSelf: ExpressionVisitor,{@@ -1427,7 +1424,7 @@ impl Projection {}}- pub fn try_from_plan(plan: &LogicalPlan) -> datafusion_common::Result<&Projection> {+ pub fn try_from_plan(plan: &LogicalPlan) -> Result<&Projection> {match plan {LogicalPlan::Projection(it) => Ok(it),_ => plan_err!("Could not coerce into Projection!"),@@ -1449,10 +1446,7 @@ pub struct SubqueryAlias {}impl SubqueryAlias {- pub fn try_new(- plan: LogicalPlan,- alias: impl Into<String>,- ) -> datafusion_common::Result<Self> {+ pub fn try_new(plan: LogicalPlan, alias: impl Into<String>) -> Result<Self> {let alias = alias.into();let table_ref = TableReference::bare(&alias);let schema: Schema = plan.schema().as_ref().clone().into();@@ -1490,10 +1484,7 @@ pub struct Filter {impl Filter {/// Create a new filter operator.- pub fn try_new(- predicate: Expr,- input: Arc<LogicalPlan>,- ) -> datafusion_common::Result<Self> {+ pub fn try_new(predicate: Expr, input: Arc<LogicalPlan>) -> Result<Self> {// Filter predicates must return a boolean value so we try and validate that here.// Note that it is not always possible to resolve the predicate expression during plan// construction (such as with correlated subqueries) so we make a best effort here and@@ -1518,7 +1509,7 @@ impl Filter {Ok(Self { predicate, input })}- pub fn try_from_plan(plan: &LogicalPlan) -> datafusion_common::Result<&Filter> {+ pub fn try_from_plan(plan: &LogicalPlan) -> Result<&Filter> {match plan {LogicalPlan::Filter(it) => Ok(it),_ => plan_err!("Could not coerce into Filter!"),@@ -1818,7 +1809,7 @@ impl Aggregate {input: Arc<LogicalPlan>,group_expr: Vec<Expr>,aggr_expr: Vec<Expr>,- ) -> datafusion_common::Result<Self> {+ ) -> Result<Self> {let grouping_expr: Vec<Expr> = grouping_set_to_exprlist(group_expr.as_slice())?;let all_expr = grouping_expr.iter().chain(aggr_expr.iter());validate_unique_names("Aggregations", all_expr.clone())?;@@ -1839,7 +1830,7 @@ impl Aggregate {group_expr: Vec<Expr>,aggr_expr: Vec<Expr>,schema: DFSchemaRef,- ) -> datafusion_common::Result<Self> {+ ) -> Result<Self> {if group_expr.is_empty() && aggr_expr.is_empty() {return Err(DataFusionError::Plan("Aggregate requires at least one grouping or aggregate expression"@@ -1862,7 +1853,7 @@ impl Aggregate {})}- pub fn try_from_plan(plan: &LogicalPlan) -> datafusion_common::Result<&Aggregate> {+ pub fn try_from_plan(plan: &LogicalPlan) -> Result<&Aggregate> {match plan {LogicalPlan::Aggregate(it) => Ok(it),_ => plan_err!("Could not coerce into Aggregate!"),@@ -1947,7 +1938,7 @@ pub struct Subquery {}impl Subquery {- pub fn try_from_expr(plan: &Expr) -> datafusion_common::Result<&Subquery> {+ pub fn try_from_expr(plan: &Expr) -> Result<&Subquery> {match plan {Expr::ScalarSubquery(it) => Ok(it),Expr::Cast(cast) => Subquery::try_from_expr(cast.expr.as_ref()),@@ -2069,7 +2060,6 @@ mod tests {use crate::{col, exists, in_subquery, lit};use arrow::datatypes::{DataType, Field, Schema};use datafusion_common::DFSchema;- use datafusion_common::Result;use std::collections::HashMap;fn employee_schema() -> Schema {diff --git a/datafusion/optimizer/src/decorrelate_where_in.rs b/datafusion/optimizer/src/decorrelate_where_in.rsindex 3439757f08..8d7988d711 100644--- a/datafusion/optimizer/src/decorrelate_where_in.rs+++ b/datafusion/optimizer/src/decorrelate_where_in.rs@@ -53,7 +53,7 @@ impl DecorrelateWhereIn {&self,predicate: &Expr,config: &dyn OptimizerConfig,- ) -> datafusion_common::Result<(Vec<SubqueryInfo>, Vec<Expr>)> {+ ) -> Result<(Vec<SubqueryInfo>, Vec<Expr>)> {let filters = split_conjunction(predicate); // TODO: disjunctionslet mut subqueries = vec![];diff --git a/datafusion/optimizer/src/eliminate_cross_join.rs b/datafusion/optimizer/src/eliminate_cross_join.rsindex bcf4b4d5a8..533566a0bf 100644--- a/datafusion/optimizer/src/eliminate_cross_join.rs+++ b/datafusion/optimizer/src/eliminate_cross_join.rs@@ -147,19 +147,19 @@ fn flatten_join_inputs(possible_join_keys.extend(join.on.clone());let left = &*(join.left);let right = &*(join.right);- Ok::<Vec<&LogicalPlan>, DataFusionError>(vec![left, right])+ vec![left, right]}LogicalPlan::CrossJoin(join) => {let left = &*(join.left);let right = &*(join.right);- Ok::<Vec<&LogicalPlan>, DataFusionError>(vec![left, right])+ vec![left, right]}_ => {return Err(DataFusionError::Plan("flatten_join_inputs just can call join/cross_join".to_string(),));}- }?;+ };for child in children.iter() {match *child {diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rsindex e32443e01a..5f927c701e 100644--- a/datafusion/sql/src/statement.rs+++ b/datafusion/sql/src/statement.rs@@ -447,8 +447,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {if !schema.has_column(column) {// Return an error if any column is not in the schema:return Err(DataFusionError::Plan(format!(- "Column {} is not in schema",- column+ "Column {column} is not in schema")));}}