Skip to content

Commit 1614a70

Browse files
author
Bhargava Vadlamani
committed
decimal_types_bool_cast_native_support
1 parent e49fe1a commit 1614a70

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

  • native/spark-expr/src/conversion_funcs

native/spark-expr/src/conversion_funcs/cast.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ fn cast_array(
10151015
{
10161016
spark_cast_nonintegral_numeric_to_integral(&array, eval_mode, from_type, to_type)
10171017
}
1018-
(Decimal128(_p, _s), Boolean) => spark_cast_decimal_to_boolean(&array, from_type, to_type),
1018+
(Decimal128(_p, _s), Boolean) => spark_cast_decimal_to_boolean(&array),
10191019
(Utf8View, Utf8) => Ok(cast_with_options(&array, to_type, &CAST_OPTIONS)?),
10201020
(Struct(_), Utf8) => Ok(casts_struct_to_string(array.as_struct(), cast_options)?),
10211021
(Struct(_), Struct(_)) => Ok(cast_struct_to_struct(
@@ -1529,29 +1529,19 @@ where
15291529
Ok(Arc::new(output_array))
15301530
}
15311531

1532-
fn spark_cast_decimal_to_boolean(
1533-
array: &dyn Array,
1534-
from_type: &DataType,
1535-
to_type: &DataType,
1536-
) -> SparkResult<ArrayRef> {
1537-
match (from_type, to_type) {
1538-
(DataType::Decimal128(_p, _s), DataType::Boolean) => {
1539-
let decimal_array = array.as_primitive::<Decimal128Type>();
1540-
let mut result = BooleanBuilder::with_capacity(decimal_array.len());
1541-
for i in 0..decimal_array.len() {
1542-
if decimal_array.is_null(i) {
1543-
result.append_null()
1544-
} else if decimal_array.value(i).is_zero() {
1545-
result.append_value(false);
1546-
} else {
1547-
result.append_value(true);
1548-
}
1549-
}
1550-
Ok(Arc::new(result.finish()))
1532+
fn spark_cast_decimal_to_boolean(array: &dyn Array) -> SparkResult<ArrayRef> {
1533+
let decimal_array = array.as_primitive::<Decimal128Type>();
1534+
let mut result = BooleanBuilder::with_capacity(decimal_array.len());
1535+
for i in 0..decimal_array.len() {
1536+
if decimal_array.is_null(i) {
1537+
result.append_null()
1538+
} else {
1539+
result.append_value(!decimal_array.value(i).is_zero());
15511540
}
1552-
_ => panic!("invalid cast from decimal type: {from_type} to boolean type: {to_type}"),
15531541
}
1542+
Ok(Arc::new(result.finish()))
15541543
}
1544+
15551545
fn spark_cast_nonintegral_numeric_to_integral(
15561546
array: &dyn Array,
15571547
eval_mode: EvalMode,

0 commit comments

Comments
 (0)