Skip to content

Commit

Permalink
Minor: remove duplicated array_replace tests (#8066)
Browse files Browse the repository at this point in the history
* Add whitespace

* remove redundant test

* remove unused code
  • Loading branch information
alamb committed Nov 11, 2023
1 parent 21b9626 commit 4068b06
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 217 deletions.
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 @@ -2775,193 +2775,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 @@ -3194,17 +3007,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

0 comments on commit 4068b06

Please sign in to comment.