diff --git a/common/datablocks/src/kernels/data_block_filter.rs b/common/datablocks/src/kernels/data_block_filter.rs index 8f832525e4fc..2d48570974c0 100644 --- a/common/datablocks/src/kernels/data_block_filter.rs +++ b/common/datablocks/src/kernels/data_block_filter.rs @@ -64,14 +64,7 @@ impl DataBlock { Ok(Arc::new(ConstColumn::new(inner_boolean, col.len()))) } else if predict.is_nullable() { let col: &NullableColumn = unsafe { Series::static_cast(predict) }; - let inner = col.inner(); - if inner.is_const() { - let col: &ConstColumn = unsafe { Series::static_cast(inner) }; - let inner_boolean = Self::cast_to_nonull_boolean(inner)?; - return Ok(Arc::new(ConstColumn::new(inner_boolean, col.len()))); - } - - let inner_boolean = Self::cast_to_nonull_boolean(inner)?; + let inner_boolean = Self::cast_to_nonull_boolean(col.inner())?; // no const nullable or nullable constant let inner: &BooleanColumn = Series::check_get(&inner_boolean)?; let validity = col.ensure_validity(); diff --git a/common/datavalues/src/columns/nullable/mod.rs b/common/datavalues/src/columns/nullable/mod.rs index 8779d5d462f7..fd87e7f1a39b 100644 --- a/common/datavalues/src/columns/nullable/mod.rs +++ b/common/datavalues/src/columns/nullable/mod.rs @@ -87,7 +87,7 @@ impl Column for NullableColumn { fn data_type(&self) -> DataTypePtr { let nest = self.column.data_type(); - Arc::new(NullableType::create(nest)) + NullableType::arc(nest) } fn column_type_name(&self) -> String { diff --git a/common/datavalues/src/types/data_type.rs b/common/datavalues/src/types/data_type.rs index fc50272d33d5..746e38f5af71 100644 --- a/common/datavalues/src/types/data_type.rs +++ b/common/datavalues/src/types/data_type.rs @@ -179,7 +179,7 @@ pub fn from_arrow_field(f: &ArrowField) -> DataTypePtr { let is_nullable = f.is_nullable; if is_nullable && ty.can_inside_nullable() { - Arc::new(NullableType::create(ty)) + NullableType::arc(ty) } else { ty } @@ -209,7 +209,7 @@ pub fn wrap_nullable(data_type: &DataTypePtr) -> DataTypePtr { if !data_type.can_inside_nullable() { return data_type.clone(); } - Arc::new(NullableType::create(data_type.clone())) + NullableType::arc(data_type.clone()) } pub fn remove_nullable(data_type: &DataTypePtr) -> DataTypePtr { diff --git a/common/datavalues/src/types/type_factory.rs b/common/datavalues/src/types/type_factory.rs index 362f5c2abb38..7a7b1ad6d760 100644 --- a/common/datavalues/src/types/type_factory.rs +++ b/common/datavalues/src/types/type_factory.rs @@ -114,7 +114,7 @@ impl TypeFactory { let mut nulls = HashMap::new(); for (k, v) in self.case_insensitive_types.iter() { if v.can_inside_nullable() { - let data_type: DataTypePtr = Arc::new(NullableType::create(v.clone())); + let data_type: DataTypePtr = NullableType::arc(v.clone()); nulls.insert( format!("Nullable({})", k).to_ascii_lowercase(), data_type.clone(), diff --git a/common/datavalues/src/types/type_nullable.rs b/common/datavalues/src/types/type_nullable.rs index 3bad3aae1c3d..aac96c5d4633 100644 --- a/common/datavalues/src/types/type_nullable.rs +++ b/common/datavalues/src/types/type_nullable.rs @@ -32,10 +32,7 @@ pub struct NullableType { impl NullableType { pub fn arc(inner: DataTypePtr) -> DataTypePtr { - Arc::new(Self { - name: format!("Nullable({})", inner.name()), - inner, - }) + Arc::new(Self::create(inner)) } pub fn create(inner: DataTypePtr) -> Self { diff --git a/common/datavalues/tests/it/types/create_column.rs b/common/datavalues/tests/it/types/create_column.rs index 4069f5fc2098..c0fe902e4786 100644 --- a/common/datavalues/tests/it/types/create_column.rs +++ b/common/datavalues/tests/it/types/create_column.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::Arc; - use common_datavalues::prelude::*; use common_exception::Result; use pretty_assertions::assert_eq; @@ -82,7 +80,7 @@ fn test_create_constant() -> Result<()> { }, Test { name: "nullable_i32", - data_type: Arc::new(NullableType::create(Int32Type::arc())), + data_type: NullableType::arc(Int32Type::arc()), value: DataValue::Null, size: 2, column_expected: Series::from_data(&[None, None, Some(1i32)][0..2]), diff --git a/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs b/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs index 999031124352..b9737ab7f923 100644 --- a/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs +++ b/common/functions/src/scalars/arithmetics/arithmetic_modulo.rs @@ -25,6 +25,7 @@ use num_traits::AsPrimitive; use super::utils::rem_scalar; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -160,4 +161,3 @@ where write!(f, "div") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/contexts/current_user.rs b/common/functions/src/scalars/contexts/current_user.rs index f290f6fb6e89..9678589db0c9 100644 --- a/common/functions/src/scalars/contexts/current_user.rs +++ b/common/functions/src/scalars/contexts/current_user.rs @@ -27,10 +27,7 @@ use crate::scalars::FunctionFeatures; pub struct CurrentUserFunction {} impl CurrentUserFunction { - pub fn try_create( - _display_name: &str, - _args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(_display_name: &str, _args: &[&DataTypePtr]) -> Result> { Ok(Box::new(CurrentUserFunction {})) } diff --git a/common/functions/src/scalars/contexts/database.rs b/common/functions/src/scalars/contexts/database.rs index aad5824bd1b9..f9fb0cdfaff8 100644 --- a/common/functions/src/scalars/contexts/database.rs +++ b/common/functions/src/scalars/contexts/database.rs @@ -28,10 +28,7 @@ pub struct DatabaseFunction {} // we bind database as first argument in eval impl DatabaseFunction { - pub fn try_create( - _display_name: &str, - _args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(_display_name: &str, _args: &[&DataTypePtr]) -> Result> { Ok(Box::new(DatabaseFunction {})) } diff --git a/common/functions/src/scalars/contexts/version.rs b/common/functions/src/scalars/contexts/version.rs index 2b20be1c07e7..fbffb71b8594 100644 --- a/common/functions/src/scalars/contexts/version.rs +++ b/common/functions/src/scalars/contexts/version.rs @@ -29,10 +29,7 @@ pub struct VersionFunction { } impl VersionFunction { - pub fn try_create( - display_name: &str, - _args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(display_name: &str, _args: &[&DataTypePtr]) -> Result> { Ok(Box::new(VersionFunction { _display_name: display_name.to_string(), })) diff --git a/common/functions/src/scalars/function_adapter.rs b/common/functions/src/scalars/function_adapter.rs index 22728d5fa02e..e142eb59222e 100644 --- a/common/functions/src/scalars/function_adapter.rs +++ b/common/functions/src/scalars/function_adapter.rs @@ -37,6 +37,7 @@ use common_exception::Result; use super::Function; use super::FunctionDescription; use super::Monotonicity; +use crate::scalars::FunctionContext; #[derive(Clone)] pub struct FunctionAdapter { @@ -127,7 +128,7 @@ impl Function for FunctionAdapter { .collect::>(); let col = self.eval(&columns, 1, func_ctx)?; - let col = if col.is_const() && col.len() != 1 { + let col = if col.is_const() && col.len() != input_rows { col.replicate(&[input_rows]) } else if col.is_null() { NullColumn::new(input_rows).arc() @@ -216,4 +217,3 @@ impl std::fmt::Display for FunctionAdapter { } } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/function_factory.rs b/common/functions/src/scalars/function_factory.rs index 153a302c71f9..9359835275a9 100644 --- a/common/functions/src/scalars/function_factory.rs +++ b/common/functions/src/scalars/function_factory.rs @@ -43,7 +43,7 @@ pub type FactoryCreator = pub struct FunctionDescription { pub(crate) features: FunctionFeatures, - pub function_creator: FactoryCreator, + pub(crate) function_creator: FactoryCreator, } impl FunctionDescription { @@ -106,28 +106,30 @@ impl FunctionFactory { let origin_name = name.as_ref(); let lowercase_name = origin_name.to_lowercase(); - // TODO(Winter): we should write similar function names into error message if function name is not found. - match self.case_insensitive_desc.get(&lowercase_name) { - Some(desc) => FunctionAdapter::try_create(desc, origin_name, args), - None => Err(ErrorCode::UnknownFunction(format!( - "Unsupported Function: {}", - origin_name - ))), - } + let desc = self + .case_insensitive_desc + .get(&lowercase_name) + .ok_or_else(|| { + // TODO(Winter): we should write similar function names into error message if function name is not found. + ErrorCode::UnknownFunction(format!("Unsupported Function: {}", origin_name)) + })?; + + FunctionAdapter::try_create(desc, origin_name, args) } pub fn get_features(&self, name: impl AsRef) -> Result { let origin_name = name.as_ref(); let lowercase_name = origin_name.to_lowercase(); - // TODO(Winter): we should write similar function names into error message if function name is not found. - match self.case_insensitive_desc.get(&lowercase_name) { - Some(desc) => Ok(desc.features.clone()), - None => Err(ErrorCode::UnknownFunction(format!( - "Unsupported Function: {}", - origin_name - ))), - } + let desc = self + .case_insensitive_desc + .get(&lowercase_name) + .ok_or_else(|| { + // TODO(Winter): we should write similar function names into error message if function name is not found. + ErrorCode::UnknownFunction(format!("Unsupported Function: {}", origin_name)) + })?; + + Ok(desc.features.clone()) } pub fn check(&self, name: impl AsRef) -> bool { diff --git a/common/functions/src/scalars/logics/and.rs b/common/functions/src/scalars/logics/and.rs index fcbb81042094..7c315efda14a 100644 --- a/common/functions/src/scalars/logics/and.rs +++ b/common/functions/src/scalars/logics/and.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::Arc; - use common_datavalues::prelude::*; use common_exception::Result; diff --git a/common/functions/src/scalars/logics/logic.rs b/common/functions/src/scalars/logics/logic.rs index 7acee27155f1..02763de08508 100644 --- a/common/functions/src/scalars/logics/logic.rs +++ b/common/functions/src/scalars/logics/logic.rs @@ -53,7 +53,7 @@ pub struct LogicFunctionImpl { } pub trait LogicExpression: Sync + Send { - fn eval(columns: &ColumnsWithField, input_rows: usize, _nullable: bool) -> Result; + fn eval(columns: &ColumnsWithField, input_rows: usize, nullable: bool) -> Result; } impl LogicFunctionImpl diff --git a/common/functions/src/scalars/logics/macros.rs b/common/functions/src/scalars/logics/macros.rs index 0c27d731f582..082bea777e78 100644 --- a/common/functions/src/scalars/logics/macros.rs +++ b/common/functions/src/scalars/logics/macros.rs @@ -30,7 +30,7 @@ macro_rules! impl_logic_expression { impl LogicExpression for $name { fn eval(columns: &ColumnsWithField, input_rows: usize, nullable: bool) -> Result { let dt = if nullable { - Arc::new(NullableType::create(BooleanType::arc())) + NullableType::arc(BooleanType::arc()) } else { BooleanType::arc() }; diff --git a/common/functions/src/scalars/logics/or.rs b/common/functions/src/scalars/logics/or.rs index e5594c6f687c..f8f9bfa135cb 100644 --- a/common/functions/src/scalars/logics/or.rs +++ b/common/functions/src/scalars/logics/or.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::Arc; - use common_datavalues::prelude::*; use common_exception::Result; diff --git a/common/functions/src/scalars/maths/floor.rs b/common/functions/src/scalars/maths/floor.rs index c61d47ef6b34..d6f8b8f0c25f 100644 --- a/common/functions/src/scalars/maths/floor.rs +++ b/common/functions/src/scalars/maths/floor.rs @@ -25,6 +25,7 @@ use crate::scalars::function_factory::FunctionDescription; use crate::scalars::scalar_unary_op; use crate::scalars::EvalContext; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionFeatures; use crate::scalars::Monotonicity; @@ -92,4 +93,3 @@ impl fmt::Display for FloorFunction { write!(f, "{}", self.display_name.to_uppercase()) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/maths/pi.rs b/common/functions/src/scalars/maths/pi.rs index 9fd1c22057d1..9870310cf1a1 100644 --- a/common/functions/src/scalars/maths/pi.rs +++ b/common/functions/src/scalars/maths/pi.rs @@ -20,6 +20,7 @@ use common_exception::Result; use crate::scalars::function_factory::FunctionDescription; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionFeatures; #[derive(Clone)] @@ -64,4 +65,3 @@ impl fmt::Display for PiFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/others/exists.rs b/common/functions/src/scalars/others/exists.rs index 640aa3f66856..7043d6618e0c 100644 --- a/common/functions/src/scalars/others/exists.rs +++ b/common/functions/src/scalars/others/exists.rs @@ -27,10 +27,7 @@ use crate::scalars::FunctionFeatures; pub struct ExistsFunction; impl ExistsFunction { - pub fn try_create( - _display_name: &str, - _args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(_display_name: &str, _args: &[&DataTypePtr]) -> Result> { Ok(Box::new(ExistsFunction {})) } diff --git a/common/functions/src/scalars/others/ignore.rs b/common/functions/src/scalars/others/ignore.rs index d5558e9ba9b4..c78fc8d00852 100644 --- a/common/functions/src/scalars/others/ignore.rs +++ b/common/functions/src/scalars/others/ignore.rs @@ -36,10 +36,7 @@ pub struct IgnoreFunction { } impl IgnoreFunction { - pub fn try_create( - display_name: &str, - _args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(display_name: &str, _args: &[&DataTypePtr]) -> Result> { Ok(Box::new(IgnoreFunction { display_name: display_name.to_string(), })) diff --git a/common/functions/src/scalars/others/inet_aton.rs b/common/functions/src/scalars/others/inet_aton.rs index dce10b81cfe4..fbb72c0d5591 100644 --- a/common/functions/src/scalars/others/inet_aton.rs +++ b/common/functions/src/scalars/others/inet_aton.rs @@ -38,10 +38,7 @@ pub struct InetAtonFunctionImpl { } impl InetAtonFunctionImpl { - pub fn try_create( - display_name: &str, - args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { assert_string(args[0])?; Ok(Box::new(InetAtonFunctionImpl:: { diff --git a/common/functions/src/scalars/others/inet_ntoa.rs b/common/functions/src/scalars/others/inet_ntoa.rs index d67116b45540..59125777f75b 100644 --- a/common/functions/src/scalars/others/inet_ntoa.rs +++ b/common/functions/src/scalars/others/inet_ntoa.rs @@ -15,7 +15,6 @@ use std::fmt; use std::net::Ipv4Addr; use std::str; -use std::sync::Arc; use common_datavalues::prelude::*; use common_exception::Result; @@ -76,7 +75,7 @@ impl Function for InetNtoaFunctionImpl Result { if SUPPRESS_CAST_ERROR { - let cast_to: DataTypePtr = Arc::new(NullableType::create(UInt32Type::arc())); + let cast_to: DataTypePtr = NullableType::arc(UInt32Type::arc()); let cast_options = CastOptions { // we allow cast failure exception_mode: ExceptionMode::Zero, diff --git a/common/functions/src/scalars/others/running_difference_function.rs b/common/functions/src/scalars/others/running_difference_function.rs index 521037edafb7..083f8eee61a9 100644 --- a/common/functions/src/scalars/others/running_difference_function.rs +++ b/common/functions/src/scalars/others/running_difference_function.rs @@ -48,7 +48,7 @@ impl RunningDifferenceFunction { | TypeID::DateTime64 | TypeID::Interval => Ok(type_primitive::Int64Type::arc()), TypeID::Float32 | TypeID::Float64 => Ok(type_primitive::Float64Type::arc()), - _ => Result::Err(ErrorCode::IllegalDataType( + _ => Err(ErrorCode::IllegalDataType( "Argument for function runningDifference must have numeric type", )), }?; diff --git a/common/functions/src/scalars/others/sleep.rs b/common/functions/src/scalars/others/sleep.rs index 300c4972efd6..8b4c16463202 100644 --- a/common/functions/src/scalars/others/sleep.rs +++ b/common/functions/src/scalars/others/sleep.rs @@ -33,10 +33,7 @@ pub struct SleepFunction { } impl SleepFunction { - pub fn try_create( - display_name: &str, - args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { assert_numeric(args[0])?; Ok(Box::new(SleepFunction { display_name: display_name.to_string(), diff --git a/common/functions/src/scalars/others/to_type_name.rs b/common/functions/src/scalars/others/to_type_name.rs index c06d659b55d4..08dd3800b3ac 100644 --- a/common/functions/src/scalars/others/to_type_name.rs +++ b/common/functions/src/scalars/others/to_type_name.rs @@ -30,10 +30,7 @@ pub struct ToTypeNameFunction { } impl ToTypeNameFunction { - pub fn try_create( - display_name: &str, - _args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(display_name: &str, _args: &[&DataTypePtr]) -> Result> { Ok(Box::new(ToTypeNameFunction { _display_name: display_name.to_string(), })) diff --git a/common/functions/src/scalars/semi_structureds/check_json.rs b/common/functions/src/scalars/semi_structureds/check_json.rs index aef4bb99b96d..ab9bfa103f61 100644 --- a/common/functions/src/scalars/semi_structureds/check_json.rs +++ b/common/functions/src/scalars/semi_structureds/check_json.rs @@ -13,7 +13,6 @@ // limitations under the License. use std::fmt; -use std::sync::Arc; use common_datavalues::prelude::*; use common_exception::ErrorCode; @@ -49,7 +48,7 @@ impl Function for CheckJsonFunction { } fn return_type(&self) -> DataTypePtr { - Arc::new(NullableType::create(StringType::arc())) + NullableType::arc(StringType::arc()) } fn eval( diff --git a/common/functions/src/scalars/semi_structureds/parse_json.rs b/common/functions/src/scalars/semi_structureds/parse_json.rs index 916458cea243..21099054ba8e 100644 --- a/common/functions/src/scalars/semi_structureds/parse_json.rs +++ b/common/functions/src/scalars/semi_structureds/parse_json.rs @@ -123,12 +123,7 @@ impl Function for ParseJsonFunctionImpl::with_capacity(input_rows); @@ -138,7 +133,7 @@ impl Function for ParseJsonFunctionImpl { for (i, v) in values.iter().enumerate() { if let Some(valids) = valids { diff --git a/common/functions/src/scalars/strings/bin.rs b/common/functions/src/scalars/strings/bin.rs index 86b311622edf..703899d84e0f 100644 --- a/common/functions/src/scalars/strings/bin.rs +++ b/common/functions/src/scalars/strings/bin.rs @@ -21,6 +21,7 @@ use common_exception::Result; use crate::scalars::assert_numeric; use crate::scalars::cast_column_field; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -109,4 +110,3 @@ impl fmt::Display for BinFunction { write!(f, "BIN") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/char_.rs b/common/functions/src/scalars/strings/char_.rs index bfd9cf450880..1d271b095016 100644 --- a/common/functions/src/scalars/strings/char_.rs +++ b/common/functions/src/scalars/strings/char_.rs @@ -20,6 +20,7 @@ use common_exception::Result; use crate::scalars::assert_numeric; use crate::scalars::default_column_cast; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -104,4 +105,3 @@ impl fmt::Display for CharFunction { write!(f, "CHAR") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/concat.rs b/common/functions/src/scalars/strings/concat.rs index f65b051f639d..0fc776c51ea6 100644 --- a/common/functions/src/scalars/strings/concat.rs +++ b/common/functions/src/scalars/strings/concat.rs @@ -19,6 +19,7 @@ use common_exception::Result; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -87,4 +88,3 @@ impl fmt::Display for ConcatFunction { write!(f, "CONCAT") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/concat_ws.rs b/common/functions/src/scalars/strings/concat_ws.rs index e2bd91be8862..2583678c6a64 100644 --- a/common/functions/src/scalars/strings/concat_ws.rs +++ b/common/functions/src/scalars/strings/concat_ws.rs @@ -19,6 +19,7 @@ use common_exception::Result; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -210,4 +211,3 @@ impl fmt::Display for ConcatWsFunction { write!(f, "CONCAT_WS") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/elt.rs b/common/functions/src/scalars/strings/elt.rs index 769ddca34f1d..d3bc0e29fb10 100644 --- a/common/functions/src/scalars/strings/elt.rs +++ b/common/functions/src/scalars/strings/elt.rs @@ -23,6 +23,7 @@ use num_traits::AsPrimitive; use crate::scalars::assert_numeric; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -178,4 +179,3 @@ impl fmt::Display for EltFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/export_set.rs b/common/functions/src/scalars/strings/export_set.rs index e8004df89215..b8eca8e1715f 100644 --- a/common/functions/src/scalars/strings/export_set.rs +++ b/common/functions/src/scalars/strings/export_set.rs @@ -23,6 +23,7 @@ use crate::scalars::assert_numeric; use crate::scalars::assert_string; use crate::scalars::cast_with_type; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; use crate::scalars::DEFAULT_CAST_OPTIONS; @@ -167,4 +168,3 @@ fn export_set<'a>( } } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/field.rs b/common/functions/src/scalars/strings/field.rs index 5c4d837fd99f..98cc156c15fa 100644 --- a/common/functions/src/scalars/strings/field.rs +++ b/common/functions/src/scalars/strings/field.rs @@ -19,6 +19,7 @@ use common_exception::Result; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -95,4 +96,3 @@ impl fmt::Display for FieldFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/find_in_set.rs b/common/functions/src/scalars/strings/find_in_set.rs index 176496276610..be32e5f27014 100644 --- a/common/functions/src/scalars/strings/find_in_set.rs +++ b/common/functions/src/scalars/strings/find_in_set.rs @@ -21,6 +21,7 @@ use crate::scalars::assert_string; use crate::scalars::scalar_binary_op; use crate::scalars::EvalContext; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -90,4 +91,3 @@ fn find_in_set(str: &[u8], list: &[u8], _ctx: &mut EvalContext) -> u64 { } 0 } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/format.rs b/common/functions/src/scalars/strings/format.rs index ee5edd1e4e36..30a0cdd89c6a 100644 --- a/common/functions/src/scalars/strings/format.rs +++ b/common/functions/src/scalars/strings/format.rs @@ -27,6 +27,7 @@ use crate::scalars::assert_string; use crate::scalars::scalar_binary_op; use crate::scalars::EvalContext; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -121,4 +122,3 @@ impl fmt::Display for FormatFunction { write!(f, "FORMAT") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/hex.rs b/common/functions/src/scalars/strings/hex.rs index 42c704f9eb61..f8500af17149 100644 --- a/common/functions/src/scalars/strings/hex.rs +++ b/common/functions/src/scalars/strings/hex.rs @@ -22,6 +22,7 @@ use common_exception::Result; use crate::scalars::cast_column_field; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -107,4 +108,3 @@ impl fmt::Display for HexFunction { write!(f, "HEX") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/insert.rs b/common/functions/src/scalars/strings/insert.rs index 63400a5170c9..a5d26dadc8ba 100644 --- a/common/functions/src/scalars/strings/insert.rs +++ b/common/functions/src/scalars/strings/insert.rs @@ -22,6 +22,7 @@ use num_traits::AsPrimitive; use crate::scalars::assert_numeric; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -127,4 +128,3 @@ impl fmt::Display for InsertFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/leftright.rs b/common/functions/src/scalars/strings/leftright.rs index 17aa65ce4304..67f36265fc87 100644 --- a/common/functions/src/scalars/strings/leftright.rs +++ b/common/functions/src/scalars/strings/leftright.rs @@ -25,6 +25,7 @@ use crate::scalars::assert_string; use crate::scalars::scalar_binary_op_ref; use crate::scalars::EvalContext; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -112,4 +113,3 @@ impl fmt::Display for LeftRightFunction { f.write_str(&self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/locate.rs b/common/functions/src/scalars/strings/locate.rs index 896103f7796a..e8230a3e8613 100644 --- a/common/functions/src/scalars/strings/locate.rs +++ b/common/functions/src/scalars/strings/locate.rs @@ -21,6 +21,7 @@ use crate::scalars::assert_numeric; use crate::scalars::assert_string; use crate::scalars::default_column_cast; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -125,4 +126,3 @@ fn find_at(str: &[u8], substr: &[u8], pos: u64) -> u64 { 0_u64 } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/oct.rs b/common/functions/src/scalars/strings/oct.rs index fcbeb2c3d730..522a7959e3b9 100644 --- a/common/functions/src/scalars/strings/oct.rs +++ b/common/functions/src/scalars/strings/oct.rs @@ -21,6 +21,7 @@ use common_exception::Result; use crate::scalars::assert_numeric; use crate::scalars::cast_column_field; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -111,4 +112,3 @@ impl fmt::Display for OctFunction { write!(f, "OCT") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/pad.rs b/common/functions/src/scalars/strings/pad.rs index 9a433293104c..e9e506c33bdc 100644 --- a/common/functions/src/scalars/strings/pad.rs +++ b/common/functions/src/scalars/strings/pad.rs @@ -23,6 +23,7 @@ use num_traits::AsPrimitive; use crate::scalars::assert_numeric; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -149,4 +150,3 @@ impl fmt::Display for PadFunction { f.write_str(&self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/regexp_instr.rs b/common/functions/src/scalars/strings/regexp_instr.rs index b464d0ecd07f..8ed5f27e91cb 100644 --- a/common/functions/src/scalars/strings/regexp_instr.rs +++ b/common/functions/src/scalars/strings/regexp_instr.rs @@ -27,6 +27,7 @@ use crate::scalars::assert_string; use crate::scalars::cast_column_field; use crate::scalars::strings::regexp_like::build_regexp_from_pattern; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -40,10 +41,7 @@ impl RegexpInStrFunction { for (i, arg) in args.iter().enumerate() { if i < 2 || i == 5 { assert_string(*arg)?; - } else if !arg.data_type_id().is_integer() - && !arg.data_type_id().is_string() - && !arg.data_type_id().is_null() - { + } else if !arg.data_type_id().is_integer() && !arg.data_type_id().is_string() { return Err(ErrorCode::IllegalDataType(format!( "Expected integer or string or null, but got {}", args[i].data_type_id() @@ -279,4 +277,3 @@ impl fmt::Display for RegexpInStrFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/regexp_like.rs b/common/functions/src/scalars/strings/regexp_like.rs index af353ea8f307..f57d873fe157 100644 --- a/common/functions/src/scalars/strings/regexp_like.rs +++ b/common/functions/src/scalars/strings/regexp_like.rs @@ -26,6 +26,7 @@ use regex::bytes::RegexBuilder as BytesRegexBuilder; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -245,4 +246,3 @@ pub fn build_regexp_from_pattern( )) }) } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/regexp_substr.rs b/common/functions/src/scalars/strings/regexp_substr.rs index 2b1936fa03ce..b6a6fe2ae486 100644 --- a/common/functions/src/scalars/strings/regexp_substr.rs +++ b/common/functions/src/scalars/strings/regexp_substr.rs @@ -14,7 +14,6 @@ use std::collections::HashMap; use std::fmt; -use std::sync::Arc; use bstr::ByteSlice; use common_datavalues::prelude::*; @@ -27,6 +26,7 @@ use crate::scalars::assert_string; use crate::scalars::cast_column_field; use crate::scalars::strings::regexp_like::build_regexp_from_pattern; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -40,10 +40,7 @@ impl RegexpSubStrFunction { for (i, arg) in args.iter().enumerate() { if i < 2 || i == 4 { assert_string(*arg)?; - } else if !arg.data_type_id().is_integer() - && !arg.data_type_id().is_string() - && !arg.data_type_id().is_null() - { + } else if !arg.data_type_id().is_integer() && !arg.data_type_id().is_string() { return Err(ErrorCode::IllegalDataType(format!( "Expected integer or string or null, but got {}", args[i].data_type_id() @@ -71,7 +68,7 @@ impl Function for RegexpSubStrFunction { } fn return_type(&self) -> DataTypePtr { - Arc::new(NullableType::create(StringType::arc())) + NullableType::arc(StringType::arc()) } // Notes: https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-substr @@ -247,4 +244,3 @@ impl fmt::Display for RegexpSubStrFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/repeat.rs b/common/functions/src/scalars/strings/repeat.rs index 1ae5576a18d9..ff3e645125a2 100644 --- a/common/functions/src/scalars/strings/repeat.rs +++ b/common/functions/src/scalars/strings/repeat.rs @@ -20,6 +20,7 @@ use common_exception::Result; use crate::scalars::cast_column_field; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -32,14 +33,14 @@ pub struct RepeatFunction { impl RepeatFunction { pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { - if !args[0].data_type_id().is_string() && !args[0].data_type_id().is_null() { + if !args[0].data_type_id().is_string() { return Err(ErrorCode::IllegalDataType(format!( "Expected parameter 1 is string, but got {}", args[0].data_type_id() ))); } - if !args[1].data_type_id().is_unsigned_integer() && !args[1].data_type_id().is_null() { + if !args[1].data_type_id().is_unsigned_integer() { return Err(ErrorCode::IllegalDataType(format!( "Expected parameter 2 is unsigned integer or null, but got {}", args[1].data_type_id() @@ -72,8 +73,7 @@ impl Function for RepeatFunction { input_rows: usize, _func_ctx: FunctionContext, ) -> Result { - let col1 = cast_column_field(&columns[0], &StringType::arc())?; - let col1_viewer = Vu8::try_create_viewer(&col1)?; + let col1_viewer = Vu8::try_create_viewer(columns[0].column())?; let col2 = cast_column_field(&columns[1], &UInt64Type::arc())?; let col2_viewer = u64::try_create_viewer(&col2)?; @@ -106,4 +106,3 @@ fn repeat(string: impl AsRef<[u8]>, times: u64) -> Result> { } Ok(string.as_ref().repeat(times as usize)) } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/replace.rs b/common/functions/src/scalars/strings/replace.rs index 79b9f572252f..584d1f773786 100644 --- a/common/functions/src/scalars/strings/replace.rs +++ b/common/functions/src/scalars/strings/replace.rs @@ -19,6 +19,7 @@ use common_exception::Result; use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -106,4 +107,3 @@ impl fmt::Display for ReplaceFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/space.rs b/common/functions/src/scalars/strings/space.rs index 50e8c101661d..d18f6e8ee840 100644 --- a/common/functions/src/scalars/strings/space.rs +++ b/common/functions/src/scalars/strings/space.rs @@ -24,6 +24,7 @@ use crate::scalars::assert_numeric; use crate::scalars::scalar_unary_op; use crate::scalars::EvalContext; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -78,4 +79,3 @@ impl fmt::Display for SpaceFunction { write!(f, "{}", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/strcmp.rs b/common/functions/src/scalars/strings/strcmp.rs index 67cc2e52903f..5c897c7b0088 100644 --- a/common/functions/src/scalars/strings/strcmp.rs +++ b/common/functions/src/scalars/strings/strcmp.rs @@ -23,6 +23,7 @@ use crate::scalars::assert_string; use crate::scalars::scalar_binary_op; use crate::scalars::EvalContext; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -102,4 +103,3 @@ fn strcmp(s1: &[u8], s2: &[u8], _ctx: &mut EvalContext) -> i8 { Ordering::Less => -1, } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/string2number.rs b/common/functions/src/scalars/strings/string2number.rs index 586cc75f7105..9cd7af9970c3 100644 --- a/common/functions/src/scalars/strings/string2number.rs +++ b/common/functions/src/scalars/strings/string2number.rs @@ -16,10 +16,11 @@ use std::marker::PhantomData; use std::sync::Arc; use common_datavalues::prelude::*; -use common_exception::ErrorCode; use common_exception::Result; +use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -43,13 +44,7 @@ where R: PrimitiveType + Clone + ToDataType, { pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { - // We allow string AND null as input - if !args[0].data_type_id().is_string() { - return Err(ErrorCode::IllegalDataType(format!( - "Expected string, numeric or null, but got {:?}", - args[0] - ))); - } + assert_string(args[0])?; Ok(Box::new(Self { display_name: display_name.to_string(), @@ -111,4 +106,3 @@ impl fmt::Display for String2NumberFunction { write!(f, "{}()", self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/string2string.rs b/common/functions/src/scalars/strings/string2string.rs index ee9e1670fcad..585cd3d7e0cc 100644 --- a/common/functions/src/scalars/strings/string2string.rs +++ b/common/functions/src/scalars/strings/string2string.rs @@ -17,11 +17,11 @@ use std::sync::Arc; use common_datavalues::prelude::*; use common_datavalues::StringType; -use common_datavalues::TypeID; -use common_exception::ErrorCode; use common_exception::Result; +use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -44,12 +44,7 @@ pub struct String2StringFunction { impl String2StringFunction { pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { - if args[0].data_type_id() != TypeID::String { - return Err(ErrorCode::IllegalDataType(format!( - "Expected string arg, but got {:?}", - args[0] - ))); - } + assert_string(args[0])?; Ok(Box::new(Self { display_name: display_name.to_string(), @@ -93,4 +88,3 @@ impl fmt::Display for String2StringFunction { f.write_str(&self.display_name) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/substring.rs b/common/functions/src/scalars/strings/substring.rs index 69b47338fda8..179a7548359b 100644 --- a/common/functions/src/scalars/strings/substring.rs +++ b/common/functions/src/scalars/strings/substring.rs @@ -19,8 +19,10 @@ use common_exception::ErrorCode; use common_exception::Result; use itertools::izip; +use crate::scalars::assert_string; use crate::scalars::cast_column_field; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -31,17 +33,9 @@ pub struct SubstringFunction { impl SubstringFunction { pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { - if !args[0].data_type_id().is_string() && !args[0].data_type_id().is_null() { - return Err(ErrorCode::IllegalDataType(format!( - "Expected string or null, but got {}", - args[0].data_type_id() - ))); - } + assert_string(args[0])?; - if !args[1].data_type_id().is_integer() - && !args[1].data_type_id().is_string() - && !args[1].data_type_id().is_null() - { + if !args[1].data_type_id().is_integer() && !args[1].data_type_id().is_string() { return Err(ErrorCode::IllegalDataType(format!( "Expected integer or string or null, but got {}", args[1].data_type_id() @@ -51,7 +45,6 @@ impl SubstringFunction { if args.len() > 2 && !args[2].data_type_id().is_integer() && !args[2].data_type_id().is_string() - && !args[2].data_type_id().is_null() { return Err(ErrorCode::IllegalDataType(format!( "Expected integer or string or null, but got {}", @@ -156,4 +149,3 @@ fn substr<'a>(str: &'a [u8], pos: &i64, len: &u64) -> &'a [u8] { } &str[0..0] } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/substring_index.rs b/common/functions/src/scalars/strings/substring_index.rs index db53cb354c40..b262c396576b 100644 --- a/common/functions/src/scalars/strings/substring_index.rs +++ b/common/functions/src/scalars/strings/substring_index.rs @@ -21,6 +21,7 @@ use itertools::izip; use crate::scalars::cast_column_field; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -31,28 +32,19 @@ pub struct SubstringIndexFunction { impl SubstringIndexFunction { pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { - if !args[0].data_type_id().is_numeric() - && !args[0].data_type_id().is_string() - && !args[0].data_type_id().is_null() - { + if !args[0].data_type_id().is_numeric() && !args[0].data_type_id().is_string() { return Err(ErrorCode::IllegalDataType(format!( "Expected string or null, but got {}", args[0].data_type_id() ))); } - if !args[1].data_type_id().is_numeric() - && !args[1].data_type_id().is_string() - && !args[1].data_type_id().is_null() - { + if !args[1].data_type_id().is_numeric() && !args[1].data_type_id().is_string() { return Err(ErrorCode::IllegalDataType(format!( "Expected integer or string or null, but got {}", args[1].data_type_id() ))); } - if !args[2].data_type_id().is_integer() - && !args[2].data_type_id().is_string() - && !args[2].data_type_id().is_null() - { + if !args[2].data_type_id().is_integer() && !args[2].data_type_id().is_string() { return Err(ErrorCode::IllegalDataType(format!( "Expected integer or string or null, but got {}", args[2].data_type_id() @@ -142,4 +134,3 @@ fn substring_index<'a>(str: &'a [u8], delim: &'a [u8], count: &i64) -> &'a [u8] } str } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/strings/unhex.rs b/common/functions/src/scalars/strings/unhex.rs index d4aa11770e0f..ea960e4c4e92 100644 --- a/common/functions/src/scalars/strings/unhex.rs +++ b/common/functions/src/scalars/strings/unhex.rs @@ -18,8 +18,9 @@ use common_datavalues::prelude::*; use common_exception::ErrorCode; use common_exception::Result; -use crate::scalars::cast_column_field; +use crate::scalars::assert_string; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -30,13 +31,7 @@ pub struct UnhexFunction { impl UnhexFunction { pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result> { - if !args[0].data_type_id().is_string() && !args[0].data_type_id().is_null() { - return Err(ErrorCode::IllegalDataType(format!( - "Expected string or null, but got {}", - args[0].data_type_id() - ))); - } - + assert_string(args[0])?; Ok(Box::new(UnhexFunction { _display_name: display_name.to_string(), })) @@ -65,8 +60,11 @@ impl Function for UnhexFunction { ) -> Result { const BUFFER_SIZE: usize = 32; - let col = cast_column_field(&columns[0], &StringType::arc())?; - let col = col.as_any().downcast_ref::().unwrap(); + let col = columns[0] + .column() + .as_any() + .downcast_ref::() + .unwrap(); let mut builder: ColumnBuilder = ColumnBuilder::with_capacity(input_rows); @@ -103,4 +101,3 @@ impl fmt::Display for UnhexFunction { write!(f, "UNHEX") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/tuples/tuple.rs b/common/functions/src/scalars/tuples/tuple.rs index 6c2f1dde47f0..0cc57f9a03ac 100644 --- a/common/functions/src/scalars/tuples/tuple.rs +++ b/common/functions/src/scalars/tuples/tuple.rs @@ -21,6 +21,7 @@ use common_datavalues::StructType; use common_exception::Result; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -33,7 +34,7 @@ pub struct TupleFunction { impl TupleFunction { pub fn try_create_func( _display_name: &str, - args: &[&common_datavalues::DataTypePtr], + args: &[&DataTypePtr], ) -> Result> { let names = (0..args.len()) .map(|i| format!("item_{}", i)) @@ -86,4 +87,3 @@ impl std::fmt::Display for TupleFunction { write!(f, "TUPLE") } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/uuids/uuid_creator.rs b/common/functions/src/scalars/uuids/uuid_creator.rs index 44aa890fcdc2..82f73f2d769c 100644 --- a/common/functions/src/scalars/uuids/uuid_creator.rs +++ b/common/functions/src/scalars/uuids/uuid_creator.rs @@ -25,6 +25,7 @@ use common_exception::Result; use uuid::Uuid; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -40,10 +41,7 @@ pub struct UUIDCreatorFunction { impl UUIDCreatorFunction where T: UUIDCreator + Clone + Sync + Send + 'static { - pub fn try_create( - display_name: &str, - _args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(display_name: &str, _args: &[&DataTypePtr]) -> Result> { Ok(Box::new(UUIDCreatorFunction:: { display_name: display_name.to_string(), t: PhantomData, @@ -107,4 +105,3 @@ where T: UUIDCreator + Clone + Sync + Send + 'static Ok(ConstColumn::new(col.arc(), input_rows).arc()) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/src/scalars/uuids/uuid_verifier.rs b/common/functions/src/scalars/uuids/uuid_verifier.rs index c4ff97de98a7..cd5877363230 100644 --- a/common/functions/src/scalars/uuids/uuid_verifier.rs +++ b/common/functions/src/scalars/uuids/uuid_verifier.rs @@ -30,6 +30,7 @@ use common_exception::Result; use uuid::Uuid; use crate::scalars::Function; +use crate::scalars::FunctionContext; use crate::scalars::FunctionDescription; use crate::scalars::FunctionFeatures; @@ -45,10 +46,7 @@ pub struct UUIDVerifierFunction { impl UUIDVerifierFunction where T: UUIDVerifier + Clone + Sync + Send + 'static { - pub fn try_create( - display_name: &str, - args: &[&common_datavalues::DataTypePtr], - ) -> Result> { + pub fn try_create(display_name: &str, args: &[&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 {:?}", @@ -146,4 +144,3 @@ where T: UUIDVerifier + Clone + Sync + Send + 'static Ok(Arc::new(result_column)) } } -use crate::scalars::FunctionContext; diff --git a/common/functions/tests/it/scalars/others.rs b/common/functions/tests/it/scalars/others.rs index 02045374448c..928d7a3834ad 100644 --- a/common/functions/tests/it/scalars/others.rs +++ b/common/functions/tests/it/scalars/others.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::Arc; - use common_datavalues::prelude::*; use common_exception::Result; @@ -229,10 +227,7 @@ fn test_running_difference_datetime32_first_null() -> Result<()> { name: "datetime32_first_null", columns: vec![ColumnWithField::new( Series::from_data([None, Some(3_u32), None, Some(4), Some(10)]), - DataField::new( - "dummy_1", - Arc::new(NullableType::create(DateTime32Type::arc(None))), - ), + DataField::new("dummy_1", NullableType::arc(DateTime32Type::arc(None))), )], expect: Series::from_data([None, None, None, None, Some(6_i64)]), error: "", @@ -241,10 +236,7 @@ fn test_running_difference_datetime32_first_null() -> Result<()> { name: "datetime32_first_not_null", columns: vec![ColumnWithField::new( Series::from_data([Some(2_u32), Some(3), None, Some(4), Some(10)]), - DataField::new( - "dummy_1", - Arc::new(NullableType::create(DateTime32Type::arc(None))), - ), + DataField::new("dummy_1", NullableType::arc(DateTime32Type::arc(None))), )], expect: Series::from_data([Some(0_i64), Some(1), None, None, Some(6)]), error: "", diff --git a/query/src/sql/statements/analyzer_expr.rs b/query/src/sql/statements/analyzer_expr.rs index f5ed9ed884b7..38947d655dfa 100644 --- a/query/src/sql/statements/analyzer_expr.rs +++ b/query/src/sql/statements/analyzer_expr.rs @@ -541,7 +541,7 @@ impl ExprRPNBuilder { Expr::TryCast { data_type, .. } => { let mut ty = SQLCommon::make_data_type(data_type)?; if ty.can_inside_nullable() { - ty = Arc::new(NullableType::create(ty)) + ty = NullableType::arc(ty) } self.rpn.push(ExprRPNItem::Cast(ty)); } diff --git a/tests/suites/0_stateless/02_function/02_0026_function_string_substring_index.sql b/tests/suites/0_stateless/02_function/02_0026_function_string_substring_index.sql index 548409be23c1..06cdd0f446a6 100644 --- a/tests/suites/0_stateless/02_function/02_0026_function_string_substring_index.sql +++ b/tests/suites/0_stateless/02_function/02_0026_function_string_substring_index.sql @@ -35,4 +35,3 @@ SELECT SUBSTRING_INDEX(number + 10, number, 1) FROM numbers(5) ORDER BY number; SELECT '=== series, series, series ==='; SELECT SUBSTRING_INDEX(number + 10, number, number) FROM numbers(5) ORDER BY number; -