This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 8473490edb test(arrow-cast): move string cast tests to integration
suite (#11998)
8473490edb is described below
commit 8473490edb8aa585a674076b00c151c59d09fc3a
Author: Arnab Mondal <[email protected]>
AuthorDate: Sat Nov 7 05:04:51 2026 +0000
test(arrow-cast): move string cast tests to integration suite (#11998)
# Which issue does this PR close?
Part of [#11033](https://github.com/apache/arrow-rs/issues/11033).
# Rationale for this change
The public-behavior cast tests in `arrow-cast/src/cast/mod.rs` are being
moved into the crate-level integration test suite so individual cast
families are easier to locate and maintain. This is the string-test
slice of that work.
# What changes are included in this PR?
- Adds `arrow-cast/tests/cast/string.rs` to the existing `cast`
integration-test target.
- Moves three public string cast tests out of the inline `cast/mod.rs`
test module.
- Keeps numeric and boolean, temporal, and binary and byte-view cases
for their separately tracked groups.
- Does not change production behavior or widen production visibility.
# Are these changes tested?
Yes. The existing string cast coverage is preserved unchanged in the
integration suite. The full workspace test suite passes locally, and the
moved sliced-offset test was verified to fail when its expected public
result was deliberately corrupted. Repository-wide formatting, spelling,
and all-features Clippy checks also pass.
# Are there any significant user-facing changes?
No.
# AI usage disclosure
OpenAI Codex assisted with the mechanical test extraction. I reviewed
the resulting changes, verified the moved tests exercise the public cast
API, and ran the full workspace validation locally.
---
arrow-cast/src/cast/mod.rs | 74 -------------------------------------
arrow-cast/tests/cast/mod.rs | 1 +
arrow-cast/tests/cast/string.rs | 81 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 82 insertions(+), 74 deletions(-)
diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs
index 28ad31d484..e166500c82 100644
--- a/arrow-cast/src/cast/mod.rs
+++ b/arrow-cast/src/cast/mod.rs
@@ -4771,67 +4771,6 @@ mod tests {
assert!(c.is_null(3));
}
- #[test]
- fn test_cast_to_strings() {
- let a = Int32Array::from(vec![1, 2, 3]);
- let out = cast(&a, &DataType::Utf8).unwrap();
- let out = out
- .as_any()
- .downcast_ref::<StringArray>()
- .unwrap()
- .into_iter()
- .collect::<Vec<_>>();
- assert_eq!(out, vec![Some("1"), Some("2"), Some("3")]);
- let out = cast(&a, &DataType::LargeUtf8).unwrap();
- let out = out
- .as_any()
- .downcast_ref::<LargeStringArray>()
- .unwrap()
- .into_iter()
- .collect::<Vec<_>>();
- assert_eq!(out, vec![Some("1"), Some("2"), Some("3")]);
- }
-
- #[test]
- fn test_str_to_str_casts() {
- for data in [
- vec![Some("foo"), Some("bar"), Some("ham")],
- vec![Some("foo"), None, Some("bar")],
- ] {
- let a = LargeStringArray::from(data.clone());
- let to = cast(&a, &DataType::Utf8).unwrap();
- let expect = a
- .as_any()
- .downcast_ref::<LargeStringArray>()
- .unwrap()
- .into_iter()
- .collect::<Vec<_>>();
- let out = to
- .as_any()
- .downcast_ref::<StringArray>()
- .unwrap()
- .into_iter()
- .collect::<Vec<_>>();
- assert_eq!(expect, out);
-
- let a = StringArray::from(data);
- let to = cast(&a, &DataType::LargeUtf8).unwrap();
- let expect = a
- .as_any()
- .downcast_ref::<StringArray>()
- .unwrap()
- .into_iter()
- .collect::<Vec<_>>();
- let out = to
- .as_any()
- .downcast_ref::<LargeStringArray>()
- .unwrap()
- .into_iter()
- .collect::<Vec<_>>();
- assert_eq!(expect, out);
- }
- }
-
const VIEW_TEST_DATA: [Option<&str>; 5] = [
Some("hello"),
Some("repeated"),
@@ -6461,19 +6400,6 @@ mod tests {
assert_eq!(946684800000, c.value(5));
}
- #[test]
- fn test_utf8_cast_offsets() {
- // test if offset of the array is taken into account during cast
- let str_array = StringArray::from(vec!["a", "b", "c"]);
- let str_array = str_array.slice(1, 2);
-
- let out = cast(&str_array, &DataType::LargeUtf8).unwrap();
-
- let large_str_array =
out.as_any().downcast_ref::<LargeStringArray>().unwrap();
- let strs = large_str_array.into_iter().flatten().collect::<Vec<_>>();
- assert_eq!(strs, &["b", "c"])
- }
-
#[test]
fn test_cast_outside_supported_range_for_nanoseconds() {
const EXPECTED_ERROR_MESSAGE: &str = "The dates that can be
represented as nanoseconds have to be between 1677-09-21T00:12:44.0 and
2262-04-11T23:47:16.854775804";
diff --git a/arrow-cast/tests/cast/mod.rs b/arrow-cast/tests/cast/mod.rs
index e8c64141a9..a7d2313da4 100644
--- a/arrow-cast/tests/cast/mod.rs
+++ b/arrow-cast/tests/cast/mod.rs
@@ -6,4 +6,5 @@ mod decimal;
mod dictionary;
mod list;
mod map;
+mod string;
mod r#struct;
diff --git a/arrow-cast/tests/cast/string.rs b/arrow-cast/tests/cast/string.rs
new file mode 100644
index 0000000000..de614e4078
--- /dev/null
+++ b/arrow-cast/tests/cast/string.rs
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for
additional information regarding copyright ownership
+// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF)
under one or more contributor license agreements
+
+use arrow_array::{Array, Int32Array, LargeStringArray, StringArray};
+use arrow_cast::cast;
+use arrow_schema::DataType;
+
+#[test]
+fn test_cast_to_strings() {
+ let a = Int32Array::from(vec![1, 2, 3]);
+ let out = cast(&a, &DataType::Utf8).unwrap();
+ let out = out
+ .as_any()
+ .downcast_ref::<StringArray>()
+ .unwrap()
+ .into_iter()
+ .collect::<Vec<_>>();
+ assert_eq!(out, vec![Some("1"), Some("2"), Some("3")]);
+ let out = cast(&a, &DataType::LargeUtf8).unwrap();
+ let out = out
+ .as_any()
+ .downcast_ref::<LargeStringArray>()
+ .unwrap()
+ .into_iter()
+ .collect::<Vec<_>>();
+ assert_eq!(out, vec![Some("1"), Some("2"), Some("3")]);
+}
+
+#[test]
+fn test_str_to_str_casts() {
+ for data in [
+ vec![Some("foo"), Some("bar"), Some("ham")],
+ vec![Some("foo"), None, Some("bar")],
+ ] {
+ let a = LargeStringArray::from(data.clone());
+ let to = cast(&a, &DataType::Utf8).unwrap();
+ let expect = a
+ .as_any()
+ .downcast_ref::<LargeStringArray>()
+ .unwrap()
+ .into_iter()
+ .collect::<Vec<_>>();
+ let out = to
+ .as_any()
+ .downcast_ref::<StringArray>()
+ .unwrap()
+ .into_iter()
+ .collect::<Vec<_>>();
+ assert_eq!(expect, out);
+
+ let a = StringArray::from(data);
+ let to = cast(&a, &DataType::LargeUtf8).unwrap();
+ let expect = a
+ .as_any()
+ .downcast_ref::<StringArray>()
+ .unwrap()
+ .into_iter()
+ .collect::<Vec<_>>();
+ let out = to
+ .as_any()
+ .downcast_ref::<LargeStringArray>()
+ .unwrap()
+ .into_iter()
+ .collect::<Vec<_>>();
+ assert_eq!(expect, out);
+ }
+}
+
+#[test]
+fn test_utf8_cast_offsets() {
+ // test if offset of the array is taken into account during cast
+ let str_array = StringArray::from(vec!["a", "b", "c"]);
+ let str_array = str_array.slice(1, 2);
+
+ let out = cast(&str_array, &DataType::LargeUtf8).unwrap();
+
+ let large_str_array =
out.as_any().downcast_ref::<LargeStringArray>().unwrap();
+ let strs = large_str_array.into_iter().flatten().collect::<Vec<_>>();
+ assert_eq!(strs, &["b", "c"])
+}