You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ag...@apache.org on 2019/03/15 18:17:11 UTC
[arrow] branch master updated: ARROW-4899: [Rust] [DataFusion]
Remove panic from expression.rs
This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new e50269d ARROW-4899: [Rust] [DataFusion] Remove panic from expression.rs
e50269d is described below
commit e50269dfaa81ae432c77796aff7e17f0dbe40078
Author: Andy Grove <an...@gmail.com>
AuthorDate: Fri Mar 15 12:17:01 2019 -0600
ARROW-4899: [Rust] [DataFusion] Remove panic from expression.rs
Author: Andy Grove <an...@gmail.com>
Closes #3921 from andygrove/ARROW-4899 and squashes the following commits:
758f156 <Andy Grove> Remove panic from expression.rs
---
rust/datafusion/src/execution/aggregate.rs | 2 +-
rust/datafusion/src/execution/context.rs | 2 +-
rust/datafusion/src/execution/expression.rs | 30 ++++++++++++++++-------------
rust/datafusion/src/execution/filter.rs | 2 +-
rust/datafusion/src/execution/projection.rs | 2 +-
5 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/rust/datafusion/src/execution/aggregate.rs b/rust/datafusion/src/execution/aggregate.rs
index b81c87b..fb66dbd 100644
--- a/rust/datafusion/src/execution/aggregate.rs
+++ b/rust/datafusion/src/execution/aggregate.rs
@@ -846,7 +846,7 @@ impl AggregateRelation {
let group_by_keys: Vec<ArrayRef> = self
.group_expr
.iter()
- .map(|e| e.get_func()(&batch))
+ .map(|e| e.get_func()?(&batch))
.collect::<Result<Vec<ArrayRef>>>()?;
// iterate over each row in the batch
diff --git a/rust/datafusion/src/execution/context.rs b/rust/datafusion/src/execution/context.rs
index b1ebf40..4b586a6 100644
--- a/rust/datafusion/src/execution/context.rs
+++ b/rust/datafusion/src/execution/context.rs
@@ -145,7 +145,7 @@ impl ExecutionContext {
let runtime_expr = compile_scalar_expr(&self, expr, &input_schema)?;
let rel = FilterRelation::new(
input_rel,
- runtime_expr, /* .get_func().clone() */
+ runtime_expr, /* .get_func()?.clone() */
input_schema,
);
Ok(Rc::new(RefCell::new(rel)))
diff --git a/rust/datafusion/src/execution/expression.rs b/rust/datafusion/src/execution/expression.rs
index f166159..361a294 100644
--- a/rust/datafusion/src/execution/expression.rs
+++ b/rust/datafusion/src/execution/expression.rs
@@ -57,10 +57,12 @@ pub enum RuntimeExpr {
}
impl RuntimeExpr {
- pub fn get_func(&self) -> CompiledExpr {
+ pub fn get_func(&self) -> Result<CompiledExpr> {
match self {
- &RuntimeExpr::Compiled { ref f, .. } => f.clone(),
- _ => panic!(),
+ &RuntimeExpr::Compiled { ref f, .. } => Ok(f.clone()),
+ _ => Err(ExecutionError::InternalError(
+ "Invalid runtime expression".to_string(),
+ )),
}
}
@@ -109,13 +111,15 @@ pub fn compile_expr(
))),
};
+ let mut args = vec![];
+ for arg in compiled_args? {
+ args.push(arg.get_func()?.clone());
+ }
+
Ok(RuntimeExpr::AggregateFunction {
name: name.to_string(),
f: func?,
- args: compiled_args?
- .iter()
- .map(|e| e.get_func().clone())
- .collect(),
+ args,
t: return_type.clone(),
})
}
@@ -133,8 +137,8 @@ macro_rules! binary_op {
macro_rules! math_ops {
($LEFT:expr, $RIGHT:expr, $BATCH:expr, $OP:ident) => {{
- let left_values = $LEFT.get_func()($BATCH)?;
- let right_values = $RIGHT.get_func()($BATCH)?;
+ let left_values = $LEFT.get_func()?($BATCH)?;
+ let right_values = $RIGHT.get_func()?($BATCH)?;
match (left_values.data_type(), right_values.data_type()) {
(DataType::Int8, DataType::Int8) => {
binary_op!(left_values, right_values, $OP, Int8Array)
@@ -173,8 +177,8 @@ macro_rules! math_ops {
macro_rules! comparison_ops {
($LEFT:expr, $RIGHT:expr, $BATCH:expr, $OP:ident) => {{
- let left_values = $LEFT.get_func()($BATCH)?;
- let right_values = $RIGHT.get_func()($BATCH)?;
+ let left_values = $LEFT.get_func()?($BATCH)?;
+ let right_values = $RIGHT.get_func()?($BATCH)?;
match (left_values.data_type(), right_values.data_type()) {
(DataType::Int8, DataType::Int8) => {
binary_op!(left_values, right_values, $OP, Int8Array)
@@ -214,8 +218,8 @@ macro_rules! comparison_ops {
macro_rules! boolean_ops {
($LEFT:expr, $RIGHT:expr, $BATCH:expr, $OP:ident) => {{
- let left_values = $LEFT.get_func()($BATCH)?;
- let right_values = $RIGHT.get_func()($BATCH)?;
+ let left_values = $LEFT.get_func()?($BATCH)?;
+ let right_values = $RIGHT.get_func()?($BATCH)?;
Ok(Arc::new(compute::$OP(
left_values.as_any().downcast_ref::<BooleanArray>().unwrap(),
right_values
diff --git a/rust/datafusion/src/execution/filter.rs b/rust/datafusion/src/execution/filter.rs
index 3467926..6ae01a7 100644
--- a/rust/datafusion/src/execution/filter.rs
+++ b/rust/datafusion/src/execution/filter.rs
@@ -55,7 +55,7 @@ impl Relation for FilterRelation {
match self.input.borrow_mut().next()? {
Some(batch) => {
// evaluate the filter expression against the batch
- match self.expr.get_func()(&batch)?
+ match self.expr.get_func()?(&batch)?
.as_any()
.downcast_ref::<BooleanArray>()
{
diff --git a/rust/datafusion/src/execution/projection.rs b/rust/datafusion/src/execution/projection.rs
index fd15715..9b61395 100644
--- a/rust/datafusion/src/execution/projection.rs
+++ b/rust/datafusion/src/execution/projection.rs
@@ -54,7 +54,7 @@ impl Relation for ProjectRelation {
match self.input.borrow_mut().next()? {
Some(batch) => {
let projected_columns: Result<Vec<ArrayRef>> =
- self.expr.iter().map(|e| e.get_func()(&batch)).collect();
+ self.expr.iter().map(|e| e.get_func()?(&batch)).collect();
let schema = Schema::new(
self.expr