Skip to content

Commit

Permalink
use expect() instead of unwrap() when downcasting arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Sep 24, 2019
1 parent 9b94cc8 commit bb82a24
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions rust/datafusion/src/execution/physical_plan/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,14 @@ pub fn sum(expr: Arc<dyn PhysicalExpr>) -> Arc<dyn AggregateExpr> {
/// Invoke a compute kernel on a pair of arrays
macro_rules! compute_op {
($LEFT:expr, $RIGHT:expr, $OP:ident, $DT:ident) => {{
let ll = $LEFT.as_any().downcast_ref::<$DT>().unwrap();
let rr = $RIGHT.as_any().downcast_ref::<$DT>().unwrap();
let ll = $LEFT
.as_any()
.downcast_ref::<$DT>()
.expect("compute_op failed to downcast array");
let rr = $RIGHT
.as_any()
.downcast_ref::<$DT>()
.expect("compute_op failed to downcast array");
Ok(Arc::new($OP(&ll, &rr)?))
}};
}
Expand Down Expand Up @@ -233,8 +239,14 @@ macro_rules! comparison_op {
/// Invoke a boolean kernel on a pair of arrays
macro_rules! boolean_op {
($LEFT:expr, $RIGHT:expr, $OP:ident) => {{
let ll = $LEFT.as_any().downcast_ref::<BooleanArray>().unwrap();
let rr = $RIGHT.as_any().downcast_ref::<BooleanArray>().unwrap();
let ll = $LEFT
.as_any()
.downcast_ref::<BooleanArray>()
.expect("boolean_op failed to downcast array");
let rr = $RIGHT
.as_any()
.downcast_ref::<BooleanArray>()
.expect("boolean_op failed to downcast array");
Ok(Arc::new($OP(&ll, &rr)?))
}};
}
Expand Down

0 comments on commit bb82a24

Please sign in to comment.