Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BACKPORT: Correct return type for initcap scalar function with utf8view (#13909) #13934

Merged
merged 1 commit into from
Dec 28, 2024
Merged
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
18 changes: 11 additions & 7 deletions datafusion/functions/src/unicode/initcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ impl ScalarUDFImpl for InitcapFunc {
}

fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
utf8_to_str_type(&arg_types[0], "initcap")
if let DataType::Utf8View = arg_types[0] {
Ok(DataType::Utf8View)
} else {
utf8_to_str_type(&arg_types[0], "initcap")
}
}

fn invoke_batch(
Expand Down Expand Up @@ -188,7 +192,7 @@ mod tests {
use crate::unicode::initcap::InitcapFunc;
use crate::utils::test::test_function;
use arrow::array::{Array, StringArray, StringViewArray};
use arrow::datatypes::DataType::Utf8;
use arrow::datatypes::DataType::{Utf8, Utf8View};
use datafusion_common::{Result, ScalarValue};
use datafusion_expr::{ColumnarValue, ScalarUDFImpl};

Expand Down Expand Up @@ -247,7 +251,7 @@ mod tests {
)))],
Ok(Some("Hi Thomas")),
&str,
Utf8,
Utf8View,
StringViewArray
);
test_function!(
Expand All @@ -257,7 +261,7 @@ mod tests {
)))],
Ok(Some("Hi Thomas With M0re Than 12 Chars")),
&str,
Utf8,
Utf8View,
StringViewArray
);
test_function!(
Expand All @@ -270,7 +274,7 @@ mod tests {
"Đẹp Đẽ Êm Ả Ñandú Árbol Олег Иванович Íslensku Þjóðarinnar Ελληνική"
)),
&str,
Utf8,
Utf8View,
StringViewArray
);
test_function!(
Expand All @@ -280,15 +284,15 @@ mod tests {
)))],
Ok(Some("")),
&str,
Utf8,
Utf8View,
StringViewArray
);
test_function!(
InitcapFunc::new(),
vec![ColumnarValue::Scalar(ScalarValue::Utf8View(None))],
Ok(None),
&str,
Utf8,
Utf8View,
StringViewArray
);

Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub mod test {

let result = result.unwrap().to_array(cardinality).expect("Failed to convert to array");
let result = result.as_any().downcast_ref::<$ARRAY_TYPE>().expect("Failed to convert to type");
assert_eq!(result.data_type(), &$EXPECTED_DATA_TYPE);

// value is correct
match expected {
Expand Down
Loading