alamb commented on code in PR #11676:
URL: https://github.com/apache/datafusion/pull/11676#discussion_r1693945106


##########
datafusion/functions/src/unicode/character_length.rs:
##########
@@ -92,15 +81,32 @@ impl ScalarUDFImpl for CharacterLengthFunc {
 /// Returns number of characters in the string.
 /// character_length('josé') = 4
 /// The implementation counts UTF-8 code points to count the number of 
characters
-fn character_length<T: ArrowPrimitiveType>(args: &[ArrayRef]) -> 
Result<ArrayRef>
+fn character_length(args: &[ArrayRef]) -> Result<ArrayRef> {
+    match args[0].data_type() {
+        DataType::Utf8 => {
+            let string_array = args[0].as_string::<i32>();
+            character_length_general::<Int32Type, _>(string_array)
+        }
+        DataType::LargeUtf8 => {
+            let string_array = args[0].as_string::<i64>();
+            character_length_general::<Int64Type, _>(string_array)
+        }
+        DataType::Utf8View => {
+            let string_array = args[0].as_string_view();
+            character_length_general::<Int32Type, _>(string_array)
+        }
+        _ => unreachable!(),
+    }
+}
+
+fn character_length_general<'a, T: ArrowPrimitiveType, V: ArrayAccessor<Item = 
&'a str>>(

Review Comment:
   This pattern comes up a lot (specifically using `ArrayAccessor<Item = &'a 
str>`) and I think will be one of the key pattens to implement native / 
specialized support for StringView across the codebase
   
   I wonder if there is any way to make this more discoverable / approachable 🤔 
   
   I am thinking I should adapt this code as a documentation example to the 
`ArrayAccessor` trait 
https://docs.rs/arrow/latest/arrow/array/trait.ArrayAccessor.html



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to