Skip to content

Commit

Permalink
fix: using native array iter
Browse files Browse the repository at this point in the history
  • Loading branch information
ygf11 committed Sep 5, 2021
1 parent 2bc4a8f commit 922c86a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
46 changes: 24 additions & 22 deletions common/functions/src/scalars/dates/number_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,41 @@ where T: NumberResultFunction + Clone + Sync + Send + 'static
}

let data_type = columns[0].data_type();
let number_vec = match data_type {
DataType::Date16 | DataType::Date32 => {
let number_vec_result: Vec<Option<u32>> = columns[0]
.column()
.to_values()?
.iter()
.map(|value| match value {
DataValue::UInt16(Some(v)) => {
let number_vec: Vec<Option<u32>> = match data_type {
DataType::Date16 => {
let number_vec_result = columns[0].column().to_array()?.u16()?.iter().map(|value|{
match value {
Some(v) => {
let date_time = Utc.timestamp(*v as i64 * 24 * 3600, 0_u32);
Some(T::execute(date_time))
}
DataValue::UInt32(Some(v)) => {
},
None => None,
}
}).collect();
Ok(number_vec_result)
},
DataType::Date32 => {
let number_vec_result = columns[0].column().to_array()?.u32()?.iter().map(|value|{
match value {
Some(v) => {
let date_time = Utc.timestamp(*v as i64 * 24 * 3600, 0_u32);
Some(T::execute(date_time))
}
_ => None,
})
.collect();
},
None => None,
}
}).collect();
Ok(number_vec_result)
},
DataType::DateTime32 => {
let number_vec_result: Vec<Option<u32>> = columns[0].column().to_values()?
.iter()
.map(|value| {
match value {
DataValue::UInt32(Some(v)) => {
let number_vec_result = columns[0].column().to_array()?.u32()?.iter().map(|value|{
match value {
Some(v) => {
let date_time = Utc.timestamp(*v as i64, 0_u32);
Some(T::execute(date_time))
},
_ => None,
None => None,
}
}).collect();

}).collect();
Ok(number_vec_result)
},
other => Result::Err(ErrorCode::IllegalDataType(format!(
Expand Down
5 changes: 2 additions & 3 deletions tests/suites/0_stateless/02_0012_function_datetimes.result
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ true
true
true
true
202108
true
true
202109
202109
true
true
10 changes: 5 additions & 5 deletions tests/suites/0_stateless/02_0012_function_datetimes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ select today() - yesterday() = 1;
select today() + 1 = tomorrow();
select tomorrow() - today() = 1;

select toYYYYMM(toDateTime(1630320462));
select toYYYYMM(today() - 31) = toYYYYMM(today()) - 1;
select toYYYYMM(today() + 31) = toYYYYMM(today()) + 1;
select toYYYYMM(today()) - toYYYYMM(today() - 31) = 1;
select toYYYYMM(today() + 31) - toYYYYMM(today()) = 1;
select toYYYYMM(toDateTime(1630833797));
select toYYYYMM(toDate(18875));
select toYYYYMM(toDateTime(1630833797)) = 202109;
select toYYYYMM(toDate(18875) ) = 202109;

0 comments on commit 922c86a

Please sign in to comment.