milevin commented on code in PR #13741: URL: https://github.com/apache/datafusion/pull/13741#discussion_r1881596978
########## 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: What's the alternative? You can't cast an integer to an interval in arrow. You are right; it only works for literals. Do you have thoughts on how to make it work for non also? -- 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