Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rust/datafusion/src/logicalplan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

silly question, but are we excluding UInt16 here because it could overflow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my understanding, yes.

_ => 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 {
Expand Down
14 changes: 14 additions & 0 deletions rust/datafusion/src/optimizer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down