seddonm1 commented on a change in pull request #9509:
URL: https://github.com/apache/arrow/pull/9509#discussion_r577299127
##########
File path: rust/datafusion/src/physical_plan/string_expressions.rs
##########
@@ -115,6 +119,40 @@ where
}
}
+/// Returns number of characters in the string.
+/// character_length_i32('josé') = 4
+pub fn character_length_i32(args: &[ArrayRef]) -> Result<ArrayRef> {
+ let string_array: &GenericStringArray<i32> = args[0]
+ .as_any()
+ .downcast_ref::<GenericStringArray<i32>>()
+ .unwrap();
+
+ // first map is the iterator, second is for the `Option<_>`
+ let result = string_array
+ .iter()
+ .map(|x| x.map(|x: &str| x.graphemes(true).count() as i32))
+ .collect::<Int32Array>();
+
+ Ok(Arc::new(result) as ArrayRef)
+}
+
+/// Returns number of characters in the string.
+/// character_length_i64('josé') = 4
+pub fn character_length_i64(args: &[ArrayRef]) -> Result<ArrayRef> {
Review comment:
Thanks I will have a go. There are a couple more instances this generic
from_usize could help.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]