Skip to content

Commit cc67c13

Browse files
bert-beyondloopsBert Vermeiren
andauthored
Fix: allow coercion from Binary and LargeBinary into BinaryView (#21800)
## Which issue does this PR close? - Closes #21798 ## Rationale for this change The coercion should take place in the same way as is foreseen already for the string datatypes (Utf8, LargeUtf8, Null -> Utf8View) ## What changes are included in this PR? The coerced_from function in datafusion/expr/src/type_coercion/functions.rs was missing a match arm for (BinaryView, Binary | LargeBinary | Null). ## Are these changes tested? Additional unit test written : `test_binary_conversion` ## Are there any user-facing changes? No Co-authored-by: Bert Vermeiren <bert.vermeiren@datadobi.com>
1 parent 14c18ec commit cc67c13

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

datafusion/expr/src/type_coercion/functions.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ fn coerced_from<'a>(
888888
(Utf8View, Utf8 | LargeUtf8 | Null) => Some(type_into.clone()),
889889
// Any type can be coerced into strings
890890
(Utf8 | LargeUtf8, _) => Some(type_into.clone()),
891+
// We can go into a BinaryView from a Binary or LargeBinary
892+
(BinaryView, Binary | LargeBinary | Null) => Some(type_into.clone()),
891893
(Null, _) if can_cast_types(type_from, type_into) => Some(type_into.clone()),
892894

893895
(List(_), FixedSizeList(_, _)) => Some(type_into.clone()),
@@ -956,6 +958,20 @@ mod tests {
956958
let cases = vec![
957959
(DataType::Utf8View, DataType::Utf8),
958960
(DataType::Utf8View, DataType::LargeUtf8),
961+
(DataType::Utf8View, DataType::Null),
962+
];
963+
964+
for case in cases {
965+
assert_eq!(coerced_from(&case.0, &case.1), Some(case.0));
966+
}
967+
}
968+
969+
#[test]
970+
fn test_binary_conversion() {
971+
let cases = vec![
972+
(DataType::BinaryView, DataType::Binary),
973+
(DataType::BinaryView, DataType::LargeBinary),
974+
(DataType::BinaryView, DataType::Null),
959975
];
960976

961977
for case in cases {

0 commit comments

Comments
 (0)