From 80bafa4cb1e5e9612e578ad3e9f1240a1b7777d7 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Wed, 26 May 2021 18:41:41 +0000 Subject: [PATCH] Simplified creation of array from scalar. --- datafusion/src/scalar.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/datafusion/src/scalar.rs b/datafusion/src/scalar.rs index f3fa5b2c5de5..ad8f3bcf6c85 100644 --- a/datafusion/src/scalar.rs +++ b/datafusion/src/scalar.rs @@ -344,7 +344,7 @@ impl ScalarValue { macro_rules! build_array_primitive { ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{ { - let values = scalars + let array = scalars .map(|sv| { if let ScalarValue::$SCALAR_TY(v) = sv { Ok(*v) @@ -356,9 +356,7 @@ impl ScalarValue { ))) } }) - .collect::>>()?; - - let array: $ARRAY_TY = values.iter().collect(); + .collect::>()?; Arc::new(array) } }}; @@ -369,10 +367,10 @@ impl ScalarValue { macro_rules! build_array_string { ($ARRAY_TY:ident, $SCALAR_TY:ident) => {{ { - let values = scalars + let array = scalars .map(|sv| { if let ScalarValue::$SCALAR_TY(v) = sv { - Ok(v) + Ok(v.as_ref()) } else { Err(DataFusionError::Internal(format!( "Inconsistent types in ScalarValue::iter_to_array. \ @@ -381,14 +379,8 @@ impl ScalarValue { ))) } }) - .collect::>>()?; - - // it is annoying that one can not create - // StringArray et al directly from iter of &String, - // requiring this map to &str - let values = values.iter().map(|s| s.as_ref()); + .collect::>()?; - let array: $ARRAY_TY = values.collect(); Arc::new(array) } }};