Skip to content

Commit

Permalink
Minor: Extend ScalarValue::new_zero() (#13828)
Browse files Browse the repository at this point in the history
* Update mod.rs

* Update mod.rs

* Update mod.rs

* Update mod.rs
  • Loading branch information
berkaysynnada authored Dec 18, 2024
1 parent 01ffb64 commit c2b6035
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ impl ScalarValue {
DataType::Float16 => ScalarValue::Float16(Some(f16::from_f32(0.0))),
DataType::Float32 => ScalarValue::Float32(Some(0.0)),
DataType::Float64 => ScalarValue::Float64(Some(0.0)),
DataType::Decimal128(precision, scale) => {
ScalarValue::Decimal128(Some(0), *precision, *scale)
}
DataType::Decimal256(precision, scale) => {
ScalarValue::Decimal256(Some(i256::ZERO), *precision, *scale)
}
DataType::Timestamp(TimeUnit::Second, tz) => {
ScalarValue::TimestampSecond(Some(0), tz.clone())
}
Expand All @@ -1162,6 +1168,16 @@ impl ScalarValue {
DataType::Timestamp(TimeUnit::Nanosecond, tz) => {
ScalarValue::TimestampNanosecond(Some(0), tz.clone())
}
DataType::Time32(TimeUnit::Second) => ScalarValue::Time32Second(Some(0)),
DataType::Time32(TimeUnit::Millisecond) => {
ScalarValue::Time32Millisecond(Some(0))
}
DataType::Time64(TimeUnit::Microsecond) => {
ScalarValue::Time64Microsecond(Some(0))
}
DataType::Time64(TimeUnit::Nanosecond) => {
ScalarValue::Time64Nanosecond(Some(0))
}
DataType::Interval(IntervalUnit::YearMonth) => {
ScalarValue::IntervalYearMonth(Some(0))
}
Expand All @@ -1181,6 +1197,8 @@ impl ScalarValue {
DataType::Duration(TimeUnit::Nanosecond) => {
ScalarValue::DurationNanosecond(Some(0))
}
DataType::Date32 => ScalarValue::Date32(Some(0)),
DataType::Date64 => ScalarValue::Date64(Some(0)),
_ => {
return _not_impl_err!(
"Can't create a zero scalar from data_type \"{datatype:?}\""
Expand Down

0 comments on commit c2b6035

Please sign in to comment.