From 77294eb81c6d42fd2332901285940de58462c314 Mon Sep 17 00:00:00 2001 From: zhyass Date: Mon, 11 Apr 2022 22:55:33 +0800 Subject: [PATCH] use FactoryCreatorWithTypes for functions --- .../src/scalars/conditionals/conditional.rs | 4 +- .../src/scalars/conditionals/in_basic.rs | 68 +++++++--------- .../functions/src/scalars/function_adapter.rs | 27 ++----- .../functions/src/scalars/function_factory.rs | 81 ++++--------------- common/functions/src/scalars/tuples/tuple.rs | 47 +++++------ .../src/scalars/tuples/tuple_class.rs | 2 +- common/functions/src/scalars/uuids/uuid.rs | 8 +- .../src/scalars/uuids/uuid_creator.rs | 11 ++- .../src/scalars/uuids/uuid_verifier.rs | 27 ++++--- .../functions/tests/it/scalars/maths/abs.rs | 4 +- .../functions/tests/it/scalars/maths/ceil.rs | 4 +- .../functions/tests/it/scalars/maths/floor.rs | 4 +- .../functions/tests/it/scalars/maths/log.rs | 3 +- .../functions/tests/it/scalars/maths/sign.rs | 4 +- common/functions/tests/it/scalars/tuples.rs | 53 ++++++------ .../tests/it/scalars/uuids/uuid_creator.rs | 6 +- .../tests/it/scalars/uuids/uuid_verifier.rs | 12 ++- 17 files changed, 155 insertions(+), 210 deletions(-) diff --git a/common/functions/src/scalars/conditionals/conditional.rs b/common/functions/src/scalars/conditionals/conditional.rs index e3060418313c1..74acba933adce 100644 --- a/common/functions/src/scalars/conditionals/conditional.rs +++ b/common/functions/src/scalars/conditionals/conditional.rs @@ -26,7 +26,7 @@ impl ConditionalFunction { factory.register_typed("if", IfFunction::desc()); factory.register_typed("isNull", IsNullFunction::desc()); factory.register_typed("isNotNull", IsNotNullFunction::desc()); - factory.register("in", InFunction::::desc()); - factory.register("not_in", InFunction::::desc()); + factory.register_typed("in", InFunction::::desc()); + factory.register_typed("not_in", InFunction::::desc()); } } diff --git a/common/functions/src/scalars/conditionals/in_basic.rs b/common/functions/src/scalars/conditionals/in_basic.rs index cc87116ca63ed..8f88f3f4f00c4 100644 --- a/common/functions/src/scalars/conditionals/in_basic.rs +++ b/common/functions/src/scalars/conditionals/in_basic.rs @@ -23,19 +23,36 @@ use ordered_float::OrderedFloat; use crate::scalars::cast_column_field; use crate::scalars::Function; -use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; +use crate::scalars::TypedFunctionDescription; #[derive(Clone)] -pub struct InFunction; +pub struct InFunction { + is_null: bool, +} impl InFunction { - pub fn try_create(_display_name: &str) -> Result> { - Ok(Box::new(InFunction:: {})) + pub fn try_create(_display_name: &str, args: &[&DataTypePtr]) -> Result> { + for dt in args { + let type_id = remove_nullable(dt).data_type_id(); + if type_id.is_date_or_date_time() + || type_id.is_interval() + || type_id.is_array() + || type_id.is_struct() + { + return Err(ErrorCode::UnexpectedError(format!( + "{} type is not supported for IN now", + type_id + ))); + } + } + + let is_null = args[0].data_type_id() == TypeID::Null; + Ok(Box::new(InFunction:: { is_null })) } - pub fn desc() -> FunctionDescription { - FunctionDescription::creator(Box::new(Self::try_create)).features( + pub fn desc() -> TypedFunctionDescription { + TypedFunctionDescription::creator(Box::new(Self::try_create)).features( FunctionFeatures::default() .bool_function() .disable_passthrough_null() @@ -93,46 +110,15 @@ impl Function for InFunction { "InFunction" } - fn return_type(&self, args: &[&DataTypePtr]) -> Result { - for dt in args { - let type_id = remove_nullable(dt).data_type_id(); - if type_id.is_date_or_date_time() - || type_id.is_interval() - || type_id.is_array() - || type_id.is_struct() - { - return Err(ErrorCode::UnexpectedError(format!( - "{} type is not supported for IN now", - type_id - ))); - } - } - let input_dt = remove_nullable(args[0]).data_type_id(); - if input_dt == TypeID::Null { + fn return_type(&self, _args: &[&DataTypePtr]) -> Result { + if self.is_null { return Ok(NullType::arc()); } Ok(BooleanType::arc()) } fn eval(&self, columns: &ColumnsWithField, input_rows: usize) -> Result { - for col in columns { - let dt = col.column().data_type(); - let type_id = remove_nullable(&dt).data_type_id(); - if type_id.is_date_or_date_time() - || type_id.is_interval() - || type_id.is_array() - || type_id.is_struct() - { - return Err(ErrorCode::UnexpectedError(format!( - "{} type is not supported for IN now", - type_id - ))); - } - } - - let input_col = &columns[0]; - let input_dt = remove_nullable(input_col.data_type()).data_type_id(); - if input_dt == TypeID::Null { + if self.is_null { let col = NullType::arc().create_constant_column(&DataValue::Null, input_rows)?; return Ok(col); } @@ -141,7 +127,7 @@ impl Function for InFunction { let least_super_dt = aggregate_types(&types)?; let least_super_type_id = remove_nullable(&least_super_dt).data_type_id(); - let input_col = cast_column_field(input_col, &least_super_dt)?; + let input_col = cast_column_field(&columns[0], &least_super_dt)?; match least_super_type_id { TypeID::Boolean => { diff --git a/common/functions/src/scalars/function_adapter.rs b/common/functions/src/scalars/function_adapter.rs index 373a026915d17..f49c4b871d6bc 100644 --- a/common/functions/src/scalars/function_adapter.rs +++ b/common/functions/src/scalars/function_adapter.rs @@ -45,23 +45,6 @@ pub struct FunctionAdapter { } impl FunctionAdapter { - pub fn create(inner: Box, passthrough_null: bool) -> Box { - Box::new(Self { - inner: Some(inner), - passthrough_null, - }) - } - - pub fn create_some( - inner: Option>, - passthrough_null: bool, - ) -> Box { - Box::new(Self { - inner, - passthrough_null, - }) - } - pub fn try_create_by_typed( desc: &TypedFunctionDescription, name: &str, @@ -72,7 +55,10 @@ impl FunctionAdapter { let inner = if passthrough_null { // one is null, result is null if args.iter().any(|v| v.data_type_id() == TypeID::Null) { - return Ok(Self::create_some(None, true)); + return Ok(Box::new(Self { + inner: None, + passthrough_null: true, + })); } let types = args.iter().map(|v| remove_nullable(v)).collect::>(); let types = types.iter().collect::>(); @@ -81,7 +67,10 @@ impl FunctionAdapter { (desc.typed_function_creator)(name, args)? }; - Ok(Self::create(inner, passthrough_null)) + Ok(Box::new(Self { + inner: Some(inner), + passthrough_null, + })) } } diff --git a/common/functions/src/scalars/function_factory.rs b/common/functions/src/scalars/function_factory.rs index 47d13433db4d2..1919fc2b7edcc 100644 --- a/common/functions/src/scalars/function_factory.rs +++ b/common/functions/src/scalars/function_factory.rs @@ -38,31 +38,9 @@ use super::TupleClassFunction; use crate::scalars::DateFunction; use crate::scalars::UUIDFunction; -pub type FactoryCreator = Box Result> + Send + Sync>; - pub type FactoryCreatorWithTypes = Box Result> + Send + Sync>; -pub struct FunctionDescription { - pub(crate) features: FunctionFeatures, - function_creator: FactoryCreator, -} - -impl FunctionDescription { - pub fn creator(creator: FactoryCreator) -> FunctionDescription { - FunctionDescription { - function_creator: creator, - features: FunctionFeatures::default(), - } - } - - #[must_use] - pub fn features(mut self, features: FunctionFeatures) -> FunctionDescription { - self.features = features; - self - } -} - pub struct TypedFunctionDescription { pub(crate) features: FunctionFeatures, pub typed_function_creator: FactoryCreatorWithTypes, @@ -84,7 +62,6 @@ impl TypedFunctionDescription { } pub struct FunctionFactory { - case_insensitive_desc: HashMap, case_insensitive_typed_desc: HashMap, } @@ -112,7 +89,6 @@ static FUNCTION_FACTORY: Lazy> = Lazy::new(|| { impl FunctionFactory { pub(in crate::scalars::function_factory) fn create() -> FunctionFactory { FunctionFactory { - case_insensitive_desc: Default::default(), case_insensitive_typed_desc: Default::default(), } } @@ -121,11 +97,6 @@ impl FunctionFactory { FUNCTION_FACTORY.as_ref() } - pub fn register(&mut self, name: &str, desc: FunctionDescription) { - let case_insensitive_desc = &mut self.case_insensitive_desc; - case_insensitive_desc.insert(name.to_lowercase(), desc); - } - pub fn register_typed(&mut self, name: &str, desc: TypedFunctionDescription) { let case_insensitive_typed_desc = &mut self.case_insensitive_typed_desc; case_insensitive_typed_desc.insert(name.to_lowercase(), desc); @@ -135,22 +106,13 @@ impl FunctionFactory { let origin_name = name.as_ref(); let lowercase_name = origin_name.to_lowercase(); - match self.case_insensitive_desc.get(&lowercase_name) { - // TODO(Winter): we should write similar function names into error message if function name is not found. - None => match self.case_insensitive_typed_desc.get(&lowercase_name) { - None => Err(ErrorCode::UnknownFunction(format!( - "Unsupported Function: {}", - origin_name - ))), - Some(desc) => FunctionAdapter::try_create_by_typed(desc, origin_name, args), - }, - Some(desc) => { - let inner = (desc.function_creator)(origin_name)?; - Ok(FunctionAdapter::create( - inner, - desc.features.passthrough_null, - )) - } + // TODO(Winter): we should write similar function names into error message if function name is not found. + match self.case_insensitive_typed_desc.get(&lowercase_name) { + Some(desc) => FunctionAdapter::try_create_by_typed(desc, origin_name, args), + None => Err(ErrorCode::UnknownFunction(format!( + "Unsupported Function: {}", + origin_name + ))), } } @@ -158,16 +120,13 @@ impl FunctionFactory { let origin_name = name.as_ref(); let lowercase_name = origin_name.to_lowercase(); - match self.case_insensitive_desc.get(&lowercase_name) { - // TODO(Winter): we should write similar function names into error message if function name is not found. - None => match self.case_insensitive_typed_desc.get(&lowercase_name) { - None => Err(ErrorCode::UnknownFunction(format!( - "Unsupported Function: {}", - origin_name - ))), - Some(desc) => Ok(desc.features.clone()), - }, + // TODO(Winter): we should write similar function names into error message if function name is not found. + match self.case_insensitive_typed_desc.get(&lowercase_name) { Some(desc) => Ok(desc.features.clone()), + None => Err(ErrorCode::UnknownFunction(format!( + "Unsupported Function: {}", + origin_name + ))), } } @@ -175,32 +134,22 @@ impl FunctionFactory { let origin_name = name.as_ref(); let lowercase_name = origin_name.to_lowercase(); - if self.case_insensitive_desc.contains_key(&lowercase_name) { - return true; - } self.case_insensitive_typed_desc .contains_key(&lowercase_name) } pub fn registered_names(&self) -> Vec { - self.case_insensitive_desc + self.case_insensitive_typed_desc .keys() - .chain(self.case_insensitive_typed_desc.keys()) .cloned() .collect::>() } pub fn registered_features(&self) -> Vec { - self.case_insensitive_desc + self.case_insensitive_typed_desc .values() .into_iter() .map(|v| &v.features) - .chain( - self.case_insensitive_typed_desc - .values() - .into_iter() - .map(|v| &v.features), - ) .cloned() .collect::>() } diff --git a/common/functions/src/scalars/tuples/tuple.rs b/common/functions/src/scalars/tuples/tuple.rs index 17d7c1a788465..86e83796b6e53 100644 --- a/common/functions/src/scalars/tuples/tuple.rs +++ b/common/functions/src/scalars/tuples/tuple.rs @@ -15,28 +15,40 @@ use std::fmt; use std::sync::Arc; +use common_datavalues::DataTypePtr; use common_datavalues::StructColumn; use common_datavalues::StructType; use common_exception::Result; use crate::scalars::Function; -use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; +use crate::scalars::TypedFunctionDescription; #[derive(Clone)] pub struct TupleFunction { _display_name: String, + result_type: DataTypePtr, } impl TupleFunction { - pub fn try_create_func(_display_name: &str) -> Result> { + pub fn try_create_func( + _display_name: &str, + args: &[&common_datavalues::DataTypePtr], + ) -> Result> { + let names = (0..args.len()) + .map(|i| format!("item_{}", i)) + .collect::>(); + let types = args.iter().map(|x| (*x).clone()).collect::>(); + let result_type = Arc::new(StructType::create(names, types)); + Ok(Box::new(TupleFunction { _display_name: "tuple".to_string(), + result_type, })) } - pub fn desc() -> FunctionDescription { - FunctionDescription::creator(Box::new(Self::try_create_func)).features( + pub fn desc() -> TypedFunctionDescription { + TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features( FunctionFeatures::default() .deterministic() .disable_passthrough_null() @@ -52,14 +64,9 @@ impl Function for TupleFunction { fn return_type( &self, - args: &[&common_datavalues::DataTypePtr], + _args: &[&common_datavalues::DataTypePtr], ) -> Result { - let names = (0..args.len()) - .map(|i| format!("item_{}", i)) - .collect::>(); - let types = args.iter().map(|x| (*x).clone()).collect::>(); - let t = Arc::new(StructType::create(names, types)); - Ok(t) + Ok(self.result_type.clone()) } fn eval( @@ -67,21 +74,11 @@ impl Function for TupleFunction { columns: &common_datavalues::ColumnsWithField, _input_rows: usize, ) -> Result { - let mut cols = vec![]; - let mut types = vec![]; - - let names = (0..columns.len()) - .map(|i| format!("item_{}", i)) + let cols = columns + .iter() + .map(|v| v.column().clone()) .collect::>(); - - for c in columns { - cols.push(c.column().clone()); - types.push(c.data_type().clone()); - } - - let t = Arc::new(StructType::create(names, types)); - - let arr: StructColumn = StructColumn::from_data(cols, t); + let arr: StructColumn = StructColumn::from_data(cols, self.result_type.clone()); Ok(Arc::new(arr)) } } diff --git a/common/functions/src/scalars/tuples/tuple_class.rs b/common/functions/src/scalars/tuples/tuple_class.rs index 1844d30c4e79b..09ca71cc89a87 100644 --- a/common/functions/src/scalars/tuples/tuple_class.rs +++ b/common/functions/src/scalars/tuples/tuple_class.rs @@ -20,6 +20,6 @@ pub struct TupleClassFunction; impl TupleClassFunction { pub fn register(factory: &mut FunctionFactory) { - factory.register("tuple", TupleFunction::desc()); + factory.register_typed("tuple", TupleFunction::desc()); } } diff --git a/common/functions/src/scalars/uuids/uuid.rs b/common/functions/src/scalars/uuids/uuid.rs index ab898cd657236..fa3f773a4d5eb 100644 --- a/common/functions/src/scalars/uuids/uuid.rs +++ b/common/functions/src/scalars/uuids/uuid.rs @@ -22,9 +22,9 @@ pub struct UUIDFunction; impl UUIDFunction { pub fn register(factory: &mut FunctionFactory) { - factory.register("generateUUIDv4", UUIDv4Function::desc()); - factory.register("zeroUUID", UUIDZeroFunction::desc()); - factory.register("isemptyUUID", UUIDIsEmptyFunction::desc()); - factory.register("isnotemptyUUID", UUIDIsNotEmptyFunction::desc()); + factory.register_typed("generateUUIDv4", UUIDv4Function::desc()); + factory.register_typed("zeroUUID", UUIDZeroFunction::desc()); + factory.register_typed("isemptyUUID", UUIDIsEmptyFunction::desc()); + factory.register_typed("isnotemptyUUID", UUIDIsNotEmptyFunction::desc()); } } diff --git a/common/functions/src/scalars/uuids/uuid_creator.rs b/common/functions/src/scalars/uuids/uuid_creator.rs index dd49501570cf8..1e1f7abcae07b 100644 --- a/common/functions/src/scalars/uuids/uuid_creator.rs +++ b/common/functions/src/scalars/uuids/uuid_creator.rs @@ -24,8 +24,8 @@ use common_exception::Result; use uuid::Uuid; use crate::scalars::Function; -use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; +use crate::scalars::TypedFunctionDescription; pub type UUIDv4Function = UUIDCreatorFunction; pub type UUIDZeroFunction = UUIDCreatorFunction; @@ -39,15 +39,18 @@ pub struct UUIDCreatorFunction { impl UUIDCreatorFunction where T: UUIDCreator + Clone + Sync + Send + 'static { - pub fn try_create(display_name: &str) -> Result> { + pub fn try_create( + display_name: &str, + _args: &[&common_datavalues::DataTypePtr], + ) -> Result> { Ok(Box::new(UUIDCreatorFunction:: { display_name: display_name.to_string(), t: PhantomData, })) } - pub fn desc() -> FunctionDescription { - FunctionDescription::creator(Box::new(Self::try_create)) + pub fn desc() -> TypedFunctionDescription { + TypedFunctionDescription::creator(Box::new(Self::try_create)) .features(FunctionFeatures::default()) } } diff --git a/common/functions/src/scalars/uuids/uuid_verifier.rs b/common/functions/src/scalars/uuids/uuid_verifier.rs index dbc44951e2824..0452fd740c21a 100644 --- a/common/functions/src/scalars/uuids/uuid_verifier.rs +++ b/common/functions/src/scalars/uuids/uuid_verifier.rs @@ -29,8 +29,8 @@ use common_exception::Result; use uuid::Uuid; use crate::scalars::Function; -use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; +use crate::scalars::TypedFunctionDescription; pub type UUIDIsEmptyFunction = UUIDVerifierFunction; pub type UUIDIsNotEmptyFunction = UUIDVerifierFunction; @@ -44,15 +44,25 @@ pub struct UUIDVerifierFunction { impl UUIDVerifierFunction where T: UUIDVerifier + Clone + Sync + Send + 'static { - pub fn try_create(display_name: &str) -> Result> { + pub fn try_create( + display_name: &str, + args: &[&common_datavalues::DataTypePtr], + ) -> Result> { + if args[0].data_type_id() != TypeID::String && args[0].data_type_id() != TypeID::Null { + return Err(ErrorCode::IllegalDataType(format!( + "Expected string or null, but got {:?}", + args[0] + ))); + } + Ok(Box::new(UUIDVerifierFunction:: { display_name: display_name.to_string(), t: PhantomData, })) } - pub fn desc() -> FunctionDescription { - FunctionDescription::creator(Box::new(Self::try_create)).features( + pub fn desc() -> TypedFunctionDescription { + TypedFunctionDescription::creator(Box::new(Self::try_create)).features( FunctionFeatures::default() .disable_passthrough_null() .num_arguments(1), @@ -107,15 +117,8 @@ where T: UUIDVerifier + Clone + Sync + Send + 'static fn return_type( &self, - args: &[&common_datavalues::DataTypePtr], + _args: &[&common_datavalues::DataTypePtr], ) -> Result { - if args[0].data_type_id() != TypeID::String && args[0].data_type_id() != TypeID::Null { - return Err(ErrorCode::IllegalDataType(format!( - "Expected string or null, but got {:?}", - args[0] - ))); - } - Ok(BooleanType::arc()) } diff --git a/common/functions/tests/it/scalars/maths/abs.rs b/common/functions/tests/it/scalars/maths/abs.rs index 62548a87b1632..6fbad5b0f6a57 100644 --- a/common/functions/tests/it/scalars/maths/abs.rs +++ b/common/functions/tests/it/scalars/maths/abs.rs @@ -16,7 +16,7 @@ use common_datavalues::prelude::*; use common_exception::Result; use common_functions::scalars::*; -use crate::scalars::scalar_function2_test::test_scalar_functions; +use crate::scalars::scalar_function2_test::test_eval; use crate::scalars::scalar_function2_test::ScalarFunctionTest; #[test] @@ -51,7 +51,7 @@ fn test_abs_function() -> Result<()> { for (typ, test) in tests { match AbsFunction::try_create("abs", &[&typ]) { Ok(f) => { - test_scalar_functions(f, &[test], true)?; + test_eval(&f, &test.columns, true)?; } Err(cause) => { assert_eq!(test.error, cause.message(), "{}", test.name); diff --git a/common/functions/tests/it/scalars/maths/ceil.rs b/common/functions/tests/it/scalars/maths/ceil.rs index f5262ec8e9980..2611422e3c915 100644 --- a/common/functions/tests/it/scalars/maths/ceil.rs +++ b/common/functions/tests/it/scalars/maths/ceil.rs @@ -16,7 +16,7 @@ use common_datavalues::prelude::*; use common_exception::Result; use common_functions::scalars::*; -use crate::scalars::scalar_function2_test::test_scalar_functions; +use crate::scalars::scalar_function2_test::test_eval; use crate::scalars::scalar_function2_test::ScalarFunctionTest; #[test] @@ -81,7 +81,7 @@ fn test_ceil_function() -> Result<()> { for (typ, test) in tests { match CeilFunction::try_create("ceil", &[&typ]) { Ok(f) => { - test_scalar_functions(f, &[test], true)?; + test_eval(&f, &test.columns, true)?; } Err(cause) => { assert_eq!(test.error, cause.message(), "{}", test.name); diff --git a/common/functions/tests/it/scalars/maths/floor.rs b/common/functions/tests/it/scalars/maths/floor.rs index 5a97b1f4c2089..a7c486c751599 100644 --- a/common/functions/tests/it/scalars/maths/floor.rs +++ b/common/functions/tests/it/scalars/maths/floor.rs @@ -16,7 +16,7 @@ use common_datavalues::prelude::*; use common_exception::Result; use common_functions::scalars::*; -use crate::scalars::scalar_function2_test::test_scalar_functions; +use crate::scalars::scalar_function2_test::test_eval; use crate::scalars::scalar_function2_test::ScalarFunctionTest; #[test] @@ -81,7 +81,7 @@ fn test_floor_function() -> Result<()> { for (typ, test) in tests { match FloorFunction::try_create("floor", &[&typ]) { Ok(f) => { - test_scalar_functions(f, &[test], true)?; + test_eval(&f, &test.columns, true)?; } Err(cause) => { assert_eq!(test.error, cause.message(), "{}", test.name); diff --git a/common/functions/tests/it/scalars/maths/log.rs b/common/functions/tests/it/scalars/maths/log.rs index 4577413750778..1408051b8ee03 100644 --- a/common/functions/tests/it/scalars/maths/log.rs +++ b/common/functions/tests/it/scalars/maths/log.rs @@ -18,6 +18,7 @@ use common_datavalues::prelude::*; use common_exception::Result; use common_functions::scalars::*; +use crate::scalars::scalar_function2_test::test_eval; use crate::scalars::scalar_function2_test::test_scalar_functions; use crate::scalars::scalar_function2_test::ScalarFunctionTest; @@ -110,7 +111,7 @@ fn test_log_function() -> Result<()> { ]; for (test_function, test) in tests { - test_scalar_functions(test_function, &[test], true)?; + test_eval(&test_function, &test.columns, true)?; } Ok(()) diff --git a/common/functions/tests/it/scalars/maths/sign.rs b/common/functions/tests/it/scalars/maths/sign.rs index 2638409de5a84..45084a5ed752f 100644 --- a/common/functions/tests/it/scalars/maths/sign.rs +++ b/common/functions/tests/it/scalars/maths/sign.rs @@ -16,7 +16,7 @@ use common_datavalues::prelude::*; use common_exception::Result; use common_functions::scalars::*; -use crate::scalars::scalar_function2_test::test_scalar_functions; +use crate::scalars::scalar_function2_test::test_eval; use crate::scalars::scalar_function2_test::ScalarFunctionTest; #[test] @@ -111,7 +111,7 @@ fn test_sign_function() -> Result<()> { for (typ, test) in tests { match SignFunction::try_create("sign", &[&typ]) { Ok(f) => { - test_scalar_functions(f, &[test], true)?; + test_eval(&f, &test.columns, true)?; } Err(cause) => { assert_eq!(test.error, cause.message(), "{}", test.name); diff --git a/common/functions/tests/it/scalars/tuples.rs b/common/functions/tests/it/scalars/tuples.rs index 7b4e9e9eb7a03..1645a65a84916 100644 --- a/common/functions/tests/it/scalars/tuples.rs +++ b/common/functions/tests/it/scalars/tuples.rs @@ -21,36 +21,41 @@ use super::scalar_function2_test::ScalarFunctionTest; #[test] fn test_tuple_function() -> Result<()> { + let types = vec![vec![UInt8Type::arc()], vec![ + UInt8Type::arc(), + UInt8Type::arc(), + ]]; let tests = vec![ - ScalarFunctionTest { - name: "one element to tuple", - columns: vec![Series::from_data([0_u8])], - expect: Series::from_data([0_u8]), - error: "", - }, - ScalarFunctionTest { - name: "more element to tuple", - columns: vec![Series::from_data([0_u8]), Series::from_data([0_u8])], - expect: Series::from_data([0_u8]), - error: "", - }, + ( + vec![DataValue::Struct(vec![DataValue::UInt64(0)])], + ScalarFunctionTest { + name: "one element to tuple", + columns: vec![Series::from_data([0_u8])], + expect: Series::from_data([0_u8]), + error: "", + }, + ), + ( + vec![DataValue::Struct(vec![ + DataValue::UInt64(0), + DataValue::UInt64(0), + ])], + ScalarFunctionTest { + name: "more element to tuple", + columns: vec![Series::from_data([0_u8]), Series::from_data([0_u8])], + expect: Series::from_data([0_u8]), + error: "", + }, + ), ]; - let v1 = vec![DataValue::Struct(vec![DataValue::UInt64(0)])]; - let v2 = vec![DataValue::Struct(vec![ - DataValue::UInt64(0), - DataValue::UInt64(0), - ])]; - - let values = vec![v1, v2]; - - for (t, v) in tests.iter().zip(values.iter()) { - let func = TupleFunction::try_create_func("")?; - let result = test_eval(&func, &t.columns, false)?; + for ((val, test), typ) in tests.iter().zip(types.iter()) { + let func = TupleFunction::try_create_func("", &typ.iter().collect::>())?; + let result = test_eval(&func, &test.columns, false)?; let result = result.convert_full_column(); let result = (0..result.len()).map(|i| result.get(i)).collect::>(); - assert!(&result == v) + assert!(&result == val) } Ok(()) diff --git a/common/functions/tests/it/scalars/uuids/uuid_creator.rs b/common/functions/tests/it/scalars/uuids/uuid_creator.rs index 6791abe6c5e6f..b5146cebb1629 100644 --- a/common/functions/tests/it/scalars/uuids/uuid_creator.rs +++ b/common/functions/tests/it/scalars/uuids/uuid_creator.rs @@ -40,5 +40,9 @@ fn test_uuid_creator_functions() -> Result<()> { error: "", }]; - test_scalar_functions(UUIDZeroFunction::try_create("")?, &tests, true) + test_scalar_functions( + UUIDZeroFunction::try_create("", &[&StringType::arc()])?, + &tests, + true, + ) } diff --git a/common/functions/tests/it/scalars/uuids/uuid_verifier.rs b/common/functions/tests/it/scalars/uuids/uuid_verifier.rs index 8f156896736a4..96fe0fc5cec81 100644 --- a/common/functions/tests/it/scalars/uuids/uuid_verifier.rs +++ b/common/functions/tests/it/scalars/uuids/uuid_verifier.rs @@ -31,7 +31,11 @@ fn test_uuid_is_empty_functions() -> Result<()> { error: "", }]; - test_scalar_functions(UUIDIsEmptyFunction::try_create("")?, &tests, false) + test_scalar_functions( + UUIDIsEmptyFunction::try_create("", &[&StringType::arc()])?, + &tests, + false, + ) } #[test] @@ -46,5 +50,9 @@ fn test_uuid_is_not_empty_functions() -> Result<()> { error: "", }]; - test_scalar_functions(UUIDIsNotEmptyFunction::try_create("")?, &tests, false) + test_scalar_functions( + UUIDIsNotEmptyFunction::try_create("", &[&StringType::arc()])?, + &tests, + false, + ) }