Skip to content

Minor: remove duplicated array_replace tests #8066

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 0 additions & 198 deletions datafusion/physical-expr/src/array_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2752,193 +2752,6 @@ mod tests {
);
}

#[test]
fn test_array_replace() {
// array_replace([3, 1, 2, 3, 2, 3], 3, 4) = [4, 1, 2, 3, 2, 3]
let list_array = return_array_with_repeating_elements();
let array = array_replace(&[
list_array,
Arc::new(Int64Array::from_value(3, 1)),
Arc::new(Int64Array::from_value(4, 1)),
])
.expect("failed to initialize function array_replace");
let result =
as_list_array(&array).expect("failed to initialize function array_replace");

assert_eq!(result.len(), 1);
assert_eq!(
&[4, 1, 2, 3, 2, 3],
result
.value(0)
.as_any()
.downcast_ref::<Int64Array>()
.unwrap()
.values()
);
}

#[test]
fn test_nested_array_replace() {
// array_replace(
// [[1, 2, 3, 4], [5, 6, 7, 8], [1, 2, 3, 4], [9, 10, 11, 12], [5, 6, 7, 8]],
// [1, 2, 3, 4],
// [11, 12, 13, 14],
// ) = [[11, 12, 13, 14], [5, 6, 7, 8], [1, 2, 3, 4], [9, 10, 11, 12], [5, 6, 7, 8]]
let list_array = return_nested_array_with_repeating_elements();
let from_array = return_array();
let to_array = return_extra_array();
let array = array_replace(&[list_array, from_array, to_array])
.expect("failed to initialize function array_replace");
let result =
as_list_array(&array).expect("failed to initialize function array_replace");

assert_eq!(result.len(), 1);
let data = vec![
Some(vec![Some(11), Some(12), Some(13), Some(14)]),
Some(vec![Some(5), Some(6), Some(7), Some(8)]),
Some(vec![Some(1), Some(2), Some(3), Some(4)]),
Some(vec![Some(9), Some(10), Some(11), Some(12)]),
Some(vec![Some(5), Some(6), Some(7), Some(8)]),
];
let expected = ListArray::from_iter_primitive::<Int64Type, _, _>(data);
assert_eq!(
expected,
result
.value(0)
.as_any()
.downcast_ref::<ListArray>()
.unwrap()
.clone()
);
}

#[test]
fn test_array_replace_n() {
// array_replace_n([3, 1, 2, 3, 2, 3], 3, 4, 2) = [4, 1, 2, 4, 2, 3]
let list_array = return_array_with_repeating_elements();
let array = array_replace_n(&[
list_array,
Arc::new(Int64Array::from_value(3, 1)),
Arc::new(Int64Array::from_value(4, 1)),
Arc::new(Int64Array::from_value(2, 1)),
])
.expect("failed to initialize function array_replace_n");
let result =
as_list_array(&array).expect("failed to initialize function array_replace_n");

assert_eq!(result.len(), 1);
assert_eq!(
&[4, 1, 2, 4, 2, 3],
result
.value(0)
.as_any()
.downcast_ref::<Int64Array>()
.unwrap()
.values()
);
}

