Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions datafusion/functions-nested/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use datafusion_common::{exec_err, internal_err, plan_err, Result, ScalarValue};

use core::any::type_name;
use datafusion_common::DataFusionError;
use datafusion_expr::{ColumnarValue, ScalarFunctionImplementation};
use datafusion_expr::ColumnarValue;

macro_rules! downcast_arg {
($ARG:expr, $ARRAY_TYPE:ident) => {{
Expand Down Expand Up @@ -60,11 +60,13 @@ pub(crate) fn check_datatypes(name: &str, args: &[&ArrayRef]) -> Result<()> {
}

/// array function wrapper that differentiates between scalar (length 1) and array.
pub(crate) fn make_scalar_function<F>(inner: F) -> ScalarFunctionImplementation
pub(crate) fn make_scalar_function<F>(
inner: F,
) -> impl Fn(&[ColumnarValue]) -> Result<ColumnarValue>
where
F: Fn(&[ArrayRef]) -> Result<ArrayRef> + Sync + Send + 'static,
F: Fn(&[ArrayRef]) -> Result<ArrayRef>,
{
Arc::new(move |args: &[ColumnarValue]| {
move |args: &[ColumnarValue]| {
// first, identify if any of the arguments is an Array. If yes, store its `len`,
// as any scalar will need to be converted to an array of len `len`.
let len = args
Expand All @@ -87,7 +89,7 @@ where
} else {
result.map(ColumnarValue::Array)
}
})
}
}

pub(crate) fn align_array_dimensions<O: OffsetSizeTrait>(
Expand Down
12 changes: 5 additions & 7 deletions datafusion/functions/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
// specific language governing permissions and limitations
// under the License.

use std::sync::Arc;

use arrow::array::ArrayRef;
use arrow::datatypes::DataType;

use datafusion_common::{Result, ScalarValue};
use datafusion_expr::function::Hint;
use datafusion_expr::{ColumnarValue, ScalarFunctionImplementation};
use datafusion_expr::ColumnarValue;

/// Creates a function to identify the optimal return type of a string function given
/// the type of its first argument.
Expand Down Expand Up @@ -80,11 +78,11 @@ get_optimal_return_type!(utf8_to_int_type, DataType::Int64, DataType::Int32);
pub(super) fn make_scalar_function<F>(
inner: F,
hints: Vec<Hint>,
) -> ScalarFunctionImplementation
) -> impl Fn(&[ColumnarValue]) -> Result<ColumnarValue>
where
F: Fn(&[ArrayRef]) -> Result<ArrayRef> + Sync + Send + 'static,
F: Fn(&[ArrayRef]) -> Result<ArrayRef>,
{
Arc::new(move |args: &[ColumnarValue]| {
move |args: &[ColumnarValue]| {
// first, identify if any of the arguments is an Array. If yes, store its `len`,
// as any scalar will need to be converted to an array of len `len`.
let len = args
Expand Down Expand Up @@ -119,7 +117,7 @@ where
} else {
result.map(ColumnarValue::Array)
}
})
}
}

#[cfg(test)]
Expand Down