Skip to content

Apache DataFusion SQL Query Engine

Support type coercion for timestamp and utf8 (#4312)

André Calado Coroado8547fd8a562e
diff --git a/datafusion/expr/src/type_coercion/binary.rs b/datafusion/expr/src/type_coercion/binary.rs
index 6ca0c4e044..18ea51d0df 100644
--- a/datafusion/expr/src/type_coercion/binary.rs
+++ b/datafusion/expr/src/type_coercion/binary.rs
@@ -561,6 +561,8 @@ fn temporal_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataTyp
false => None,
true => Some(Time64(unit.clone())),
},
+ (Timestamp(_, tz), Utf8) => Some(Timestamp(TimeUnit::Nanosecond, tz.clone())),
+ (Utf8, Timestamp(_, tz)) => Some(Timestamp(TimeUnit::Nanosecond, tz.clone())),
(Timestamp(lhs_unit, lhs_tz), Timestamp(rhs_unit, rhs_tz)) => {
let tz = match (lhs_tz, rhs_tz) {
// can't cast across timezones
@@ -886,6 +888,30 @@ mod tests {
Operator::Eq,
DataType::Time64(TimeUnit::Nanosecond)
);
+ test_coercion_binary_rule!(
+ DataType::Utf8,
+ DataType::Timestamp(TimeUnit::Second, None),
+ Operator::Lt,
+ DataType::Timestamp(TimeUnit::Nanosecond, None)
+ );
+ test_coercion_binary_rule!(
+ DataType::Utf8,
+ DataType::Timestamp(TimeUnit::Millisecond, None),
+ Operator::Lt,
+ DataType::Timestamp(TimeUnit::Nanosecond, None)
+ );
+ test_coercion_binary_rule!(
+ DataType::Utf8,
+ DataType::Timestamp(TimeUnit::Microsecond, None),
+ Operator::Lt,
+ DataType::Timestamp(TimeUnit::Nanosecond, None)
+ );
+ test_coercion_binary_rule!(
+ DataType::Utf8,
+ DataType::Timestamp(TimeUnit::Nanosecond, None),
+ Operator::Lt,
+ DataType::Timestamp(TimeUnit::Nanosecond, None)
+ );
test_coercion_binary_rule!(
DataType::Utf8,
DataType::Utf8,