Skip to content
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

ISSUE-4847: Replace FactoryCreator with FactoryCreatorWithTypes for functions #4688

Merged
merged 15 commits into from
Apr 14, 2022
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
4 changes: 2 additions & 2 deletions common/datavalues/src/columns/nullable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -111,7 +111,7 @@ impl Column for NullableColumn {
}

fn validity(&self) -> (bool, Option<&Bitmap>) {
(false, Some(&self.validity))
(self.only_null(), Some(&self.validity))
}

fn memory_size(&self) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions common/datavalues/src/types/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion common/datavalues/src/types/type_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions common/datavalues/src/types/type_nullable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct NullableType {
}

impl NullableType {
pub fn arc(inner: DataTypePtr) -> DataTypePtr {
Arc::new(Self::create(inner))
}

pub fn create(inner: DataTypePtr) -> Self {
debug_assert!(inner.can_inside_nullable());
NullableType {
Expand Down
4 changes: 1 addition & 3 deletions common/datavalues/tests/it/types/create_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]),
Expand Down
26 changes: 13 additions & 13 deletions common/functions/src/scalars/arithmetics/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ pub struct ArithmeticFunction;

impl ArithmeticFunction {
pub fn register(factory: &mut FunctionFactory) {
factory.register_typed("negate", ArithmeticNegateFunction::desc());
factory.register_typed("+", ArithmeticPlusFunction::desc());
factory.register_typed("plus", ArithmeticPlusFunction::desc());
factory.register_typed("-", ArithmeticMinusFunction::desc());
factory.register_typed("minus", ArithmeticMinusFunction::desc());
factory.register_typed("*", ArithmeticMulFunction::desc());
factory.register_typed("multiply", ArithmeticMulFunction::desc());
factory.register_typed("/", ArithmeticDivFunction::desc());
factory.register_typed("divide", ArithmeticDivFunction::desc());
factory.register_typed("div", ArithmeticIntDivFunction::desc());
factory.register_typed("%", ArithmeticModuloFunction::desc());
factory.register_typed("modulo", ArithmeticModuloFunction::desc());
factory.register_typed("mod", ArithmeticModuloFunction::desc());
factory.register("negate", ArithmeticNegateFunction::desc());
factory.register("+", ArithmeticPlusFunction::desc());
factory.register("plus", ArithmeticPlusFunction::desc());
factory.register("-", ArithmeticMinusFunction::desc());
factory.register("minus", ArithmeticMinusFunction::desc());
factory.register("*", ArithmeticMulFunction::desc());
factory.register("multiply", ArithmeticMulFunction::desc());
factory.register("/", ArithmeticDivFunction::desc());
factory.register("divide", ArithmeticDivFunction::desc());
factory.register("div", ArithmeticIntDivFunction::desc());
factory.register("%", ArithmeticModuloFunction::desc());
factory.register("modulo", ArithmeticModuloFunction::desc());
factory.register("mod", ArithmeticModuloFunction::desc());
}
}
6 changes: 3 additions & 3 deletions common/functions/src/scalars/arithmetics/arithmetic_div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use super::arithmetic_mul::arithmetic_mul_div_monotonicity;
use crate::scalars::BinaryArithmeticFunction;
use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFeatures;
use crate::scalars::Monotonicity;
use crate::scalars::TypedFunctionDescription;

#[inline]
fn div_scalar(l: impl AsPrimitive<f64>, r: impl AsPrimitive<f64>, _ctx: &mut EvalContext) -> f64 {
Expand Down Expand Up @@ -53,8 +53,8 @@ impl ArithmeticDivFunction {
arithmetic_mul_div_monotonicity(args, DataValueBinaryOperator::Div)
}

pub fn desc() -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc() -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.monotonicity()
Expand Down
6 changes: 3 additions & 3 deletions common/functions/src/scalars/arithmetics/arithmetic_intdiv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use num_traits::AsPrimitive;
use crate::scalars::BinaryArithmeticFunction;
use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFeatures;
use crate::scalars::TypedFunctionDescription;

#[inline]
fn intdiv_scalar<O>(l: impl AsPrimitive<f64>, r: impl AsPrimitive<f64>, ctx: &mut EvalContext) -> O
Expand Down Expand Up @@ -58,8 +58,8 @@ impl ArithmeticIntDivFunction {
})
}

