HaoYang670 commented on code in PR #1784:
URL: https://github.com/apache/arrow-rs/pull/1784#discussion_r890102648


##########
arrow/src/compute/kernels/substring.rs:
##########
@@ -1083,6 +1135,164 @@ mod tests {
         generic_string_with_non_zero_offset::<i64>()
     }
 
+    fn with_nulls_generic_string_by_char<O: OffsetSizeTrait>() -> Result<()> {
+        let input_vals = vec![Some("hello"), None, Some("Γ ⊢x:T")];
+        let cases = vec![
+            // all-nulls array is always identical
+            (vec![None, None, None], 0, None, vec![None, None, None]),
+            // identity
+            (
+                input_vals.clone(),
+                0,
+                None,
+                vec![Some("hello"), None, Some("Γ ⊢x:T")],
+            ),
+            // 0 length -> Nothing
+            (
+                input_vals.clone(),
+                0,
+                Some(0),
+                vec![Some(""), None, Some("")],
+            ),
+            // high start -> Nothing
+            (
+                input_vals.clone(),
+                1000,
+                Some(0),
+                vec![Some(""), None, Some("")],
+            ),
+            // high negative start -> identity
+            (
+                input_vals.clone(),
+                -1000,
+                None,
+                vec![Some("hello"), None, Some("Γ ⊢x:T")],
+            ),
+            // high length -> identity
+            (
+                input_vals.clone(),
+                0,
+                Some(1000),
+                vec![Some("hello"), None, Some("Γ ⊢x:T")],
+            ),
+        ];
+
+        cases.into_iter().try_for_each::<_, Result<()>>(
+            |(array, start, length, expected)| {
+                let array = GenericStringArray::<O>::from(array);
+                let result = substring_by_char(&array, start, length)?;
+                assert_eq!(array.len(), result.len());
+
+                let expected = GenericStringArray::<O>::from(expected);
+                assert_eq!(expected, result);
+                Ok(())
+            },
+        )?;
+
+        Ok(())
+    }
+
+    #[test]
+    fn with_nulls_string_by_char() -> Result<()> {
+        with_nulls_generic_string_by_char::<i32>()
+    }
+
+    #[test]
+    fn with_nulls_large_string_by_char() -> Result<()> {
+        with_nulls_generic_string_by_char::<i64>()
+    }
+
+    fn without_nulls_generic_string_by_char<O: OffsetSizeTrait>() -> 
Result<()> {
+        let input_vals = vec!["hello", "", "Γ ⊢x:T"];
+        let cases = vec![
+            // empty array is always identical
+            (vec!["", "", ""], 0, None, vec!["", "", ""]),
+            // increase start
+            (input_vals.clone(), 0, None, vec!["hello", "", "Γ ⊢x:T"]),
+            (input_vals.clone(), 1, None, vec!["ello", "", " ⊢x:T"]),
+            (input_vals.clone(), 2, None, vec!["llo", "", "⊢x:T"]),
+            (input_vals.clone(), 3, None, vec!["lo", "", "x:T"]),
+            (input_vals.clone(), 10, None, vec!["", "", ""]),
+            // increase start negatively
+            (input_vals.clone(), -1, None, vec!["o", "", "T"]),
+            (input_vals.clone(), -2, None, vec!["lo", "", ":T"]),
+            (input_vals.clone(), -4, None, vec!["ello", "", "⊢x:T"]),
+            (input_vals.clone(), -10, None, vec!["hello", "", "Γ ⊢x:T"]),
+            // increase length
+            (input_vals.clone(), 1, Some(1), vec!["e", "", " "]),
+            (input_vals.clone(), 1, Some(2), vec!["el", "", " ⊢"]),
+            (input_vals.clone(), 1, Some(3), vec!["ell", "", " ⊢x"]),
+            (input_vals.clone(), 1, Some(6), vec!["ello", "", " ⊢x:T"]),
+            (input_vals.clone(), -4, Some(1), vec!["e", "", "⊢"]),
+            (input_vals.clone(), -4, Some(2), vec!["el", "", "⊢x"]),
+            (input_vals.clone(), -4, Some(3), vec!["ell", "", "⊢x:"]),
+            (input_vals.clone(), -4, Some(4), vec!["ello", "", "⊢x:T"]),
+        ];
+
+        cases.into_iter().try_for_each::<_, Result<()>>(

Review Comment:
   Tracked by #1801



##########
arrow/src/compute/kernels/substring.rs:
##########
@@ -1083,6 +1135,164 @@ mod tests {
         generic_string_with_non_zero_offset::<i64>()
     }
 
+    fn with_nulls_generic_string_by_char<O: OffsetSizeTrait>() -> Result<()> {
+        let input_vals = vec![Some("hello"), None, Some("Γ ⊢x:T")];
+        let cases = vec![
+            // all-nulls array is always identical
+            (vec![None, None, None], 0, None, vec![None, None, None]),
+            // identity
+            (
+                input_vals.clone(),
+                0,
+                None,
+                vec![Some("hello"), None, Some("Γ ⊢x:T")],
+            ),
+            // 0 length -> Nothing
+            (
+                input_vals.clone(),
+                0,
+                Some(0),
+                vec![Some(""), None, Some("")],
+            ),
+            // high start -> Nothing
+            (
+                input_vals.clone(),
+                1000,
+                Some(0),
+                vec![Some(""), None, Some("")],
+            ),
+            // high negative start -> identity
+            (
+                input_vals.clone(),
+                -1000,
+                None,
+                vec![Some("hello"), None, Some("Γ ⊢x:T")],
+            ),
+            // high length -> identity
+            (
+                input_vals.clone(),
+                0,
+                Some(1000),
+                vec![Some("hello"), None, Some("Γ ⊢x:T")],
+            ),
+        ];
+
+        cases.into_iter().try_for_each::<_, Result<()>>(
+            |(array, start, length, expected)| {
+                let array = GenericStringArray::<O>::from(array);
+                let result = substring_by_char(&array, start, length)?;
+                assert_eq!(array.len(), result.len());
+
+                let expected = GenericStringArray::<O>::from(expected);
+                assert_eq!(expected, result);
+                Ok(())
+            },
+        )?;
+
+        Ok(())
+    }
+
+    #[test]
+    fn with_nulls_string_by_char() -> Result<()> {
+        with_nulls_generic_string_by_char::<i32>()
+    }
+
+    #[test]
+    fn with_nulls_large_string_by_char() -> Result<()> {
+        with_nulls_generic_string_by_char::<i64>()
+    }
+
+    fn without_nulls_generic_string_by_char<O: OffsetSizeTrait>() -> 
Result<()> {
+        let input_vals = vec!["hello", "", "Γ ⊢x:T"];
+        let cases = vec![
+            // empty array is always identical
+            (vec!["", "", ""], 0, None, vec!["", "", ""]),
+            // increase start
+            (input_vals.clone(), 0, None, vec!["hello", "", "Γ ⊢x:T"]),
+            (input_vals.clone(), 1, None, vec!["ello", "", " ⊢x:T"]),
+            (input_vals.clone(), 2, None, vec!["llo", "", "⊢x:T"]),
+            (input_vals.clone(), 3, None, vec!["lo", "", "x:T"]),
+            (input_vals.clone(), 10, None, vec!["", "", ""]),
+            // increase start negatively
+            (input_vals.clone(), -1, None, vec!["o", "", "T"]),
+            (input_vals.clone(), -2, None, vec!["lo", "", ":T"]),
+            (input_vals.clone(), -4, None, vec!["ello", "", "⊢x:T"]),
+            (input_vals.clone(), -10, None, vec!["hello", "", "Γ ⊢x:T"]),
+            // increase length
+            (input_vals.clone(), 1, Some(1), vec!["e", "", " "]),
+            (input_vals.clone(), 1, Some(2), vec!["el", "", " ⊢"]),
+            (input_vals.clone(), 1, Some(3), vec!["ell", "", " ⊢x"]),
+            (input_vals.clone(), 1, Some(6), vec!["ello", "", " ⊢x:T"]),
+            (input_vals.clone(), -4, Some(1), vec!["e", "", "⊢"]),
+            (input_vals.clone(), -4, Some(2), vec!["el", "", "⊢x"]),
+            (input_vals.clone(), -4, Some(3), vec!["ell", "", "⊢x:"]),
+            (input_vals.clone(), -4, Some(4), vec!["ello", "", "⊢x:T"]),
+        ];
+
+        cases.into_iter().try_for_each::<_, Result<()>>(
+            |(array, start, length, expected)| {
+                let array = GenericStringArray::<O>::from(array);
+                let result = substring_by_char(&array, start, length)?;
+                assert_eq!(array.len(), result.len());
+                let expected = GenericStringArray::<O>::from(expected);
+                assert_eq!(expected, result);
+                Ok(())
+            },
+        )?;
+
+        Ok(())
+    }
+
+    #[test]
+    fn without_nulls_string_by_char() -> Result<()> {
+        without_nulls_generic_string_by_char::<i32>()
+    }
+
+    #[test]
+    fn without_nulls_large_string_by_char() -> Result<()> {
+        without_nulls_generic_string_by_char::<i64>()
+    }
+
+    fn generic_string_by_char_with_non_zero_offset<O: OffsetSizeTrait>() -> 
Result<()> {
+        let values = "S→T = Πx:S.T";

Review Comment:
   Tracked by #1801



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to