Skip to content

Apache DataFusion SQL Query Engine

ARROW-7692: [Rust] Simplify some Option / Result pattern matches

François Garillot6d99a386bd3f
diff --git a/rust/datafusion/src/execution/physical_plan/limit.rs b/rust/datafusion/src/execution/physical_plan/limit.rs
index 486cee1b87..bdc42df5dc 100644
--- a/rust/datafusion/src/execution/physical_plan/limit.rs
+++ b/rust/datafusion/src/execution/physical_plan/limit.rs
@@ -125,10 +125,7 @@ impl Partition for LimitPartition {
/// Truncate a RecordBatch to maximum of n rows
pub fn truncate_batch(batch: &RecordBatch, n: usize) -> Result<RecordBatch> {
let limited_columns: Result<Vec<ArrayRef>> = (0..batch.num_columns())
- .map(|i| match limit(batch.column(i), n) {
- Ok(result) => Ok(result),
- Err(error) => Err(ExecutionError::from(error)),
- })
+ .map(|i| limit(batch.column(i), n).map_err(|error| ExecutionError::from(error)))
.collect();
Ok(RecordBatch::try_new(
diff --git a/rust/datafusion/src/optimizer/utils.rs b/rust/datafusion/src/optimizer/utils.rs
index e9a4f7bedf..fcd05c2dfa 100644
--- a/rust/datafusion/src/optimizer/utils.rs
+++ b/rust/datafusion/src/optimizer/utils.rs
@@ -100,13 +100,12 @@ pub fn exprlist_to_fields(expr: &Vec<Expr>, input_schema: &Schema) -> Result<Vec
pub fn get_supertype(l: &DataType, r: &DataType) -> Result<DataType> {
match _get_supertype(l, r) {
Some(dt) => Ok(dt),
- None => match _get_supertype(r, l) {
- Some(dt) => Ok(dt),
- None => Err(ExecutionError::InternalError(format!(
+ None => _get_supertype(r, l).ok_or_else(|| {
+ ExecutionError::InternalError(format!(
"Failed to determine supertype of {:?} and {:?}",
l, r
- ))),
- },
+ ))
+ }),
}
}