diff --git a/datafusion/functions/src/string/initcap.rs b/datafusion/functions/src/string/initcap.rs index b3924d93c876..4e1eb213ef57 100644 --- a/datafusion/functions/src/string/initcap.rs +++ b/datafusion/functions/src/string/initcap.rs @@ -107,8 +107,9 @@ fn initcap_utf8view(args: &[ArrayRef]) -> Result { } fn initcap_string(string: Option<&str>) -> Option { + let mut char_vector = Vec::::new(); string.map(|string: &str| { - let mut char_vector = Vec::::new(); + char_vector.clear(); let mut previous_character_letter_or_number = false; for c in string.chars() { if previous_character_letter_or_number { diff --git a/datafusion/sqllogictest/test_files/string_view.slt b/datafusion/sqllogictest/test_files/string_view.slt index f1a17c8c12e3..a61e3830fd08 100644 --- a/datafusion/sqllogictest/test_files/string_view.slt +++ b/datafusion/sqllogictest/test_files/string_view.slt @@ -427,6 +427,15 @@ logical_plan ### Initcap +query TT +EXPLAIN SELECT + INITCAP(column1_utf8view) as c +FROM test; +---- +logical_plan +01)Projection: initcap(test.column1_utf8view) AS c +02)--TableScan: test projection=[column1_utf8view] + # Create a table with lowercase strings statement ok CREATE TABLE test_lowercase AS SELECT @@ -621,15 +630,6 @@ logical_plan 02)--Projection: CAST(test.column2_utf8view AS Utf8) AS __common_expr_1, test.column1_utf8view 03)----TableScan: test projection=[column1_utf8view, column2_utf8view] -query TT -EXPLAIN SELECT - INITCAP(column1_utf8view) as c -FROM test; ----- -logical_plan -01)Projection: initcap(test.column1_utf8view) AS c -02)--TableScan: test projection=[column1_utf8view] - ## Ensure no casts for LEVENSHTEIN ## TODO https://github.com/apache/datafusion/issues/11854 query TT