pub fn desc() -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc() -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.monotonicity()
Expand Down
6 changes: 3 additions & 3 deletions common/functions/src/scalars/arithmetics/arithmetic_minus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use num_traits::WrappingSub;
use crate::scalars::BinaryArithmeticFunction;
use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFactory;
use crate::scalars::FunctionFeatures;
use crate::scalars::Monotonicity;
use crate::scalars::TypedFunctionDescription;

#[inline]
fn sub_scalar<O>(l: impl AsPrimitive<O>, r: impl AsPrimitive<O>, _ctx: &mut EvalContext) -> O
Expand Down Expand Up @@ -118,8 +118,8 @@ impl ArithmeticMinusFunction {
})
}

pub fn desc() -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc() -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.monotonicity()
Expand Down
12 changes: 6 additions & 6 deletions common/functions/src/scalars/arithmetics/arithmetic_modulo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ 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;
use crate::scalars::TypedFunctionDescription;

pub struct ArithmeticModuloFunction;

Expand All @@ -44,8 +45,8 @@ impl ArithmeticModuloFunction {
})
}

pub fn desc() -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func))
pub fn desc() -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func))
.features(FunctionFeatures::default().deterministic().num_arguments(2))
}
}
Expand Down Expand Up @@ -73,8 +74,8 @@ where
"ModuloFunctionImpl"
}

fn return_type(&self, _args: &[&DataTypePtr]) -> Result<DataTypePtr> {
Ok(O::to_data_type())
fn return_type(&self) -> DataTypePtr {
O::to_data_type()
}

fn eval(
Expand Down Expand Up @@ -160,4 +161,3 @@ where
write!(f, "div")
}
}
use crate::scalars::FunctionContext;
6 changes: 3 additions & 3 deletions common/functions/src/scalars/arithmetics/arithmetic_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use num_traits::WrappingMul;
use crate::scalars::BinaryArithmeticFunction;
use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFeatures;
use crate::scalars::Monotonicity;
use crate::scalars::TypedFunctionDescription;

#[inline]
fn mul_scalar<O>(l: impl AsPrimitive<O>, r: impl AsPrimitive<O>, _ctx: &mut EvalContext) -> O
Expand Down Expand Up @@ -79,8 +79,8 @@ impl ArithmeticMulFunction {
})
}

pub fn desc() -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc() -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.monotonicity()
Expand Down
6 changes: 3 additions & 3 deletions common/functions/src/scalars/arithmetics/arithmetic_negate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use num_traits::WrappingNeg;

use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFeatures;
use crate::scalars::Monotonicity;
use crate::scalars::TypedFunctionDescription;
use crate::scalars::UnaryArithmeticFunction;

fn neg<O>(l: impl AsPrimitive<O>, _ctx: &mut EvalContext) -> O
Expand Down Expand Up @@ -79,8 +79,8 @@ impl ArithmeticNegateFunction {
})
}

pub fn desc() -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc() -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.monotonicity()
Expand Down
6 changes: 3 additions & 3 deletions common/functions/src/scalars/arithmetics/arithmetic_plus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use num_traits::WrappingAdd;
use crate::scalars::BinaryArithmeticFunction;
use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFactory;
use crate::scalars::FunctionFeatures;
use crate::scalars::Monotonicity;
use crate::scalars::TypedFunctionDescription;

#[inline]
fn add_scalar<O>(l: impl AsPrimitive<O>, r: impl AsPrimitive<O>, _ctx: &mut EvalContext) -> O
Expand Down Expand Up @@ -125,8 +125,8 @@ impl ArithmeticPlusFunction {
})
}

pub fn desc() -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc() -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.monotonicity()
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/arithmetics/binary_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ where
"BinaryArithmeticFunction"
}

fn return_type(&self, _args: &[&DataTypePtr]) -> Result<DataTypePtr> {
Ok(self.result_type.clone())
fn return_type(&self) -> DataTypePtr {
self.result_type.clone()
}

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/arithmetics/unary_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ where
"UnaryArithmeticFunction"
}

