Skip to content

Commit 4430409

Browse files
tustvoldalamb
authored andcommitted
ARROW-12400: [Rust] Re-enable tests in arrow::array::transform
These tests were all commented out in #9329. Given the PR made changes to the commented out code, I'm inclined to think this was an accidental omission? If not, happy for this to be closed 😀 FYI @jorgecarleitao Signed-off-by: Raphael Taylor-Davies <[email protected]> Closes #10048 from tustvold/enable-transform-tests Authored-by: Raphael Taylor-Davies <[email protected]> Signed-off-by: Andrew Lamb <[email protected]>
1 parent 4122ff2 commit 4430409

File tree

1 file changed

+46
-63
lines changed
  • rust/arrow/src/array/transform

1 file changed

+46
-63
lines changed

rust/arrow/src/array/transform/mod.rs

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ impl<'a> MutableArrayData<'a> {
398398
}
399399
}
400400

401-
/*
402401
#[cfg(test)]
403402
mod tests {
404403
use std::{convert::TryFrom, sync::Arc};
@@ -424,8 +423,7 @@ mod tests {
424423
#[test]
425424
fn test_primitive() {
426425
let b = UInt8Array::from(vec![Some(1), Some(2), Some(3)]);
427-
let b = b.data();
428-
let arrays = vec![b];
426+
let arrays = vec![b.data()];
429427
let mut a = MutableArrayData::new(arrays, false, 3);
430428
a.extend(0, 0, 2);
431429
let result = a.freeze();
@@ -439,8 +437,7 @@ mod tests {
439437
fn test_primitive_offset() {
440438
let b = UInt8Array::from(vec![Some(1), Some(2), Some(3)]);
441439
let b = b.slice(1, 2);
442-
let b = b.data();
443-
let arrays = vec![b];
440+
let arrays = vec![b.data()];
444441
let mut a = MutableArrayData::new(arrays, false, 2);
445442
a.extend(0, 0, 2);
446443
let result = a.freeze();
@@ -453,8 +450,8 @@ mod tests {
453450
#[test]
454451
fn test_primitive_null_offset() {
455452
let b = UInt8Array::from(vec![Some(1), None, Some(3)]);
456-
let b = b.slice(1, 2).data();
457-
let arrays = vec![b];
453+
let b = b.slice(1, 2);
454+
let arrays = vec![b.data()];
458455
let mut a = MutableArrayData::new(arrays, false, 2);
459456
a.extend(0, 0, 2);
460457
let result = a.freeze();
@@ -466,8 +463,8 @@ mod tests {
466463
#[test]
467464
fn test_primitive_null_offset_nulls() {
468465
let b = UInt8Array::from(vec![Some(1), Some(2), Some(3)]);
469-
let b = b.slice(1, 2).data();
470-
let arrays = vec![b];
466+
let b = b.slice(1, 2);
467+
let arrays = vec![b.data()];
471468
let mut a = MutableArrayData::new(arrays, true, 2);
472469
a.extend(0, 0, 2);
473470
a.extend_nulls(3);
@@ -489,8 +486,8 @@ mod tests {
489486
builder.append(true)?;
490487
builder.values().append_slice(&[6, 7, 8])?;
491488
builder.append(true)?;
492-
let array = builder.finish().data();
493-
let arrays = vec![array];
489+
let array = builder.finish();
490+
let arrays = vec![array.data()];
494491

495492
let mut mutable = MutableArrayData::new(arrays, false, 0);
496493
mutable.extend(0, 0, 1);
@@ -512,9 +509,8 @@ mod tests {
512509
/// tests extending from a variable-sized (strings and binary) array w/ offset with nulls
513510
#[test]
514511
fn test_variable_sized_nulls() {
515-
let array =
516-
StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]).data();
517-
let arrays = vec![array];
512+
let array = StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]);
513+
let arrays = vec![array.data()];
518514

519515
let mut mutable = MutableArrayData::new(arrays, false, 0);
520516

@@ -531,11 +527,10 @@ mod tests {
531527
/// with an offset and nulls
532528
#[test]
533529
fn test_variable_sized_offsets() {
534-
let array =
535-
StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]).data();
530+
let array = StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]);
536531
let array = array.slice(1, 3);
537532

538-
let arrays = vec![&array];
533+
let arrays = vec![array.data()];
539534

540535
let mut mutable = MutableArrayData::new(arrays, false, 0);
541536

@@ -550,11 +545,10 @@ mod tests {
550545

551546
#[test]
552547
fn test_string_offsets() {
553-
let array =
554-
StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]).data();
548+
let array = StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]);
555549
let array = array.slice(1, 3);
556550

557-
let arrays = vec![&array];
551+
let arrays = vec![array.data()];
558552

559553
let mut mutable = MutableArrayData::new(arrays, false, 0);
560554

@@ -569,10 +563,10 @@ mod tests {
569563

570564
#[test]
571565
fn test_multiple_with_nulls() {
572-
let array1 = StringArray::from(vec!["hello", "world"]).data();
573-
let array2 = StringArray::from(vec![Some("1"), None]).data();
566+
let array1 = StringArray::from(vec!["hello", "world"]);
567+
let array2 = StringArray::from(vec![Some("1"), None]);
574568

575-
let arrays = vec![array1, array2];
569+
let arrays = vec![array1.data(), array2.data()];
576570

577571
let mut mutable = MutableArrayData::new(arrays, false, 5);
578572

@@ -589,11 +583,10 @@ mod tests {
589583

590584
#[test]
591585
fn test_string_null_offset_nulls() {
592-
let array =
593-
StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]).data();
586+
let array = StringArray::from(vec![Some("a"), Some("bc"), None, Some("defh")]);
594587
let array = array.slice(1, 3);
595588

596-
let arrays = vec![&array];
589+
let arrays = vec![array.data()];
597590

598591
let mut mutable = MutableArrayData::new(arrays, true, 0);
599592

@@ -609,9 +602,8 @@ mod tests {
609602

610603
#[test]
611604
fn test_bool() {
612-
let array =
613-
BooleanArray::from(vec![Some(false), Some(true), None, Some(false)]).data();
614-
let arrays = vec![array];
605+
let array = BooleanArray::from(vec![Some(false), Some(true), None, Some(false)]);
606+
let arrays = vec![array.data()];
615607

616608
let mut mutable = MutableArrayData::new(arrays, false, 0);
617609

@@ -626,9 +618,9 @@ mod tests {
626618

627619
#[test]
628620
fn test_null() {
629-
let array1 = NullArray::new(10).data();
630-
let array2 = NullArray::new(5).data();
631-
let arrays = vec![array1, array2];
621+
let array1 = NullArray::new(10);
622+
let array2 = NullArray::new(5);
623+
let arrays = vec![array1.data(), array2.data()];
632624

633625
let mut mutable = MutableArrayData::new(arrays, false, 0);
634626

@@ -698,9 +690,8 @@ mod tests {
698690

699691
let array =
700692
StructArray::try_from(vec![("f1", strings.clone()), ("f2", ints.clone())])
701-
.unwrap()
702-
.data();
703-
let arrays = vec![array];
693+
.unwrap();
694+
let arrays = vec![array.data()];
704695
let mut mutable = MutableArrayData::new(arrays, false, 0);
705696

706697
mutable.extend(0, 1, 3);
@@ -735,14 +726,13 @@ mod tests {
735726
let array =
736727
StructArray::try_from(vec![("f1", strings.clone()), ("f2", ints.clone())])
737728
.unwrap()
738-
.slice(1, 3)
739-
.data();
740-
let arrays = vec![array.as_ref()];
729+
.slice(1, 3);
730+
let arrays = vec![array.data()];
741731
let mut mutable = MutableArrayData::new(arrays, false, 0);
742732

743733
mutable.extend(0, 1, 3);
744734
let data = mutable.freeze();
745-
let array = StructArray::from(Arc::new(data));
735+
let array = StructArray::from(data);
746736

747737
let expected_strings: ArrayRef =
748738
Arc::new(StringArray::from(vec![None, Some("mark")]));
@@ -774,9 +764,8 @@ mod tests {
774764

775765
let array =
776766
StructArray::try_from(vec![("f1", strings.clone()), ("f2", ints.clone())])
777-
.unwrap()
778-
.data();
779-
let arrays = vec![array];
767+
.unwrap();
768+
let arrays = vec![array.data()];
780769

781770
let mut mutable = MutableArrayData::new(arrays, false, 0);
782771

@@ -812,9 +801,8 @@ mod tests {
812801

813802
let array =
814803
StructArray::try_from(vec![("f1", strings.clone()), ("f2", ints.clone())])
815-
.unwrap()
816-
.data();
817-
let arrays = vec![array, array];
804+
.unwrap();
805+
let arrays = vec![array.data(), array.data()];
818806
let mut mutable = MutableArrayData::new(arrays, false, 0);
819807

820808
mutable.extend(0, 1, 3);
@@ -838,12 +826,11 @@ mod tests {
838826
let array = FixedSizeBinaryArray::try_from_iter(
839827
vec![vec![0, 0], vec![0, 1], vec![0, 2]].into_iter(),
840828
)
841-
.expect("Failed to create FixedSizeBinaryArray from iterable")
842-
.data();
829+
.expect("Failed to create FixedSizeBinaryArray from iterable");
843830
let array = array.slice(1, 2);
844831
// = [[0, 1], [0, 2]] due to the offset = 1
845832

846-
let arrays = vec![&array];
833+
let arrays = vec![array.data()];
847834

848835
let mut mutable = MutableArrayData::new(arrays, false, 0);
849836

@@ -869,7 +856,7 @@ mod tests {
869856
builder.values().append_slice(&[6, 7, 8])?;
870857
builder.values().append_slice(&[9, 10, 11])?;
871858
builder.append(true)?;
872-
let a = builder.finish().data();
859+
let a = builder.finish();
873860

874861
let a_builder = Int64Builder::new(24);
875862
let mut a_builder = ListBuilder::<Int64Builder>::new(a_builder);
@@ -880,10 +867,10 @@ mod tests {
880867
a_builder.append(true)?;
881868
let b = a_builder.finish();
882869

883-
let b = b.data();
884870
let c = b.slice(1, 2);
885871

886-
let mut mutable = MutableArrayData::new(vec![a, b, &c], false, 1);
872+
let mut mutable =
873+
MutableArrayData::new(vec![a.data(), b.data(), c.data()], false, 1);
887874
mutable.extend(0, 0, a.len());
888875
mutable.extend(1, 0, b.len());
889876
mutable.extend(2, 0, c.len());
@@ -1016,7 +1003,7 @@ mod tests {
10161003
builder.values().append_value("Arrow")?;
10171004
builder.values().append_null()?;
10181005
builder.append(true)?;
1019-
let a = builder.finish().data();
1006+
let a = builder.finish();
10201007

10211008
// [["alpha", "beta"], [None], ["gamma", "delta", None]]
10221009
let mut builder = ListBuilder::new(StringBuilder::new(32));
@@ -1029,9 +1016,9 @@ mod tests {
10291016
builder.values().append_value("delta")?;
10301017
builder.values().append_null()?;
10311018
builder.append(true)?;
1032-
let b = builder.finish().data();
1019+
let b = builder.finish();
10331020

1034-
let mut mutable = MutableArrayData::new(vec![a, b], false, 10);
1021+
let mut mutable = MutableArrayData::new(vec![a.data(), b.data()], false, 10);
10351022

10361023
mutable.extend(0, 0, a.len());
10371024
mutable.extend(1, 0, b.len());
@@ -1082,8 +1069,7 @@ mod tests {
10821069
fn test_fixed_size_binary_append() {
10831070
let a = vec![Some(vec![1, 2]), Some(vec![3, 4]), Some(vec![5, 6])];
10841071
let a = FixedSizeBinaryArray::try_from_sparse_iter(a.into_iter())
1085-
.expect("Failed to create FixedSizeBinaryArray from iterable")
1086-
.data();
1072+
.expect("Failed to create FixedSizeBinaryArray from iterable");
10871073

10881074
let b = vec![
10891075
None,
@@ -1094,10 +1080,9 @@ mod tests {
10941080
None,
10951081
];
10961082
let b = FixedSizeBinaryArray::try_from_sparse_iter(b.into_iter())
1097-
.expect("Failed to create FixedSizeBinaryArray from iterable")
1098-
.data();
1083+
.expect("Failed to create FixedSizeBinaryArray from iterable");
10991084

1100-
let mut mutable = MutableArrayData::new(vec![a, b], false, 10);
1085+
let mut mutable = MutableArrayData::new(vec![a.data(), b.data()], false, 10);
11011086

11021087
mutable.extend(0, 0, a.len());
11031088
mutable.extend(1, 0, b.len());
@@ -1127,9 +1112,8 @@ mod tests {
11271112
// b[4..4]
11281113
];
11291114
let expected = FixedSizeBinaryArray::try_from_sparse_iter(expected.into_iter())
1130-
.expect("Failed to create FixedSizeBinaryArray from iterable")
1131-
.data();
1132-
assert_eq!(&result, expected.as_ref());
1115+
.expect("Failed to create FixedSizeBinaryArray from iterable");
1116+
assert_eq!(&result, expected.data());
11331117
}
11341118

11351119
/*
@@ -1220,4 +1204,3 @@ mod tests {
12201204
}
12211205
*/
12221206
}
1223-
*/

0 commit comments

Comments
 (0)