Skip to content

Run cargo-fmt on all of datafusion-functions #9390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2024
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
20 changes: 10 additions & 10 deletions datafusion/functions/src/encoding/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl EncodeFunc {
Exact(vec![LargeBinary, Utf8]),
],
Volatility::Immutable,
)
),
}
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ impl DecodeFunc {
Exact(vec![LargeBinary, Utf8]),
],
Volatility::Immutable,
)
),
}
}
}
Expand Down Expand Up @@ -272,8 +272,8 @@ impl Encoding {
}

fn encode_binary_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_binary_array::<T>(value)?;
let array: ArrayRef = match self {
Expand All @@ -284,8 +284,8 @@ impl Encoding {
}

fn encode_utf8_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_string_array::<T>(value)?;
let array: ArrayRef = match self {
Expand Down Expand Up @@ -352,8 +352,8 @@ impl Encoding {
}

fn decode_binary_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_binary_array::<T>(value)?;
let array: ArrayRef = match self {
Expand All @@ -364,8 +364,8 @@ impl Encoding {
}

fn decode_utf8_array<T>(self, value: &dyn Array) -> Result<ColumnarValue>
where
T: OffsetSizeTrait,
where
T: OffsetSizeTrait,
{
let input_value = as_generic_string_array::<T>(value)?;
let array: ArrayRef = match self {
Expand Down
2 changes: 0 additions & 2 deletions datafusion/functions/src/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

mod inner;


// create `encode` and `decode` UDFs
make_udf_function!(inner::EncodeFunc, ENCODE, encode);
make_udf_function!(inner::DecodeFunc, DECODE, decode);
Expand All @@ -27,4 +26,3 @@ export_functions!(
(encode, input encoding, "encode the `input`, using the `encoding`. encoding can be base64 or hex"),
(decode, input encoding, "decode the `input`, using the `encoding`. encoding can be base64 or hex")
);

25 changes: 18 additions & 7 deletions datafusion/functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,25 @@ pub mod macros;
pub mod core;
make_stub_package!(core, "core_expressions");

make_package!(
encoding,
"encoding_expressions",
"Hex and binary `encode` and `decode` functions."
);
/// Encoding expressions.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual change of this PR. The rest of the PR is the result of running cargo fmt and checking it in

/// Contains Hex and binary `encode` and `decode` functions.
/// Enabled via feature flag `encoding_expressions`
#[cfg(feature = "encoding_expressions")]
pub mod encoding;
make_stub_package!(encoding, "encoding_expressions");

/// Mathematical functions.
/// Enabled via feature flag `math_expressions`
#[cfg(feature = "math_expressions")]
pub mod math;
make_stub_package!(math, "math_expressions");

/// Regular expression functions.
/// Enabled via feature flag `regex_expressions`
#[cfg(feature = "regex_expressions")]
pub mod regex;
make_stub_package!(regex, "regex_expressions");

make_package!(math, "math_expressions", "Mathematical functions.");
make_package!(regex, "regex_expressions", "Regex functions");
/// Fluent-style API for creating `Expr`s
pub mod expr_fn {
#[cfg(feature = "core_expressions")]
Expand Down
38 changes: 0 additions & 38 deletions datafusion/functions/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,44 +84,6 @@ macro_rules! make_udf_function {
};
}

/// Macro creates the named module if the feature is enabled
/// otherwise creates a stub
///
/// Which returns:
///
/// 1. The list of actual function implementation when the relevant
/// feature is activated,
///
/// 2. A list of stub function when the feature is not activated that produce
/// a runtime error (and explain what feature flag is needed to activate them).
///
/// The rationale for providing stub functions is to help users to configure datafusion
/// properly (so they get an error telling them why a function is not available)
/// instead of getting a cryptic "no function found" message at runtime.

macro_rules! make_package {
($name:ident, $feature:literal, $DOC:expr) => {
#[cfg(feature = $feature)]
#[doc = $DOC ]
#[doc = concat!("Enabled via feature flag `", $feature, "`")]
pub mod $name;

#[cfg(not(feature = $feature))]
#[doc = concat!("Disabled. Enable via feature flag `", $feature, "`")]
pub mod $name {
use datafusion_expr::ScalarUDF;
use log::debug;
use std::sync::Arc;

/// Returns an empty list of functions when the feature is not enabled
pub fn functions() -> Vec<Arc<ScalarUDF>> {
debug!("{} functions disabled", stringify!($name));
vec![]
}
}
};
}

/// Macro creates a sub module if the feature is not enabled
///
/// The rationale for providing stub functions is to help users to configure datafusion
Expand Down
31 changes: 18 additions & 13 deletions datafusion/functions/src/math/abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ use arrow::array::Int32Array;
use arrow::array::Int64Array;
use arrow::array::Int8Array;
use arrow::datatypes::DataType;
use datafusion_common::{exec_err, not_impl_err};
use datafusion_common::plan_datafusion_err;
use datafusion_common::{Result, DataFusionError};
use datafusion_common::{exec_err, not_impl_err};
use datafusion_common::{DataFusionError, Result};
use datafusion_expr::utils;
use datafusion_expr::ColumnarValue;

use arrow::array::{ArrayRef, Float32Array, Float64Array};
use arrow::error::ArrowError;
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
use std::any::Any;
use std::sync::Arc;
use arrow::array::{ArrayRef, Float32Array, Float64Array};
use arrow::error::ArrowError;

type MathArrayFunction = fn(&Vec<ArrayRef>) -> Result<ArrayRef>;

Expand Down Expand Up @@ -80,9 +80,7 @@ macro_rules! make_decimal_abs_function {

/// Abs SQL function
/// Return different implementations based on input datatype to reduce branches during execution
fn create_abs_function(
input_data_type: &DataType,
) -> Result<MathArrayFunction> {
fn create_abs_function(input_data_type: &DataType) -> Result<MathArrayFunction> {
match input_data_type {
DataType::Float32 => Ok(make_abs_function!(Float32Array)),
DataType::Float64 => Ok(make_abs_function!(Float64Array)),
Expand Down Expand Up @@ -115,7 +113,7 @@ pub(super) struct AbsFunc {
impl AbsFunc {
pub fn new() -> Self {
Self {
signature: Signature::any(1, Volatility::Immutable)
signature: Signature::any(1, Volatility::Immutable),
}
}
}
Expand Down Expand Up @@ -155,9 +153,16 @@ impl ScalarUDFImpl for AbsFunc {
DataType::UInt16 => Ok(DataType::UInt16),
DataType::UInt32 => Ok(DataType::UInt32),
DataType::UInt64 => Ok(DataType::UInt64),
DataType::Decimal128(precision, scale) => Ok(DataType::Decimal128(precision, scale)),
DataType::Decimal256(precision, scale) => Ok(DataType::Decimal256(precision, scale)),
_ => not_impl_err!("Unsupported data type {} for function abs", arg_types[0].to_string()),
DataType::Decimal128(precision, scale) => {
Ok(DataType::Decimal128(precision, scale))
}
DataType::Decimal256(precision, scale) => {
Ok(DataType::Decimal256(precision, scale))
}
_ => not_impl_err!(
"Unsupported data type {} for function abs",
arg_types[0].to_string()
),
}
}

Expand All @@ -167,10 +172,10 @@ impl ScalarUDFImpl for AbsFunc {
if args.len() != 1 {
return exec_err!("abs function requires 1 argument, got {}", args.len());
}

let input_data_type = args[0].data_type();
let abs_fun = create_abs_function(input_data_type)?;

let arr = abs_fun(&args)?;
Ok(ColumnarValue::Array(arr))
}
Expand Down
48 changes: 25 additions & 23 deletions datafusion/functions/src/math/nans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
//! Math function: `isnan()`.

use arrow::datatypes::DataType;
use datafusion_common::{exec_err, DataFusionError, Result, plan_datafusion_err};
use datafusion_common::{exec_err, plan_datafusion_err, DataFusionError, Result};
use datafusion_expr::ColumnarValue;

use arrow::array::{ArrayRef, BooleanArray, Float32Array, Float64Array};
use datafusion_expr::TypeSignature::*;
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility, utils::generate_signature_error_msg};
use datafusion_expr::{
utils::generate_signature_error_msg, ScalarUDFImpl, Signature, Volatility,
};
use std::any::Any;
use std::sync::Arc;

Expand All @@ -36,11 +38,10 @@ impl IsNanFunc {
pub fn new() -> Self {
use DataType::*;
Self {
signature:
Signature::one_of(
signature: Signature::one_of(
vec![Exact(vec![Float32]), Exact(vec![Float64])],
Volatility::Immutable,
)
),
}
}
}
Expand Down Expand Up @@ -76,25 +77,26 @@ impl ScalarUDFImpl for IsNanFunc {
let args = ColumnarValue::values_to_arrays(args)?;

let arr: ArrayRef = match args[0].data_type() {
DataType::Float64 => {
Arc::new(make_function_scalar_inputs_return_type!(
&args[0],
self.name(),
Float64Array,
BooleanArray,
{ f64::is_nan }
))
}
DataType::Float32 => {
Arc::new(make_function_scalar_inputs_return_type!(
&args[0],
self.name(),
Float32Array,
BooleanArray,
{ f32::is_nan }
))
DataType::Float64 => Arc::new(make_function_scalar_inputs_return_type!(
&args[0],
self.name(),
Float64Array,
BooleanArray,
{ f64::is_nan }
)),
DataType::Float32 => Arc::new(make_function_scalar_inputs_return_type!(
&args[0],
self.name(),
Float32Array,
BooleanArray,
{ f32::is_nan }
)),
other => {
return exec_err!(
"Unsupported data type {other:?} for function {}",
self.name()
)
}
other => return exec_err!("Unsupported data type {other:?} for function {}", self.name()),
};
Ok(ColumnarValue::Array(arr))
}
Expand Down
16 changes: 6 additions & 10 deletions datafusion/functions/src/regex/regexpmatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ use arrow::array::{Array, ArrayRef, OffsetSizeTrait};
use arrow::compute::kernels::regexp;
use arrow::datatypes::DataType;
use arrow::datatypes::Field;
use datafusion_common::ScalarValue;
use datafusion_expr::TypeSignature::*;
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
use std::any::Any;
use datafusion_common::exec_err;
use datafusion_common::ScalarValue;
use datafusion_common::{arrow_datafusion_err, plan_err};
use datafusion_common::{
cast::as_generic_string_array, internal_err, DataFusionError, Result,
};
use datafusion_expr::ColumnarValue;
use datafusion_expr::TypeSignature::*;
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
use std::any::Any;
use std::sync::Arc;

#[derive(Debug)]
Expand Down Expand Up @@ -107,12 +107,8 @@ impl ScalarUDFImpl for RegexpMatchFunc {
}
fn regexp_match_func(args: &[ArrayRef]) -> Result<ArrayRef> {
match args[0].data_type() {
DataType::Utf8 => {
regexp_match::<i32>(args)
}
DataType::LargeUtf8 => {
regexp_match::<i64>(args)
}
DataType::Utf8 => regexp_match::<i32>(args),
DataType::LargeUtf8 => regexp_match::<i64>(args),
other => {
internal_err!("Unsupported data type {other:?} for function regexp_match")
}
Expand Down