Skip to content

Commit

Permalink
refactor function return type
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyass committed Apr 13, 2022
1 parent 5699eca commit dcfa039
Show file tree
Hide file tree
Showing 81 changed files with 177 additions and 198 deletions.
4 changes: 2 additions & 2 deletions common/functions/src/scalars/arithmetics/arithmetic_modulo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,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
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
4 changes: 2 additions & 2 deletions common/functions/src/scalars/comparisons/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions common/functions/src/scalars/conditionals/if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ impl Function for IfFunction {
"IfFunction"
}

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

fn eval(
Expand Down
6 changes: 3 additions & 3 deletions common/functions/src/scalars/conditionals/in_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ impl<const NEGATED: bool> Function for InFunction<NEGATED> {
"InFunction"
}

fn return_type(&self, _args: &[&DataTypePtr]) -> Result<DataTypePtr> {
fn return_type(&self) -> DataTypePtr {
if self.is_null {
return Ok(NullType::arc());
return NullType::arc();
}
Ok(BooleanType::arc())
BooleanType::arc()
}

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/conditionals/is_not_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl Function for IsNotNullFunction {
"IsNotNullFunction"
}

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

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/conditionals/is_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl Function for IsNullFunction {
"IsNullFunction"
}

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

fn eval(
Expand Down
8 changes: 3 additions & 5 deletions common/functions/src/scalars/contexts/current_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::fmt;

use common_datavalues::DataTypePtr;
use common_datavalues::StringType;
use common_exception::Result;

Expand Down Expand Up @@ -47,11 +48,8 @@ impl Function for CurrentUserFunction {
"CurrentUserFunction"
}

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

fn eval(
Expand Down
8 changes: 3 additions & 5 deletions common/functions/src/scalars/contexts/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::fmt;

use common_datavalues::DataTypePtr;
use common_datavalues::StringType;
use common_exception::Result;

Expand Down Expand Up @@ -48,11 +49,8 @@ impl Function for DatabaseFunction {
"DatabaseFunction"
}

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

fn eval(
Expand Down
8 changes: 3 additions & 5 deletions common/functions/src/scalars/contexts/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::fmt;

use common_datavalues::DataTypePtr;
use common_datavalues::StringType;
use common_exception::Result;

Expand Down Expand Up @@ -51,11 +52,8 @@ impl Function for VersionFunction {
"VersionFunction"
}

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

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/dates/interval_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ where
self.display_name.as_str()
}

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/dates/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl Function for NowFunction {
self.display_name.as_str()
}

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

fn eval(
Expand Down
6 changes: 3 additions & 3 deletions common/functions/src/scalars/dates/number_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ where
self.display_name.as_str()
}

fn return_type(&self, _args: &[&DataTypePtr]) -> Result<DataTypePtr> {
fn return_type(&self) -> DataTypePtr {
match T::return_type() {
None => Ok(R::to_data_type()),
Some(v) => Ok(v),
None => R::to_data_type(),
Some(v) => v,
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/dates/round_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl Function for RoundFunction {
self.display_name.as_str()
}

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

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/dates/simple_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ where T: NoArgDateFunction + Clone + Sync + Send + 'static
self.display_name.as_str()
}

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

fn eval(
Expand Down
8 changes: 4 additions & 4 deletions common/functions/src/scalars/dates/week_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct WeekFunction<T, R> {
pub trait WeekResultFunction<R> {
const IS_DETERMINISTIC: bool;

fn return_type() -> Result<DataTypePtr>;
fn return_type() -> DataTypePtr;
fn to_number(_value: DateTime<Utc>, mode: u64) -> R;
fn factor_function() -> Option<Box<dyn Function>> {
None
Expand All @@ -57,8 +57,8 @@ pub struct ToStartOfWeek;
impl WeekResultFunction<u32> for ToStartOfWeek {
const IS_DETERMINISTIC: bool = true;

fn return_type() -> Result<DataTypePtr> {
Ok(Date16Type::arc())
fn return_type() -> DataTypePtr {
Date16Type::arc()
}
fn to_number(value: DateTime<Utc>, week_mode: u64) -> u32 {
let mut weekday = value.weekday().number_from_sunday();
Expand Down Expand Up @@ -118,7 +118,7 @@ where
self.display_name.as_str()
}

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

Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/expressions/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl Function for CastFunction {
"CastFunction"
}

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

fn eval(
Expand Down
2 changes: 1 addition & 1 deletion common/functions/src/scalars/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait Function: fmt::Display + Sync + Send + DynClone {
}

/// The method returns the return_type of this function.
fn return_type(&self, args: &[&DataTypePtr]) -> Result<DataTypePtr>;
fn return_type(&self) -> DataTypePtr;

/// Evaluate the function, e.g. run/execute the function.
fn eval(
Expand Down
13 changes: 6 additions & 7 deletions common/functions/src/scalars/function_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ impl Function for FunctionAdapter {
self.inner.as_ref().map_or("null", |v| v.name())
}

fn return_type(&self, args: &[&DataTypePtr]) -> Result<DataTypePtr> {
fn return_type(&self) -> DataTypePtr {
if self.inner.is_none() {
return Ok(NullType::arc());
return NullType::arc();
}

let inner = self.inner.as_ref().unwrap();
let typ = inner.return_type(args)?;
let typ = inner.return_type();

if self.has_nullable {
Ok(wrap_nullable(&typ))
wrap_nullable(&typ)
} else {
Ok(typ)
typ
}
}

Expand Down Expand Up @@ -146,8 +146,7 @@ impl Function for FunctionAdapter {
let (is_all_null, valid) = v.column().validity();
if is_all_null {
// If only null, return null directly.
let args = columns.iter().map(|v| v.data_type()).collect::<Vec<_>>();
let inner_type = remove_nullable(&inner.return_type(args.as_slice())?);
let inner_type = remove_nullable(&inner.return_type());
return Ok(NullableColumn::wrap_inner(
inner_type
.create_constant_column(&inner_type.default_value(), input_rows)?,
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/hashes/city64_with_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ impl Function for City64WithSeedFunction {
&*self.display_name
}

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

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/hashes/hash_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ where
self.display_name.as_str()
}

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

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/hashes/sha2hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl Function for Sha2HashFunction {
&*self.display_name
}

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

fn eval(
Expand Down
6 changes: 3 additions & 3 deletions common/functions/src/scalars/logics/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ where F: LogicExpression + Clone
"LogicFunction"
}

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

Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/maths/abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ impl Function for AbsFunction {
"abs"
}

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/maths/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ where T: AngleConvertFunction + Clone + Sync + Send + 'static
"AngleFunction"
}

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

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/maths/ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl Function for CeilFunction {
&*self.display_name
}

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

fn eval(
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/maths/exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl Function for ExpFunction {
&*self._display_name
}

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

fn eval(
Expand Down
Loading

0 comments on commit dcfa039

Please sign in to comment.