Skip to content

Commit a809c5e

Browse files
committed
fix: Allow Date32 - Date32 expression (stub)
1 parent d5609f5 commit a809c5e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub(crate) fn coerce_types(
5656
Operator::Plus | Operator::Minus => {
5757
mathematics_numerical_coercion(op, lhs_type, rhs_type)
5858
.or_else(|| interval_coercion(op, lhs_type, rhs_type))
59+
.or_else(|| date_coercion(op, lhs_type, rhs_type))
5960
}
6061
// Same as Plus & Minus
6162
Operator::Modulo | Operator::Divide | Operator::Multiply => {
@@ -591,6 +592,25 @@ pub fn interval_coercion(
591592
}
592593
}
593594

595+
/// Coercion rule for dates
596+
pub fn date_coercion(
597+
op: &Operator,
598+
lhs_type: &DataType,
599+
rhs_type: &DataType,
600+
) -> Option<DataType> {
601+
use arrow::datatypes::DataType::*;
602+
603+
// these are ordered from most informative to least informative so
604+
// that the coercion removes the least amount of information
605+
match op {
606+
Operator::Minus => match (lhs_type, rhs_type) {
607+
(Date32, Date32) => Some(Int32),
608+
_ => None,
609+
},
610+
_ => None,
611+
}
612+
}
613+
594614
/// coercion rules from NULL type. Since NULL can be casted to most of types in arrow,
595615
/// either lhs or rhs is NULL, if NULL can be casted to type of the other side, the coecion is valid.
596616
fn null_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {

0 commit comments

Comments
 (0)