fn return_type(&self, _args: &[&DataTypePtr]) -> Result<DataTypePtr> {
Ok(self.result_type.clone())
fn return_type(&self) -> DataTypePtr {
self.result_type.clone()
}

fn eval(
Expand Down
40 changes: 20 additions & 20 deletions common/functions/src/scalars/comparisons/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use crate::scalars::ComparisonRegexpFunction;
use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionContext;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFactory;
use crate::scalars::FunctionFeatures;
use crate::scalars::TypedFunctionDescription;

#[derive(Clone)]
pub struct ComparisonFunction {
Expand All @@ -56,19 +56,19 @@ pub struct ComparisonFunction {

impl ComparisonFunction {
pub fn register(factory: &mut FunctionFactory) {
factory.register_typed("=", ComparisonEqFunction::desc("<>"));
factory.register_typed("<", ComparisonLtFunction::desc(">="));
factory.register_typed(">", ComparisonGtFunction::desc("<="));
factory.register_typed("<=", ComparisonLtEqFunction::desc(">"));
factory.register_typed(">=", ComparisonGtEqFunction::desc("<"));
factory.register_typed("!=", ComparisonNotEqFunction::desc("="));
factory.register_typed("<>", ComparisonNotEqFunction::desc("="));
factory.register_typed("like", ComparisonLikeFunction::desc("not like"));
factory.register_typed("not like", ComparisonNotLikeFunction::desc("like"));
factory.register_typed("regexp", ComparisonRegexpFunction::desc("not regexp"));
factory.register_typed("not regexp", ComparisonNotRegexpFunction::desc("regexp"));
factory.register_typed("rlike", ComparisonRegexpFunction::desc("not regexp"));
factory.register_typed("not rlike", ComparisonNotRegexpFunction::desc("regexp"));
factory.register("=", ComparisonEqFunction::desc("<>"));
factory.register("<", ComparisonLtFunction::desc(">="));
factory.register(">", ComparisonGtFunction::desc("<="));
factory.register("<=", ComparisonLtEqFunction::desc(">"));
factory.register(">=", ComparisonGtEqFunction::desc("<"));
factory.register("!=", ComparisonNotEqFunction::desc("="));
factory.register("<>", ComparisonNotEqFunction::desc("="));
factory.register("like", ComparisonLikeFunction::desc("not like"));
factory.register("not like", ComparisonNotLikeFunction::desc("like"));
factory.register("regexp", ComparisonRegexpFunction::desc("not regexp"));
factory.register("not regexp", ComparisonNotRegexpFunction::desc("regexp"));
factory.register("rlike", ComparisonRegexpFunction::desc("not regexp"));
factory.register("not rlike", ComparisonNotRegexpFunction::desc("regexp"));
}

pub fn try_create_func(
Expand All @@ -87,8 +87,8 @@ impl Function for ComparisonFunction {
self.display_name.as_str()
}

fn return_type(&self, _args: &[&DataTypePtr]) -> Result<DataTypePtr> {
Ok(BooleanType::arc())
fn return_type(&self) -> DataTypePtr {
BooleanType::arc()
}

fn eval(
Expand Down Expand Up @@ -167,8 +167,8 @@ impl<T: ComparisonImpl> ComparisonFunctionCreator<T> {
})
}

pub fn desc(negative_name: &str) -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc(negative_name: &str) -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.negative_function(negative_name)
Expand Down Expand Up @@ -197,8 +197,8 @@ impl<const NEGATED: bool, T: StringSearchImpl> StringSearchCreator<NEGATED, T> {
ComparisonFunction::try_create_func(display_name, func)
}

pub fn desc(negative_name: &str) -> TypedFunctionDescription {
TypedFunctionDescription::creator(Box::new(Self::try_create_func)).features(
pub fn desc(negative_name: &str) -> FunctionDescription {
FunctionDescription::creator(Box::new(Self::try_create_func)).features(
FunctionFeatures::default()
.deterministic()
.negative_function(negative_name)
Expand Down
Loading