#[test]
fn test_nested_array_replace_n() {
// array_replace_n(
// [[1, 2, 3, 4], [5, 6, 7, 8], [1, 2, 3, 4], [9, 10, 11, 12], [5, 6, 7, 8]],
// [1, 2, 3, 4],
// [11, 12, 13, 14],
// 2,
// ) = [[11, 12, 13, 14], [5, 6, 7, 8], [11, 12, 13, 14], [9, 10, 11, 12], [5, 6, 7, 8]]
let list_array = return_nested_array_with_repeating_elements();
let from_array = return_array();
let to_array = return_extra_array();
let array = array_replace_n(&[
list_array,
from_array,
to_array,
Arc::new(Int64Array::from_value(2, 1)),
])
.expect("failed to initialize function array_replace_n");
let result =
as_list_array(&array).expect("failed to initialize function array_replace_n");

assert_eq!(result.len(), 1);
let data = vec![
Some(vec![Some(11), Some(12), Some(13), Some(14)]),
Some(vec![Some(5), Some(6), Some(7), Some(8)]),
Some(vec![Some(11), Some(12), Some(13), Some(14)]),
Some(vec![Some(9), Some(10), Some(11), Some(12)]),
Some(vec![Some(5), Some(6), Some(7), Some(8)]),
];
let expected = ListArray::from_iter_primitive::<Int64Type, _, _>(data);
assert_eq!(
expected,
result
.value(0)
.as_any()
.downcast_ref::<ListArray>()
.unwrap()
.clone()
);
}

#[test]
fn test_array_replace_all() {
// array_replace_all([3, 1, 2, 3, 2, 3], 3, 4) = [4, 1, 2, 4, 2, 4]
let list_array = return_array_with_repeating_elements();
let array = array_replace_all(&[
list_array,
Arc::new(Int64Array::from_value(3, 1)),
Arc::new(Int64Array::from_value(4, 1)),
])
.expect("failed to initialize function array_replace_all");
let result = as_list_array(&array)
.expect("failed to initialize function array_replace_all");

assert_eq!(result.len(), 1);
assert_eq!(
&[4, 1, 2, 4, 2, 4],
result
.value(0)
.as_any()
.downcast_ref::<Int64Array>()
.unwrap()
.values()
);
}

#[test]
fn test_nested_array_replace_all() {
// array_replace_all(
// [[1, 2, 3, 4], [5, 6, 7, 8], [1, 2, 3, 4], [9, 10, 11, 12], [5, 6, 7, 8]],
// [1, 2, 3, 4],
// [11, 12, 13, 14],
// ) = [[11, 12, 13, 14], [5, 6, 7, 8], [11, 12, 13, 14], [9, 10, 11, 12], [5, 6, 7, 8]]
let list_array = return_nested_array_with_repeating_elements();
let from_array = return_array();
let to_array = return_extra_array();
let array = array_replace_all(&[list_array, from_array, to_array])
.expect("failed to initialize function array_replace_all");
let result = as_list_array(&array)
.expect("failed to initialize function array_replace_all");

assert_eq!(result.len(), 1);
let data = vec![
Some(vec![Some(11), Some(12), Some(13), Some(14)]),
Some(vec![Some(5), Some(6), Some(7), Some(8)]),
Some(vec![Some(11), Some(12), Some(13), Some(14)]),
Some(vec![Some(9), Some(10), Some(11), Some(12)]),
Some(vec![Some(5), Some(6), Some(7), Some(8)]),
];
let expected = ListArray::from_iter_primitive::<Int64Type, _, _>(data);
assert_eq!(
expected,
result
.value(0)
.as_any()
.downcast_ref::<ListArray>()
.unwrap()
.clone()
);
}

#[test]
fn test_array_to_string() {
// array_to_string([1, 2, 3, 4], ',') = 1,2,3,4
Expand Down Expand Up @@ -3171,17 +2984,6 @@ mod tests {
make_array(&args).expect("failed to initialize function array")
}

fn return_extra_array() -> ArrayRef {
// Returns: [11, 12, 13, 14]
let args = [
Arc::new(Int64Array::from(vec![Some(11)])) as ArrayRef,
Arc::new(Int64Array::from(vec![Some(12)])) as ArrayRef,
Arc::new(Int64Array::from(vec![Some(13)])) as ArrayRef,
Arc::new(Int64Array::from(vec![Some(14)])) as ArrayRef,
];
make_array(&args).expect("failed to initialize function array")
}

fn return_nested_array() -> ArrayRef {
// Returns: [[1, 2, 3, 4], [5, 6, 7, 8]]
let args = [
Expand Down
Loading