Skip to content

Commit

Permalink
feat: Add Utf8 coercion for intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Nov 29, 2023
1 parent 3fb79c3 commit 5833202
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
12 changes: 12 additions & 0 deletions datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ impl ScalarValue {
| ScalarValue::TimestampMicrosecond(None, _)
| ScalarValue::TimestampNanosecond(None, _)
| ScalarValue::Struct(None, _)
| ScalarValue::IntervalDayTime(None)
| ScalarValue::IntervalYearMonth(None)
| ScalarValue::IntervalMonthDayNano(None)
| ScalarValue::Decimal128(None, _, _) // For decimal type, the value is null means ScalarValue::Decimal128 is null.
)
}
Expand Down Expand Up @@ -1740,6 +1743,15 @@ impl TryFrom<&DataType> for ScalarValue {
DataType::Struct(fields) => {
ScalarValue::Struct(None, Box::new(fields.clone()))
}
DataType::Interval(IntervalUnit::DayTime) => {
ScalarValue::IntervalDayTime(None)
}
DataType::Interval(IntervalUnit::YearMonth) => {
ScalarValue::IntervalYearMonth(None)
}
DataType::Interval(IntervalUnit::MonthDayNano) => {
ScalarValue::IntervalMonthDayNano(None)
}
_ => {
return Err(DataFusionError::NotImplemented(format!(
"Can't create a scalar from data_type \"{:?}\"",
Expand Down
42 changes: 18 additions & 24 deletions datafusion/physical-expr/src/coercion_rule/binary_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,30 +605,24 @@ pub fn interval_coercion(
_ => None,
},
Operator::Multiply => match (lhs_type, rhs_type) {
(Int64, Interval(itype)) | (Interval(itype), Int64) => {
Some(Interval(itype.clone()))
}
(Int32, Interval(itype)) | (Interval(itype), Int32) => {
Some(Interval(itype.clone()))
}
(Int16, Interval(itype)) | (Interval(itype), Int16) => {
Some(Interval(itype.clone()))
}
(Int8, Interval(itype)) | (Interval(itype), Int8) => {
Some(Interval(itype.clone()))
}
(UInt64, Interval(itype)) | (Interval(itype), UInt64) => {
Some(Interval(itype.clone()))
}
(UInt32, Interval(itype)) | (Interval(itype), UInt32) => {
Some(Interval(itype.clone()))
}
(UInt16, Interval(itype)) | (Interval(itype), UInt16) => {
Some(Interval(itype.clone()))
}
(UInt8, Interval(itype)) | (Interval(itype), UInt8) => {
Some(Interval(itype.clone()))
}
(Utf8, Interval(itype))
| (Interval(itype), Utf8)
| (Int64, Interval(itype))
| (Interval(itype), Int64)
| (Int32, Interval(itype))
| (Interval(itype), Int32)
| (Int16, Interval(itype))
| (Interval(itype), Int16)
| (Int8, Interval(itype))
| (Interval(itype), Int8)
| (UInt64, Interval(itype))
| (Interval(itype), UInt64)
| (UInt32, Interval(itype))
| (Interval(itype), UInt32)
| (UInt16, Interval(itype))
| (Interval(itype), UInt16)
| (UInt8, Interval(itype))
| (Interval(itype), UInt8) => Some(Interval(itype.clone())),
_ => None,
},
_ => None,
Expand Down

0 comments on commit 5833202

Please sign in to comment.