Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Dec 18, 2022
1 parent 89e9aed commit fc1d907
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 59 deletions.
4 changes: 2 additions & 2 deletions examples/ipc_file_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn main() -> Result<()> {
Field::new("b", DataType::Utf8, false),
]);

let a = Int32Array::from_slice(&[1, 2, 3, 4, 5]);
let b = Utf8Array::<i32>::from_slice(&["a", "b", "c", "d", "e"]);
let a = Int32Array::from_slice([1, 2, 3, 4, 5]);
let b = Utf8Array::<i32>::from_slice(["a", "b", "c", "d", "e"]);

let chunk = Chunk::try_new(vec![a.boxed(), b.boxed()])?;

Expand Down
8 changes: 4 additions & 4 deletions tests/it/array/equal/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ fn test_generic_string_equal<O: Offset>() {
let cases = binary_cases();

for (lhs, rhs, expected) in cases {
let lhs = lhs.iter().map(|x| x.as_deref()).collect::<Vec<_>>();
let rhs = rhs.iter().map(|x| x.as_deref()).collect::<Vec<_>>();
let lhs = Utf8Array::<O>::from(&lhs);
let rhs = Utf8Array::<O>::from(&rhs);
let lhs = lhs.iter().map(|x| x.as_deref());
let rhs = rhs.iter().map(|x| x.as_deref());
let lhs = Utf8Array::<O>::from_trusted_len_iter(lhs);
let rhs = Utf8Array::<O>::from_trusted_len_iter(rhs);
test_equal(&lhs, &rhs, expected);
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/it/compute/concatenate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ fn empty_vec() {
#[test]
fn incompatible_datatypes() {
let re = concatenate(&[
&Int64Array::from(vec![Some(-1), Some(2), None]),
&Utf8Array::<i32>::from(&vec![Some("hello"), Some("bar"), Some("world")]),
&Int64Array::from([Some(-1), Some(2), None]),
&Utf8Array::<i32>::from([Some("hello"), Some("bar"), Some("world")]),
]);
assert!(re.is_err());
}

#[test]
fn string_arrays() -> Result<()> {
let arr = concatenate(&[
&Utf8Array::<i32>::from_slice(&vec!["hello", "world"]),
&Utf8Array::<i32>::from_slice(&vec!["2", "3", "4"]),
&Utf8Array::<i32>::from(&vec![Some("foo"), Some("bar"), None, Some("baz")]),
&Utf8Array::<i32>::from_slice(["hello", "world"]),
&Utf8Array::<i32>::from_slice(["2", "3", "4"]),
&Utf8Array::<i32>::from([Some("foo"), Some("bar"), None, Some("baz")]),
])?;

let expected_output = Utf8Array::<i32>::from(&vec![
let expected_output = Utf8Array::<i32>::from([
Some("hello"),
Some("world"),
Some("2"),
Expand Down
6 changes: 3 additions & 3 deletions tests/it/compute/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ fn primative_array_with_null() {

#[test]
fn string_array_with_null() {
let a = Utf8Array::<i32>::from(&vec![Some("hello"), None, Some("world"), None]);
let b = BooleanArray::from_slice(vec![true, false, false, true]);
let a = Utf8Array::<i32>::from([Some("hello"), None, Some("world"), None]);
let b = BooleanArray::from_slice([true, false, false, true]);
let c = filter(&a, &b).unwrap();
let d = c
.as_ref()
Expand All @@ -99,7 +99,7 @@ fn string_array_with_null() {
#[test]
fn binary_array_with_null() {
let data: Vec<Option<&[u8]>> = vec![Some(b"hello"), None, Some(b"world"), None];
let a = BinaryArray::<i32>::from(&data);
let a = BinaryArray::<i32>::from(data);
let b = BooleanArray::from_slice(vec![true, false, false, true]);
let c = filter(&a, &b).unwrap();
let d = c
Expand Down
2 changes: 1 addition & 1 deletion tests/it/compute/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn length_test_string<O: Offset>() {
]
.into_iter()
.for_each(|(input, expected)| {
let array = Utf8Array::<O>::from(&input);
let array = Utf8Array::<O>::from(input);
let result = length(&array).unwrap();

let data_type = if O::IS_LARGE {
Expand Down
21 changes: 8 additions & 13 deletions tests/it/compute/sort/lex_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ fn test_lex_sort_mixed_types() {
options: None,
},
];
let c1 = Int64Array::from(&[Some(-1), Some(0), Some(0), Some(2)]);
let c2 = UInt32Array::from(&[Some(7), Some(101), Some(102), Some(8)]);
let c3 = Int64Array::from(&[Some(-3), Some(-1), Some(-4), Some(-2)]);
let expected = vec![Box::new(c1) as Box<dyn Array>, Box::new(c2), Box::new(c3)];
let c1 = Int64Array::from([Some(-1), Some(0), Some(0), Some(2)]);
let c2 = UInt32Array::from([Some(7), Some(101), Some(102), Some(8)]);
let c3 = Int64Array::from([Some(-3), Some(-1), Some(-4), Some(-2)]);
let expected = vec![c1.boxed(), c2.boxed(), c3.boxed()];
test_lex_sort_arrays(input, expected);
}

#[test]
fn test_lex_sort_mixed_types2() {
// test mix of string and in64 with option
let c1 = Int64Array::from(&[Some(0), Some(2), Some(-1), Some(0)]);
let c2 = Utf8Array::<i32>::from(&vec![Some("foo"), Some("9"), Some("7"), Some("bar")]);
let c1 = Int64Array::from([Some(0), Some(2), Some(-1), Some(0)]);
let c2 = Utf8Array::<i32>::from([Some("foo"), Some("9"), Some("7"), Some("bar")]);
let input = vec![
SortColumn {
values: &c1,
Expand All @@ -69,13 +69,8 @@ fn test_lex_sort_mixed_types2() {
},
];
let expected = vec![
Box::new(Int64Array::from(&[Some(2), Some(0), Some(0), Some(-1)])) as Box<dyn Array>,
Box::new(Utf8Array::<i32>::from(&vec![
Some("9"),
Some("foo"),
Some("bar"),
Some("7"),
])) as Box<dyn Array>,
Int64Array::from([Some(2), Some(0), Some(0), Some(-1)]).boxed(),
Utf8Array::<i32>::from([Some("9"), Some("foo"), Some("bar"), Some("7")]).boxed(),
];
test_lex_sort_arrays(input, expected);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/it/compute/substring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ fn with_nulls_utf8<O: Offset>() -> Result<()> {
cases
.into_iter()
.try_for_each::<_, Result<()>>(|(array, start, length, expected)| {
let array = Utf8Array::<O>::from(&array);
let array = Utf8Array::<O>::from(array);
let result = substring(&array, start, &length)?;
assert_eq!(array.len(), result.len());

let result = result.as_any().downcast_ref::<Utf8Array<O>>().unwrap();
let expected = Utf8Array::<O>::from(&expected);
let expected = Utf8Array::<O>::from(expected);

assert_eq!(&expected, result);
Ok(())
Expand Down Expand Up @@ -194,12 +194,12 @@ fn with_null_binarys<O: Offset>() -> Result<()> {
cases
.into_iter()
.try_for_each::<_, Result<()>>(|(array, start, length, expected)| {
let array = BinaryArray::<O>::from(&array);
let array = BinaryArray::<O>::from(array);
let result = substring(&array, start, &length)?;
assert_eq!(array.len(), result.len());

let result = result.as_any().downcast_ref::<BinaryArray<O>>().unwrap();
let expected = BinaryArray::<O>::from(&expected);
let expected = BinaryArray::<O>::from(expected);
assert_eq!(&expected, result);
Ok(())
})?;
Expand Down Expand Up @@ -274,11 +274,11 @@ fn without_null_binarys<O: Offset>() -> Result<()> {
cases
.into_iter()
.try_for_each::<_, Result<()>>(|(array, start, length, expected)| {
let array = BinaryArray::<O>::from_slice(&array);
let array = BinaryArray::<O>::from_slice(array);
let result = substring(&array, start, &length)?;
assert_eq!(array.len(), result.len());
let result = result.as_any().downcast_ref::<BinaryArray<O>>().unwrap();
let expected = BinaryArray::<O>::from_slice(&expected);
let expected = BinaryArray::<O>::from_slice(expected);
assert_eq!(&expected, result);
Ok(())
})?;
Expand Down
12 changes: 5 additions & 7 deletions tests/it/ffi/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn timestamp_tz() -> Result<()> {

#[test]
fn utf8_nullable() -> Result<()> {
let data = Utf8Array::<i32>::from(&vec![Some("a"), None, Some("bb"), None]);
let data = Utf8Array::<i32>::from([Some("a"), None, Some("bb"), None]);
test_round_trip(data)
}

Expand All @@ -124,14 +124,13 @@ fn utf8_sliced() -> Result<()> {

#[test]
fn large_utf8() -> Result<()> {
let data = Utf8Array::<i64>::from(&vec![Some("a"), None, Some("bb"), None]);
let data = Utf8Array::<i64>::from([Some("a"), None, Some("bb"), None]);
test_round_trip(data)
}

#[test]
fn binary_nullable() -> Result<()> {
let data =
BinaryArray::<i32>::from(&vec![Some(b"a".as_ref()), None, Some(b"bb".as_ref()), None]);
let data = BinaryArray::<i32>::from([Some(b"a".as_ref()), None, Some(b"bb".as_ref()), None]);
test_round_trip(data)
}

Expand All @@ -155,8 +154,7 @@ fn binary_sliced() -> Result<()> {

#[test]
fn large_binary() -> Result<()> {
let data =
BinaryArray::<i64>::from(&vec![Some(b"a".as_ref()), None, Some(b"bb".as_ref()), None]);
let data = BinaryArray::<i64>::from([Some(b"a".as_ref()), None, Some(b"bb".as_ref()), None]);
test_round_trip(data)
}

Expand Down Expand Up @@ -214,7 +212,7 @@ fn list_sliced() -> Result<()> {
let array = ListArray::<i32>::try_new(
DataType::List(Box::new(Field::new("a", DataType::Int32, true))),
vec![0, 1, 1, 2].try_into().unwrap(),
Box::new(PrimitiveArray::<i32>::from_vec(vec![1, 2])),
Box::new(PrimitiveArray::<i32>::from_slice([1, 2])),
Some(bitmap),
)?;

Expand Down
22 changes: 11 additions & 11 deletions tests/it/io/json/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn f64() -> Result<()> {

#[test]
fn utf8() -> Result<()> {
let array = Utf8Array::<i32>::from(&vec![Some("a"), Some("b"), Some("c"), Some("d"), None]);
let array = Utf8Array::<i32>::from([Some("a"), Some("b"), Some("c"), Some("d"), None]);

let expected = r#"["a","b","c","d",null]"#;

Expand All @@ -55,7 +55,7 @@ fn utf8() -> Result<()> {
#[test]
fn struct_() -> Result<()> {
let c1 = Int32Array::from([Some(1), Some(2), Some(3), None, Some(5)]);
let c2 = Utf8Array::<i32>::from(&vec![Some("a"), Some("b"), Some("c"), Some("d"), None]);
let c2 = Utf8Array::<i32>::from([Some("a"), Some("b"), Some("c"), Some("d"), None]);

let data_type = DataType::Struct(vec![
Field::new("c1", c1.data_type().clone(), true),
Expand Down Expand Up @@ -86,7 +86,7 @@ fn nested_struct_with_validity() -> Result<()> {
StructArray::new(
DataType::Struct(inner),
vec![
Utf8Array::<i32>::from(&vec![None, Some("f"), Some("g")]).boxed(),
Utf8Array::<i32>::from([None, Some("f"), Some("g")]).boxed(),
Int32Array::from(&[Some(20), None, Some(43)]).boxed(),
],
Some(Bitmap::from([false, true, true])),
Expand All @@ -95,7 +95,7 @@ fn nested_struct_with_validity() -> Result<()> {
],
Some(Bitmap::from([true, true, false])),
);
let c2 = Utf8Array::<i32>::from(&vec![Some("a"), Some("b"), Some("c")]);
let c2 = Utf8Array::<i32>::from([Some("a"), Some("b"), Some("c")]);

let data_type = DataType::Struct(vec![
Field::new("c1", c1.data_type().clone(), true),
Expand All @@ -122,7 +122,7 @@ fn nested_struct() -> Result<()> {
Int32Array::from(&[Some(1), None, Some(5)]).boxed(),
StructArray::new(
DataType::Struct(vec![c121]),
vec![Box::new(Utf8Array::<i32>::from(&vec![
vec![Box::new(Utf8Array::<i32>::from([
Some("e"),
Some("f"),
Some("g"),
Expand All @@ -134,7 +134,7 @@ fn nested_struct() -> Result<()> {
None,
);

let c2 = Utf8Array::<i32>::from(&vec![Some("a"), Some("b"), Some("c")]);
let c2 = Utf8Array::<i32>::from([Some("a"), Some("b"), Some("c")]);

let data_type = DataType::Struct(vec![
Field::new("c1", c1.data_type().clone(), true),
Expand Down Expand Up @@ -198,7 +198,7 @@ fn nested_list() -> Result<()> {
c1.try_extend(iter).unwrap();
let c1: ListArray<i32> = c1.into();

let c2 = Utf8Array::<i32>::from(&vec![Some("foo"), Some("bar"), None]);
let c2 = Utf8Array::<i32>::from([Some("foo"), Some("bar"), None]);

let data_type = DataType::Struct(vec![
Field::new("c1", c1.data_type().clone(), true),
Expand Down Expand Up @@ -234,7 +234,7 @@ fn nested_list_records() -> Result<()> {
c1.try_extend(iter).unwrap();
let c1: ListArray<i32> = c1.into();

let c2 = Utf8Array::<i32>::from(&vec![Some("foo"), Some("bar"), None]);
let c2 = Utf8Array::<i32>::from([Some("foo"), Some("bar"), None]);

let schema: Schema = vec![
Field::new("c1", c1.data_type().clone(), true),
Expand Down Expand Up @@ -305,7 +305,7 @@ fn list_of_struct() -> Result<()> {
Int32Array::from(&[Some(1), None, Some(5)]).boxed(),
StructArray::new(
DataType::Struct(inner),
vec![Box::new(Utf8Array::<i32>::from(&vec![
vec![Box::new(Utf8Array::<i32>::from([
Some("e"),
Some("f"),
Some("g"),
Expand Down Expand Up @@ -343,7 +343,7 @@ fn list_of_struct() -> Result<()> {

#[test]
fn escaped_end_of_line_in_utf8() -> Result<()> {
let array = Utf8Array::<i32>::from(&vec![Some("a\na"), None]);
let array = Utf8Array::<i32>::from([Some("a\na"), None]);

let expected = r#"["a\na",null]"#;

Expand All @@ -352,7 +352,7 @@ fn escaped_end_of_line_in_utf8() -> Result<()> {

#[test]
fn escaped_quotation_marks_in_utf8() -> Result<()> {
let array = Utf8Array::<i32>::from(&vec![Some("a\"a"), None]);
let array = Utf8Array::<i32>::from([Some("a\"a"), None]);

let expected = r#"["a\"a",null]"#;

Expand Down
4 changes: 2 additions & 2 deletions tests/it/io/ndjson/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn case_struct() -> (String, Box<dyn Array>) {
let fields = vec![a_field];

// build expected output
let d = Utf8Array::<i32>::from(&vec![Some("text"), None, Some("text"), None]);
let d = Utf8Array::<i32>::from([Some("text"), None, Some("text"), None]);
let c = StructArray::new(
DataType::Struct(vec![d_field]),
vec![d.boxed()],
Expand Down Expand Up @@ -247,7 +247,7 @@ fn case_nested_list() -> (String, Box<dyn Array>) {
"#.to_string();

// build expected output
let d = Utf8Array::<i32>::from(&vec![
let d = Utf8Array::<i32>::from([
Some("a_text"),
Some("b_text"),
None,
Expand Down
8 changes: 4 additions & 4 deletions tests/it/io/parquet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box<dyn Array> {
[""],
]
*/
"list_utf8" => Box::new(Utf8Array::<i32>::from(&[
"list_utf8" => Box::new(Utf8Array::<i32>::from([
Some("Hello".to_string()),
Some("bbb".to_string()),
Some("aa".to_string()),
Expand All @@ -185,7 +185,7 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box<dyn Array> {
Some("bbb".to_string()),
Some("".to_string()),
])),
"list_large_binary" => Box::new(BinaryArray::<i64>::from(&[
"list_large_binary" => Box::new(BinaryArray::<i64>::from([
Some(b"Hello".to_vec()),
Some(b"bbb".to_vec()),
Some(b"aa".to_vec()),
Expand Down Expand Up @@ -334,7 +334,7 @@ pub fn pyarrow_nullable(column: &str) -> Box<dyn Array> {
None,
Some(9.0),
])),
"string" => Box::new(Utf8Array::<i32>::from(&[
"string" => Box::new(Utf8Array::<i32>::from([
Some("Hello".to_string()),
None,
Some("aa".to_string()),
Expand All @@ -346,7 +346,7 @@ pub fn pyarrow_nullable(column: &str) -> Box<dyn Array> {
Some("def".to_string()),
Some("aaa".to_string()),
])),
"bool" => Box::new(BooleanArray::from(&[
"bool" => Box::new(BooleanArray::from([
Some(true),
None,
Some(false),
Expand Down

0 comments on commit fc1d907

Please sign in to comment.