jonahgao commented on code in PR #13741:
URL: https://github.com/apache/datafusion/pull/13741#discussion_r1885119711


##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -453,6 +455,26 @@ impl ExprSchemable for Expr {
                 }
                 _ => Ok(Expr::Cast(Cast::new(Box::new(self), 
cast_to_type.clone()))),
             }
+        } else if matches!(
+            (&this_type, cast_to_type),
+            (DataType::Int32 | DataType::Int64, DataType::Interval(_))
+        ) {
+            // Convert integer (days) to the corresponding DayTime interval
+            match self {
+                Expr::Literal(ScalarValue::Int32(Some(days))) => {
+                    Ok(Expr::Literal(ScalarValue::IntervalDayTime(Some(
+                        arrow_buffer::IntervalDayTime::new(days, 0),
+                    ))))
+                }
+                Expr::Literal(ScalarValue::Int64(Some(days))) => {
+                    Ok(Expr::Literal(ScalarValue::IntervalDayTime(Some(
+                        arrow_buffer::IntervalDayTime::new(days as i32, 0),
+                    ))))
+                }
+                _ => plan_err!(
+                    "Cannot automatically convert {this_type:?} to 
{cast_to_type:?}"
+                ),
+            }

Review Comment:
   Perhaps we require a new scalar function, `make_interval`, which can convert 
integers into intervals.
   Then, similar to 
[`make_array`](https://github.com/apache/datafusion/blob/bfabd48de2e0deccbd8ce595936ad24f18baca65/datafusion/functions-nested/src/planner.rs#L101),
  perform transformations within the SQL planner. 
   Transform `4 + to_date('1970-01-03')` to `make_interval(4) + 
to_date('1970-01-03')` inside `plan_binary_op`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to