File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
datafusion/physical-expr/src/coercion_rule Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff 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.
596616fn null_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Option < DataType > {
You can’t perform that action at this time.
0 commit comments