Skip to content

Commit

Permalink
OR nullable-s
Browse files Browse the repository at this point in the history
  • Loading branch information
blaginin committed Nov 17, 2024
1 parent baf99cb commit 639f236
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions datafusion/expr-common/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,9 +1139,15 @@ fn numeric_string_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
}

fn coerce_list_children(lhs_field: &FieldRef, rhs_field: &FieldRef) -> Option<FieldRef> {
Some(Arc::new((**lhs_field).clone().with_data_type(
comparison_coercion(lhs_field.data_type(), rhs_field.data_type())?,
)))
Some(Arc::new(
(**lhs_field)
.clone()
.with_data_type(comparison_coercion(
lhs_field.data_type(),
rhs_field.data_type(),
)?)
.with_nullable(lhs_field.is_nullable() || rhs_field.is_nullable()),
))
}

/// Coercion rules for list types.
Expand All @@ -1152,7 +1158,7 @@ fn list_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
LargeList(lhs_field),
List(rhs_field) | LargeList(rhs_field) | FixedSizeList(rhs_field, _),
)
| (FixedSizeList(lhs_field, _) | List(lhs_field), LargeList(rhs_field)) => {
| (List(lhs_field) | FixedSizeList(lhs_field, _), LargeList(rhs_field)) => {
Some(LargeList(coerce_list_children(lhs_field, rhs_field)?))
}

Expand Down Expand Up @@ -2136,6 +2142,19 @@ mod tests {
Ok(())
}

#[test]
fn test_list_coercion() {
let lhs_type = DataType::List(Arc::new(Field::new("lhs", DataType::Int8, false)));

let rhs_type = DataType::List(Arc::new(Field::new("rhs", DataType::Int64, true)));

let coerced_type = list_coercion(&lhs_type, &rhs_type).unwrap();
assert_eq!(
coerced_type,
DataType::List(Arc::new(Field::new("lhs", DataType::Int64, true)))
); // nullable because the RHS is nullable
}

#[test]
fn test_type_coercion_logical_op() -> Result<()> {
test_coercion_binary_rule!(
Expand Down

0 comments on commit 639f236

Please sign in to comment.