Skip to content

Commit 1b3fc4f

Browse files
committed
feat: Support planning Interval as DatePart input
1 parent 493ce35 commit 1b3fc4f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

datafusion/core/src/physical_plan/functions.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@ pub fn return_type(
120120
}
121121
BuiltinScalarFunction::Concat => Ok(DataType::Utf8),
122122
BuiltinScalarFunction::ConcatWithSeparator => Ok(DataType::Utf8),
123-
BuiltinScalarFunction::DatePart => Ok(DataType::Int32),
123+
BuiltinScalarFunction::DatePart => {
124+
match &input_expr_types[1] {
125+
// FIXME: DatePart should *always* return a numeric but this might break things
126+
// so since interval wasn't supported in the first place, this is safe
127+
DataType::Interval(_) => Ok(DataType::Float64),
128+
_ => Ok(DataType::Int32),
129+
}
130+
}
124131
BuiltinScalarFunction::DateTrunc => {
125132
Ok(DataType::Timestamp(TimeUnit::Nanosecond, None))
126133
}
@@ -540,6 +547,10 @@ fn signature(fun: &BuiltinScalarFunction) -> Signature {
540547
DataType::Utf8,
541548
DataType::Timestamp(TimeUnit::Nanosecond, None),
542549
]),
550+
TypeSignature::Exact(vec![
551+
DataType::Utf8,
552+
DataType::Interval(IntervalUnit::MonthDayNano),
553+
]),
543554
],
544555
fun.volatility(),
545556
),

0 commit comments

Comments
 (0)