Skip to content

Commit 5833202

Browse files
committed
feat: Add Utf8 coercion for intervals
1 parent 3fb79c3 commit 5833202

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

datafusion/common/src/scalar.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ impl ScalarValue {
644644
| ScalarValue::TimestampMicrosecond(None, _)
645645
| ScalarValue::TimestampNanosecond(None, _)
646646
| ScalarValue::Struct(None, _)
647+
| ScalarValue::IntervalDayTime(None)
648+
| ScalarValue::IntervalYearMonth(None)
649+
| ScalarValue::IntervalMonthDayNano(None)
647650
| ScalarValue::Decimal128(None, _, _) // For decimal type, the value is null means ScalarValue::Decimal128 is null.
648651
)
649652
}
@@ -1740,6 +1743,15 @@ impl TryFrom<&DataType> for ScalarValue {
17401743
DataType::Struct(fields) => {
17411744
ScalarValue::Struct(None, Box::new(fields.clone()))
17421745
}
1746+
DataType::Interval(IntervalUnit::DayTime) => {
1747+
ScalarValue::IntervalDayTime(None)
1748+
}
1749+
DataType::Interval(IntervalUnit::YearMonth) => {
1750+
ScalarValue::IntervalYearMonth(None)
1751+
}
1752+
DataType::Interval(IntervalUnit::MonthDayNano) => {
1753+
ScalarValue::IntervalMonthDayNano(None)
1754+
}
17431755
_ => {
17441756
return Err(DataFusionError::NotImplemented(format!(
17451757
"Can't create a scalar from data_type \"{:?}\"",

datafusion/physical-expr/src/coercion_rule/binary_rule.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -605,30 +605,24 @@ pub fn interval_coercion(
605605
_ => None,
606606
},
607607
Operator::Multiply => match (lhs_type, rhs_type) {
608-
(Int64, Interval(itype)) | (Interval(itype), Int64) => {
609-
Some(Interval(itype.clone()))
610-
}
611-
(Int32, Interval(itype)) | (Interval(itype), Int32) => {
612-
Some(Interval(itype.clone()))
613-
}
614-
(Int16, Interval(itype)) | (Interval(itype), Int16) => {
615-
Some(Interval(itype.clone()))
616-
}
617-
(Int8, Interval(itype)) | (Interval(itype), Int8) => {
618-
Some(Interval(itype.clone()))
619-
}
620-
(UInt64, Interval(itype)) | (Interval(itype), UInt64) => {
621-
Some(Interval(itype.clone()))
622-
}
623-
(UInt32, Interval(itype)) | (Interval(itype), UInt32) => {
624-
Some(Interval(itype.clone()))
625-
}
626-
(UInt16, Interval(itype)) | (Interval(itype), UInt16) => {
627-
Some(Interval(itype.clone()))
628-
}
629-
(UInt8, Interval(itype)) | (Interval(itype), UInt8) => {
630-
Some(Interval(itype.clone()))
631-
}
608+
(Utf8, Interval(itype))
609+
| (Interval(itype), Utf8)
610+
| (Int64, Interval(itype))
611+
| (Interval(itype), Int64)
612+
| (Int32, Interval(itype))
613+
| (Interval(itype), Int32)
614+
| (Int16, Interval(itype))
615+
| (Interval(itype), Int16)
616+
| (Int8, Interval(itype))
617+
| (Interval(itype), Int8)
618+
| (UInt64, Interval(itype))
619+
| (Interval(itype), UInt64)
620+
| (UInt32, Interval(itype))
621+
| (Interval(itype), UInt32)
622+
| (UInt16, Interval(itype))
623+
| (Interval(itype), UInt16)
624+
| (UInt8, Interval(itype))
625+
| (Interval(itype), UInt8) => Some(Interval(itype.clone())),
632626
_ => None,
633627
},
634628
_ => None,

0 commit comments

Comments
 (0)