Skip to content
Closed
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
16 changes: 13 additions & 3 deletions native/spark-expr/src/conversion_funcs/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fn can_cast_from_boolean(to_type: &DataType, _: &SparkCastOptions) -> bool {
use DataType::*;
matches!(
to_type,
Int8 | Int16 | Int32 | Int64 | Float32 | Float64 | Decimal128(_, _)
Int8 | Int16 | Int32 | Int64 | Float32 | Float64 | Decimal128(_, _) | Utf8
)
}

Expand Down Expand Up @@ -3117,14 +3117,13 @@ fn trim_end(s: &str) -> &str {

#[cfg(test)]
mod tests {
use super::*;
use arrow::array::StringArray;
use arrow::datatypes::TimestampMicrosecondType;
use arrow::datatypes::{Field, Fields, TimeUnit};
use core::f64;
use std::str::FromStr;

use super::*;

/// Test helper that wraps the mode-specific parse functions
fn cast_string_to_i8(str: &str, eval_mode: EvalMode) -> SparkResult<Option<i8>> {
match eval_mode {
Expand Down Expand Up @@ -3745,4 +3744,15 @@ mod tests {
assert_eq!(r#"[null]"#, string_array.value(2));
assert_eq!(r#"[]"#, string_array.value(3));
}

#[test]
fn test_cast_supported_boolean_to_string() {
let options = SparkCastOptions::new(EvalMode::Legacy, "UTC", false);
let is_cast_supported = is_datafusion_spark_compatible(&DataType::Boolean, &DataType::Utf8);
assert!(is_cast_supported);
assert_eq!(
cast_supported(&DataType::Boolean, &DataType::Utf8, &options),
is_cast_supported
);
}
}