Skip to content

Commit

Permalink
add check and change convert to column method
Browse files Browse the repository at this point in the history
  • Loading branch information
fkuner committed May 17, 2022
1 parent a5a905c commit 5e7071e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions common/functions/src/scalars/dates/to_interval_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ use std::fmt;
use common_datavalues::prelude::*;
use common_datavalues::IntervalKind;
use common_datavalues::IntervalType;
use common_exception::ErrorCode;
use common_exception::Result;

use crate::scalars::default_column_cast;
use crate::scalars::FactoryCreator;
use crate::scalars::Function;
use crate::scalars::FunctionContext;
Expand All @@ -35,8 +37,15 @@ impl ToIntervalFunction {
pub fn try_create(
display_name: String,
interval_kind: IntervalKind,
_args: &[&DataTypeImpl],
args: &[&DataTypeImpl],
) -> Result<Box<dyn Function>> {
if !args[0].data_type_id().is_numeric() {
return Err(ErrorCode::BadDataValueType(format!(
"DataValue Error: Unsupported type {:?}",
args[0].data_type_id()
)));
}

Ok(Box::new(ToIntervalFunction {
display_name,
interval_kind,
Expand All @@ -59,7 +68,7 @@ impl Function for ToIntervalFunction {
columns: &ColumnsWithField,
_input_rows: usize,
) -> Result<ColumnRef> {
IntervalType::new_impl(self.interval_kind).create_column(&columns[0].column().to_values())
default_column_cast(columns[0].column(), &i64::to_data_type())
}
}

Expand Down

0 comments on commit 5e7071e

Please sign in to comment.