Skip to content

Apache DataFusion SQL Query Engine

ARROW-11603: [Rust] Fix Clippy Lints for Rust 1.50

Neville Dipale93901d87d1fd
diff --git a/rust/datafusion/src/execution/context.rs b/rust/datafusion/src/execution/context.rs
index 4b8a4f71fe..a6fd020fa0 100644
--- a/rust/datafusion/src/execution/context.rs
+++ b/rust/datafusion/src/execution/context.rs
@@ -172,7 +172,7 @@ impl ExecutionContext {
// create a query planner
let state = self.state.lock().unwrap().clone();
let query_planner = SqlToRel::new(&state);
- Ok(query_planner.statement_to_plan(&statements[0])?)
+ query_planner.statement_to_plan(&statements[0])
}
/// Registers a variable provider within this context.
diff --git a/rust/datafusion/src/logical_plan/builder.rs b/rust/datafusion/src/logical_plan/builder.rs
index 9f5d781d97..a573b3f097 100644
--- a/rust/datafusion/src/logical_plan/builder.rs
+++ b/rust/datafusion/src/logical_plan/builder.rs
@@ -469,7 +469,7 @@ mod tests {
}
#[test]
- fn stringified_plan() -> Result<()> {
+ fn stringified_plan() {
let stringified_plan =
StringifiedPlan::new(PlanType::LogicalPlan, "...the plan...");
assert!(stringified_plan.should_display(true));
@@ -488,7 +488,5 @@ mod tests {
);
assert!(stringified_plan.should_display(true));
assert!(!stringified_plan.should_display(false));
-
- Ok(())
}
}
diff --git a/rust/datafusion/src/logical_plan/dfschema.rs b/rust/datafusion/src/logical_plan/dfschema.rs
index 0305f07acd..9adb22b43d 100644
--- a/rust/datafusion/src/logical_plan/dfschema.rs
+++ b/rust/datafusion/src/logical_plan/dfschema.rs
@@ -237,9 +237,11 @@ where
Self: Sized,
{
/// Attempt to create a DSSchema
+ #[allow(clippy::wrong_self_convention)]
fn to_dfschema(self) -> Result<DFSchema>;
/// Attempt to create a DSSchemaRef
+ #[allow(clippy::wrong_self_convention)]
fn to_dfschema_ref(self) -> Result<DFSchemaRef> {
Ok(Arc::new(self.to_dfschema()?))
}
diff --git a/rust/datafusion/src/logical_plan/expr.rs b/rust/datafusion/src/logical_plan/expr.rs
index 63915381a7..7f358cb31b 100644
--- a/rust/datafusion/src/logical_plan/expr.rs
+++ b/rust/datafusion/src/logical_plan/expr.rs
@@ -1137,11 +1137,10 @@ mod tests {
}
#[test]
- fn case_when_different_literal_then_types() -> Result<()> {
+ fn case_when_different_literal_then_types() {
let maybe_expr = when(col("state").eq(lit("CO")), lit(303))
.when(col("state").eq(lit("NY")), lit("212"))
.end();
assert!(maybe_expr.is_err());
- Ok(())
}
}
diff --git a/rust/datafusion/src/logical_plan/operators.rs b/rust/datafusion/src/logical_plan/operators.rs
index dac48d40b4..624635e6d9 100644
--- a/rust/datafusion/src/logical_plan/operators.rs
+++ b/rust/datafusion/src/logical_plan/operators.rs
@@ -111,11 +111,10 @@ impl ops::Div for Expr {
#[cfg(test)]
mod tests {
- use crate::error::Result;
use crate::prelude::lit;
#[test]
- fn test_operators() -> Result<()> {
+ fn test_operators() {
assert_eq!(
format!("{:?}", lit(1u32) + lit(2u32)),
"UInt32(1) Plus UInt32(2)"
@@ -132,7 +131,5 @@ mod tests {
format!("{:?}", lit(1u32) / lit(2u32)),
"UInt32(1) Divide UInt32(2)"
);
-
- Ok(())
}
}
diff --git a/rust/datafusion/src/optimizer/hash_build_probe_order.rs b/rust/datafusion/src/optimizer/hash_build_probe_order.rs
index 5d63926a4a..e6ad905e73 100644
--- a/rust/datafusion/src/optimizer/hash_build_probe_order.rs
+++ b/rust/datafusion/src/optimizer/hash_build_probe_order.rs
@@ -226,7 +226,7 @@ mod tests {
}
#[test]
- fn test_swap_order() -> Result<()> {
+ fn test_swap_order() {
let lp_left = LogicalPlan::TableScan {
table_name: "left".to_string(),
projection: None,
@@ -245,7 +245,5 @@ mod tests {
assert!(should_swap_join_order(&lp_left, &lp_right));
assert!(!should_swap_join_order(&lp_right, &lp_left));
-
- Ok(())
}
}
diff --git a/rust/datafusion/src/physical_plan/aggregates.rs b/rust/datafusion/src/physical_plan/aggregates.rs
index 9ea5c17e3d..59aa730fde 100644
--- a/rust/datafusion/src/physical_plan/aggregates.rs
+++ b/rust/datafusion/src/physical_plan/aggregates.rs
@@ -205,10 +205,9 @@ mod tests {
}
#[test]
- fn test_sum_no_utf8() -> Result<()> {
+ fn test_sum_no_utf8() {
let observed = return_type(&AggregateFunction::Sum, &[DataType::Utf8]);
assert!(observed.is_err());
- Ok(())
}
#[test]
@@ -239,9 +238,8 @@ mod tests {
}
#[test]
- fn test_avg_no_utf8() -> Result<()> {
+ fn test_avg_no_utf8() {
let observed = return_type(&AggregateFunction::Avg, &[DataType::Utf8]);
assert!(observed.is_err());
- Ok(())
}
}
diff --git a/rust/datafusion/src/physical_plan/coalesce_batches.rs b/rust/datafusion/src/physical_plan/coalesce_batches.rs
index 472b10a6a8..9f36fd8f79 100644
--- a/rust/datafusion/src/physical_plan/coalesce_batches.rs
+++ b/rust/datafusion/src/physical_plan/coalesce_batches.rs
@@ -241,7 +241,7 @@ mod tests {
#[tokio::test(flavor = "multi_thread")]
async fn test_concat_batches() -> Result<()> {
let schema = test_schema();
- let partition = create_vec_batches(&schema, 10)?;
+ let partition = create_vec_batches(&schema, 10);
let partitions = vec![partition];
let output_partitions = coalesce_batches(&schema, partitions, 20).await?;
@@ -263,16 +263,13 @@ mod tests {
Arc::new(Schema::new(vec![Field::new("c0", DataType::UInt32, false)]))
}
- fn create_vec_batches(
- schema: &Arc<Schema>,
- num_batches: usize,
- ) -> Result<Vec<RecordBatch>> {
+ fn create_vec_batches(schema: &Arc<Schema>, num_batches: usize) -> Vec<RecordBatch> {
let batch = create_batch(schema);
let mut vec = Vec::with_capacity(num_batches);
for _ in 0..num_batches {
vec.push(batch.clone());
}
- Ok(vec)
+ vec
}
fn create_batch(schema: &Arc<Schema>) -> RecordBatch {
diff --git a/rust/datafusion/src/physical_plan/datetime_expressions.rs b/rust/datafusion/src/physical_plan/datetime_expressions.rs
index 247f899f50..a70ebcc4fe 100644
--- a/rust/datafusion/src/physical_plan/datetime_expressions.rs
+++ b/rust/datafusion/src/physical_plan/datetime_expressions.rs
@@ -420,7 +420,7 @@ mod tests {
}
#[test]
- fn string_to_timestamp_invalid() -> Result<()> {
+ fn string_to_timestamp_invalid() {
// Test parsing invalid formats
// It would be nice to make these messages better
@@ -430,8 +430,6 @@ mod tests {
"Wed, 18 Feb 2015 23:16:09 GMT",
"Error parsing 'Wed, 18 Feb 2015 23:16:09 GMT' as timestamp",
);
-
- Ok(())
}
// Parse a timestamp to timestamp int with a useful human readable error message
diff --git a/rust/datafusion/src/physical_plan/expressions/cast.rs b/rust/datafusion/src/physical_plan/expressions/cast.rs
index ed5cd27aff..bcf54dc14b 100644
--- a/rust/datafusion/src/physical_plan/expressions/cast.rs
+++ b/rust/datafusion/src/physical_plan/expressions/cast.rs
@@ -214,11 +214,10 @@ mod tests {
}
#[test]
- fn invalid_cast() -> Result<()> {
+ fn invalid_cast() {
// Ensure a useful error happens at plan time if invalid casts are used
let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
let result = cast(col("a"), &schema, DataType::LargeBinary);
result.expect_err("expected Invalid CAST");
- Ok(())
}
}
diff --git a/rust/datafusion/src/physical_plan/expressions/coercion.rs b/rust/datafusion/src/physical_plan/expressions/coercion.rs
index 62c30fc127..e9949f5199 100644
--- a/rust/datafusion/src/physical_plan/expressions/coercion.rs
+++ b/rust/datafusion/src/physical_plan/expressions/coercion.rs
@@ -183,10 +183,9 @@ pub fn order_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataTy
#[cfg(test)]
mod tests {
use super::*;
- use crate::error::Result;
#[test]
- fn test_dictionary_type_coersion() -> Result<()> {
+ fn test_dictionary_type_coersion() {
use DataType::*;
// TODO: In the future, this would ideally return Dictionary types and avoid unpacking
@@ -205,7 +204,5 @@ mod tests {
let lhs_type = Utf8;
let rhs_type = Dictionary(Box::new(Int8), Box::new(Utf8));
assert_eq!(dictionary_coercion(&lhs_type, &rhs_type), Some(Utf8));
-
- Ok(())
}
}
diff --git a/rust/datafusion/src/physical_plan/expressions/in_list.rs b/rust/datafusion/src/physical_plan/expressions/in_list.rs
index 311a8845ff..41f111006e 100644
--- a/rust/datafusion/src/physical_plan/expressions/in_list.rs
+++ b/rust/datafusion/src/physical_plan/expressions/in_list.rs
@@ -129,6 +129,7 @@ impl InListExpr {
}
/// Compare for specific utf8 types
+ #[allow(clippy::unnecessary_wraps)]
fn compare_utf8<T: StringOffsetSizeTrait>(
&self,
array: ArrayRef,
diff --git a/rust/datafusion/src/physical_plan/expressions/not.rs b/rust/datafusion/src/physical_plan/expressions/not.rs
index 07502b5419..23a1a46651 100644
--- a/rust/datafusion/src/physical_plan/expressions/not.rs
+++ b/rust/datafusion/src/physical_plan/expressions/not.rs
@@ -149,12 +149,10 @@ mod tests {
/// verify that expression errors when the input expression is not a boolean.
#[test]
- fn neg_op_not_null() -> Result<()> {
+ fn neg_op_not_null() {
let schema = Schema::new(vec![Field::new("a", DataType::Utf8, true)]);
let expr = not(col("a"), &schema);
assert!(expr.is_err());
-
- Ok(())
}
}
diff --git a/rust/datafusion/src/physical_plan/functions.rs b/rust/datafusion/src/physical_plan/functions.rs
index c9c2cde2a9..ca597c9e6a 100644
--- a/rust/datafusion/src/physical_plan/functions.rs
+++ b/rust/datafusion/src/physical_plan/functions.rs
@@ -474,7 +474,7 @@ pub fn create_physical_expr(
BuiltinScalarFunction::DateTrunc => {
|args| Ok(Arc::new(datetime_expressions::date_trunc(args)?))
}
- BuiltinScalarFunction::Array => |args| Ok(array_expressions::array(args)?),
+ BuiltinScalarFunction::Array => |args| array_expressions::array(args),
});
// coerce
let args = coerce(args, input_schema, &signature(fun))?;
diff --git a/rust/datafusion/src/physical_plan/group_scalar.rs b/rust/datafusion/src/physical_plan/group_scalar.rs
index 51e7c4b807..f73658dc21 100644
--- a/rust/datafusion/src/physical_plan/group_scalar.rs
+++ b/rust/datafusion/src/physical_plan/group_scalar.rs
@@ -117,7 +117,7 @@ impl From<&GroupByScalar> for ScalarValue {
mod tests {
use super::*;
- use crate::error::{DataFusionError, Result};
+ use crate::error::DataFusionError;
macro_rules! scalar_eq_test {
($TYPE:expr, $VALUE:expr) => {{
@@ -132,12 +132,10 @@ mod tests {
}
#[test]
- fn test_scalar_ne_non_std() -> Result<()> {
+ fn test_scalar_ne_non_std() {
// Test only Scalars with non native Eq, Hash
scalar_eq_test!(ScalarValue::Float32, Some(1.0));
scalar_eq_test!(ScalarValue::Float64, Some(1.0));
-
- Ok(())
}
macro_rules! scalar_ne_test {
@@ -153,16 +151,14 @@ mod tests {
}
#[test]
- fn test_scalar_eq_non_std() -> Result<()> {
+ fn test_scalar_eq_non_std() {
// Test only Scalars with non native Eq, Hash
scalar_ne_test!(ScalarValue::Float32, Some(1.0), Some(2.0));
scalar_ne_test!(ScalarValue::Float64, Some(1.0), Some(2.0));
-
- Ok(())
}
#[test]
- fn from_scalar_holding_none() -> Result<()> {
+ fn from_scalar_holding_none() {
let scalar_value = ScalarValue::Int8(None);
let result = GroupByScalar::try_from(&scalar_value);
@@ -173,12 +169,10 @@ mod tests {
),
_ => panic!("Unexpected result"),
}
-
- Ok(())
}
#[test]
- fn from_scalar_unsupported() -> Result<()> {
+ fn from_scalar_unsupported() {
// Use any ScalarValue type not supported by GroupByScalar.
let scalar_value = ScalarValue::LargeUtf8(Some("1.1".to_string()));
let result = GroupByScalar::try_from(&scalar_value);
@@ -192,8 +186,6 @@ mod tests {
),
_ => panic!("Unexpected result"),
}
-
- Ok(())
}
#[test]
diff --git a/rust/datafusion/src/physical_plan/planner.rs b/rust/datafusion/src/physical_plan/planner.rs
index 0f0f53d2e5..93bb94327a 100644
--- a/rust/datafusion/src/physical_plan/planner.rs
+++ b/rust/datafusion/src/physical_plan/planner.rs
@@ -866,7 +866,7 @@ mod tests {
}
#[test]
- fn default_extension_planner() -> Result<()> {
+ fn default_extension_planner() {
let ctx_state = make_ctx_state();
let planner = DefaultPhysicalPlanner::default();
let logical_plan = LogicalPlan::Extension {
@@ -884,11 +884,10 @@ mod tests {
expected_error
),
}
- Ok(())
}
#[test]
- fn bad_extension_planner() -> Result<()> {
+ fn bad_extension_planner() {
// Test that creating an execution plan whose schema doesn't
// match the logical plan's schema generates an error.
let ctx_state = make_ctx_state();
@@ -930,7 +929,6 @@ mod tests {
expected_error
),
}
- Ok(())
}
#[test]
diff --git a/rust/datafusion/src/physical_plan/repartition.rs b/rust/datafusion/src/physical_plan/repartition.rs
index deb78b2a47..20e7122de1 100644
--- a/rust/datafusion/src/physical_plan/repartition.rs
+++ b/rust/datafusion/src/physical_plan/repartition.rs
@@ -247,7 +247,7 @@ mod tests {
async fn one_to_many_round_robin() -> Result<()> {
// define input partitions
let schema = test_schema();
- let partition = create_vec_batches(&schema, 50)?;
+ let partition = create_vec_batches(&schema, 50);
let partitions = vec![partition];
// repartition from 1 input to 4 output
@@ -267,7 +267,7 @@ mod tests {
async fn many_to_one_round_robin() -> Result<()> {
// define input partitions
let schema = test_schema();
- let partition = create_vec_batches(&schema, 50)?;
+ let partition = create_vec_batches(&schema, 50);
let partitions = vec![partition.clone(), partition.clone(), partition.clone()];
// repartition from 3 input to 1 output
@@ -284,7 +284,7 @@ mod tests {
async fn many_to_many_round_robin() -> Result<()> {
// define input partitions
let schema = test_schema();
- let partition = create_vec_batches(&schema, 50)?;
+ let partition = create_vec_batches(&schema, 50);
let partitions = vec![partition.clone(), partition.clone(), partition.clone()];
// repartition from 3 input to 5 output
@@ -305,13 +305,13 @@ mod tests {
Arc::new(Schema::new(vec![Field::new("c0", DataType::UInt32, false)]))
}
- fn create_vec_batches(schema: &Arc<Schema>, n: usize) -> Result<Vec<RecordBatch>> {
+ fn create_vec_batches(schema: &Arc<Schema>, n: usize) -> Vec<RecordBatch> {
let batch = create_batch(schema);
let mut vec = Vec::with_capacity(n);
for _ in 0..n {
vec.push(batch.clone());
}
- Ok(vec)
+ vec
}
fn create_batch(schema: &Arc<Schema>) -> RecordBatch {
diff --git a/rust/datafusion/src/physical_plan/type_coercion.rs b/rust/datafusion/src/physical_plan/type_coercion.rs
index ebc6bf79c4..a84707a48d 100644
--- a/rust/datafusion/src/physical_plan/type_coercion.rs
+++ b/rust/datafusion/src/physical_plan/type_coercion.rs
@@ -189,7 +189,7 @@ mod tests {
use arrow::datatypes::{DataType, Field, Schema};
#[test]
- fn test_maybe_data_types() -> Result<()> {
+ fn test_maybe_data_types() {
// this vec contains: arg1, arg2, expected result
let cases = vec![
// 2 entries, same values
@@ -223,7 +223,6 @@ mod tests {
for case in cases {
assert_eq!(maybe_data_types(&case.0, &case.1), case.2)
}
- Ok(())
}
#[test]
diff --git a/rust/datafusion/src/scalar.rs b/rust/datafusion/src/scalar.rs
index 35b15907fd..31ca1da8ed 100644
--- a/rust/datafusion/src/scalar.rs
+++ b/rust/datafusion/src/scalar.rs
@@ -624,19 +624,17 @@ mod tests {
use super::*;
#[test]
- fn scalar_list_null_to_array() -> Result<()> {
+ fn scalar_list_null_to_array() {
let list_array_ref = ScalarValue::List(None, DataType::UInt64).to_array();
let list_array = list_array_ref.as_any().downcast_ref::<ListArray>().unwrap();
assert!(list_array.is_null(0));
assert_eq!(list_array.len(), 1);
assert_eq!(list_array.values().len(), 0);
-
- Ok(())
}
#[test]
- fn scalar_list_to_array() -> Result<()> {
+ fn scalar_list_to_array() {
let list_array_ref = ScalarValue::List(
Some(vec![
ScalarValue::UInt64(Some(100)),
@@ -660,7 +658,5 @@ mod tests {
assert_eq!(prim_array.value(0), 100);
assert!(prim_array.is_null(1));
assert_eq!(prim_array.value(2), 101);
-
- Ok(())
}
}
diff --git a/rust/datafusion/src/sql/parser.rs b/rust/datafusion/src/sql/parser.rs
index dc31581a0e..3637e882d2 100644
--- a/rust/datafusion/src/sql/parser.rs
+++ b/rust/datafusion/src/sql/parser.rs
@@ -311,7 +311,7 @@ mod tests {
}
/// Parses sql and asserts that the expected error message was found
- fn expect_parse_error(sql: &str, expected_error: &str) -> Result<(), ParserError> {
+ fn expect_parse_error(sql: &str, expected_error: &str) {
match DFParser::parse_sql(sql) {
Ok(statements) => {
panic!(
@@ -329,7 +329,6 @@ mod tests {
);
}
}
- Ok(())
}
fn make_column_def(name: impl Into<String>, data_type: DataType) -> ColumnDef {
@@ -374,7 +373,7 @@ mod tests {
expect_parse_error(
sql,
"Expected one of PARQUET, NDJSON, or CSV, found: UNKNOWN_TYPE",
- )?;
+ );
Ok(())
}
diff --git a/rust/datafusion/tests/sql.rs b/rust/datafusion/tests/sql.rs
index 653d1baa97..8c1850e1df 100644
--- a/rust/datafusion/tests/sql.rs
+++ b/rust/datafusion/tests/sql.rs
@@ -554,6 +554,7 @@ async fn csv_query_sqrt_sqrt() -> Result<()> {
Ok(())
}
+#[allow(clippy::unnecessary_wraps)]
fn create_ctx() -> Result<ExecutionContext> {
let mut ctx = ExecutionContext::new();
diff --git a/rust/datafusion/tests/user_defined_plan.rs b/rust/datafusion/tests/user_defined_plan.rs
index 817aadad8c..4f43c46c71 100644
--- a/rust/datafusion/tests/user_defined_plan.rs
+++ b/rust/datafusion/tests/user_defined_plan.rs
@@ -427,6 +427,7 @@ fn remove_lowest_value(top_values: &mut BTreeMap<i64, String>) {
}
}
+#[allow(clippy::unnecessary_wraps)]
fn accumulate_batch(
input_batch: &RecordBatch,
mut top_values: BTreeMap<i64, String>,