Skip to content

Apache DataFusion SQL Query Engine

ARROW-6372: [Rust][Datafusion] Casting from Un-signed to Signed Integers not supported

Paddy Horan9f518ec52d9f
diff --git a/rust/datafusion/src/logicalplan.rs b/rust/datafusion/src/logicalplan.rs
index cc2414909e..3fa9f980b8 100644
--- a/rust/datafusion/src/logicalplan.rs
+++ b/rust/datafusion/src/logicalplan.rs
@@ -571,15 +571,15 @@ pub fn can_coerce_from(type_into: &DataType, type_from: &DataType) -> bool {
_ => false,
},
Int16 => match type_from {
- Int8 | Int16 => true,
+ Int8 | Int16 | UInt8 => true,
_ => false,
},
Int32 => match type_from {
- Int8 | Int16 | Int32 => true,
+ Int8 | Int16 | Int32 | UInt8 | UInt16 => true,
_ => false,
},
Int64 => match type_from {
- Int8 | Int16 | Int32 | Int64 => true,
+ Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 => true,
_ => false,
},
UInt8 => match type_from {
diff --git a/rust/datafusion/src/optimizer/type_coercion.rs b/rust/datafusion/src/optimizer/type_coercion.rs
index d07f42aa4f..bfd63b4d5e 100644
--- a/rust/datafusion/src/optimizer/type_coercion.rs
+++ b/rust/datafusion/src/optimizer/type_coercion.rs
@@ -198,6 +198,20 @@ mod tests {
);
}
+ #[test]
+ fn test_add_u32_i64() {
+ binary_cast_test(
+ DataType::UInt32,
+ DataType::Int64,
+ "CAST(#0 AS Int64) Plus #1",
+ );
+ binary_cast_test(
+ DataType::Int64,
+ DataType::UInt32,
+ "#0 Plus CAST(#1 AS Int64)",
+ );
+ }
+
fn binary_cast_test(left_type: DataType, right_type: DataType, expected: &str) {
let schema = Schema::new(vec![
Field::new("c0", left_type, true),