Skip to content

Commit 15cd35a

Browse files
committed
Use a single session and ExecutionCtx per touched test
Consolidate the validity/scalar checks in the tests updated by the `execute_is_valid` migration so each test creates one execution context and reuses it, instead of constructing a fresh `LEGACY_SESSION` context per call (some inside loops). Also unify the ALP sliced-vector test on a single `SESSION` context for both encode and execute, rather than mixing `SESSION` and `LEGACY_SESSION`. Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 4624ef6 commit 15cd35a

6 files changed

Lines changed: 61 additions & 60 deletions

File tree

encodings/alp/src/alp/array.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,19 +695,14 @@ mod tests {
695695
})
696696
.collect();
697697

698+
let mut ctx = SESSION.create_execution_ctx();
698699
let array = PrimitiveArray::from_option_iter(values.clone());
699-
let encoded = alp_encode(
700-
array.as_view(),
701-
None,
702-
&mut LEGACY_SESSION.create_execution_ctx(),
703-
)
704-
.unwrap();
700+
let encoded = alp_encode(array.as_view(), None, &mut ctx).unwrap();
705701

706702
let slice_end = size - slice_start;
707703
let slice_len = slice_end - slice_start;
708704
let sliced_encoded = encoded.slice(slice_start..slice_end).unwrap();
709705

710-
let mut ctx = SESSION.create_execution_ctx();
711706
let result_canonical = sliced_encoded.execute::<Canonical>(&mut ctx).unwrap();
712707
let result_primitive = result_canonical.into_primitive();
713708

vortex-array/src/builders/fixed_size_list.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ mod tests {
443443

444444
#[test]
445445
fn test_nullable_lists_non_nullable_elements() {
446+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
446447
let dtype: Arc<DType> = Arc::new(DType::Primitive(I32, NonNullable));
447448
let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 2, Nullable, 0);
448449

@@ -474,21 +475,21 @@ mod tests {
474475
fsl_array
475476
.validity()
476477
.vortex_expect("fixed-size-list validity should be derivable")
477-
.execute_is_valid(0, &mut LEGACY_SESSION.create_execution_ctx())
478+
.execute_is_valid(0, &mut ctx)
478479
.unwrap()
479480
);
480481
assert!(
481482
!fsl_array
482483
.validity()
483484
.vortex_expect("fixed-size-list validity should be derivable")
484-
.execute_is_valid(1, &mut LEGACY_SESSION.create_execution_ctx())
485+
.execute_is_valid(1, &mut ctx)
485486
.unwrap()
486487
);
487488
assert!(
488489
fsl_array
489490
.validity()
490491
.vortex_expect("fixed-size-list validity should be derivable")
491-
.execute_is_valid(2, &mut LEGACY_SESSION.create_execution_ctx())
492+
.execute_is_valid(2, &mut ctx)
492493
.unwrap()
493494
);
494495
}
@@ -561,6 +562,7 @@ mod tests {
561562

562563
#[test]
563564
fn test_append_nulls() {
565+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
564566
// Elements must be nullable if we're going to append null lists
565567
let dtype: Arc<DType> = Arc::new(DType::Primitive(I32, Nullable));
566568
let mut builder = FixedSizeListBuilder::with_capacity(dtype, 2, Nullable, 0);
@@ -582,14 +584,15 @@ mod tests {
582584
!fsl_array
583585
.validity()
584586
.vortex_expect("fixed-size-list validity should be derivable")
585-
.execute_is_valid(i, &mut LEGACY_SESSION.create_execution_ctx())
587+
.execute_is_valid(i, &mut ctx)
586588
.unwrap()
587589
);
588590
}
589591
}
590592

591593
#[test]
592594
fn test_append_scalar_nulls() {
595+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
593596
// Elements must be nullable if we're going to append null lists
594597
let dtype: Arc<DType> = Arc::new(DType::Primitive(I32, Nullable));
595598
let mut builder = FixedSizeListBuilder::with_capacity(dtype, 2, Nullable, 0);
@@ -612,7 +615,7 @@ mod tests {
612615
!fsl_array
613616
.validity()
614617
.vortex_expect("fixed-size-list validity should be derivable")
615-
.execute_is_valid(0, &mut LEGACY_SESSION.create_execution_ctx())
618+
.execute_is_valid(0, &mut ctx)
616619
.unwrap()
617620
);
618621
}
@@ -662,6 +665,7 @@ mod tests {
662665

663666
#[test]
664667
fn test_extend_from_array() {
668+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
665669
let dtype: Arc<DType> = Arc::new(I32.into());
666670

667671
// Create a source array.
@@ -690,48 +694,49 @@ mod tests {
690694
fsl_array
691695
.validity()
692696
.vortex_expect("fixed-size-list validity should be derivable")
693-
.execute_is_valid(0, &mut LEGACY_SESSION.create_execution_ctx())
697+
.execute_is_valid(0, &mut ctx)
694698
.unwrap()
695699
);
696700
assert!(
697701
!fsl_array
698702
.validity()
699703
.vortex_expect("fixed-size-list validity should be derivable")
700-
.execute_is_valid(1, &mut LEGACY_SESSION.create_execution_ctx())
704+
.execute_is_valid(1, &mut ctx)
701705
.unwrap()
702706
);
703707
assert!(
704708
fsl_array
705709
.validity()
706710
.vortex_expect("fixed-size-list validity should be derivable")
707-
.execute_is_valid(2, &mut LEGACY_SESSION.create_execution_ctx())
711+
.execute_is_valid(2, &mut ctx)
708712
.unwrap()
709713
);
710714
assert!(
711715
fsl_array
712716
.validity()
713717
.vortex_expect("fixed-size-list validity should be derivable")
714-
.execute_is_valid(3, &mut LEGACY_SESSION.create_execution_ctx())
718+
.execute_is_valid(3, &mut ctx)
715719
.unwrap()
716720
);
717721
assert!(
718722
!fsl_array
719723
.validity()
720724
.vortex_expect("fixed-size-list validity should be derivable")
721-
.execute_is_valid(4, &mut LEGACY_SESSION.create_execution_ctx())
725+
.execute_is_valid(4, &mut ctx)
722726
.unwrap()
723727
);
724728
assert!(
725729
fsl_array
726730
.validity()
727731
.vortex_expect("fixed-size-list validity should be derivable")
728-
.execute_is_valid(5, &mut LEGACY_SESSION.create_execution_ctx())
732+
.execute_is_valid(5, &mut ctx)
729733
.unwrap()
730734
);
731735
}
732736

733737
#[test]
734738
fn test_extend_degenerate_arrays() {
739+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
735740
let dtype: Arc<DType> = Arc::new(I32.into());
736741

737742
// Create degenerate source arrays (size = 0).
@@ -767,35 +772,35 @@ mod tests {
767772
fsl_array
768773
.validity()
769774
.vortex_expect("fixed-size-list validity should be derivable")
770-
.execute_is_valid(0, &mut LEGACY_SESSION.create_execution_ctx())
775+
.execute_is_valid(0, &mut ctx)
771776
.unwrap()
772777
);
773778
assert!(
774779
!fsl_array
775780
.validity()
776781
.vortex_expect("fixed-size-list validity should be derivable")
777-
.execute_is_valid(1, &mut LEGACY_SESSION.create_execution_ctx())
782+
.execute_is_valid(1, &mut ctx)
778783
.unwrap()
779784
);
780785
assert!(
781786
fsl_array
782787
.validity()
783788
.vortex_expect("fixed-size-list validity should be derivable")
784-
.execute_is_valid(2, &mut LEGACY_SESSION.create_execution_ctx())
789+
.execute_is_valid(2, &mut ctx)
785790
.unwrap()
786791
);
787792
assert!(
788793
!fsl_array
789794
.validity()
790795
.vortex_expect("fixed-size-list validity should be derivable")
791-
.execute_is_valid(3, &mut LEGACY_SESSION.create_execution_ctx())
796+
.execute_is_valid(3, &mut ctx)
792797
.unwrap()
793798
);
794799
assert!(
795800
fsl_array
796801
.validity()
797802
.vortex_expect("fixed-size-list validity should be derivable")
798-
.execute_is_valid(4, &mut LEGACY_SESSION.create_execution_ctx())
803+
.execute_is_valid(4, &mut ctx)
799804
.unwrap()
800805
);
801806
}
@@ -836,6 +841,7 @@ mod tests {
836841

837842
#[test]
838843
fn test_mixed_operations() {
844+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
839845
// Use nullable elements since we'll be appending nulls
840846
let dtype: Arc<DType> = Arc::new(DType::Primitive(I32, Nullable));
841847
let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 2, Nullable, 0);
@@ -879,48 +885,49 @@ mod tests {
879885
fsl_array
880886
.validity()
881887
.vortex_expect("fixed-size-list validity should be derivable")
882-
.execute_is_valid(0, &mut LEGACY_SESSION.create_execution_ctx())
888+
.execute_is_valid(0, &mut ctx)
883889
.unwrap()
884890
); // append_value
885891
assert!(
886892
!fsl_array
887893
.validity()
888894
.vortex_expect("fixed-size-list validity should be derivable")
889-
.execute_is_valid(1, &mut LEGACY_SESSION.create_execution_ctx())
895+
.execute_is_valid(1, &mut ctx)
890896
.unwrap()
891897
); // append_null
892898
assert!(
893899
fsl_array
894900
.validity()
895901
.vortex_expect("fixed-size-list validity should be derivable")
896-
.execute_is_valid(2, &mut LEGACY_SESSION.create_execution_ctx())
902+
.execute_is_valid(2, &mut ctx)
897903
.unwrap()
898904
); // append_zeros
899905
assert!(
900906
fsl_array
901907
.validity()
902908
.vortex_expect("fixed-size-list validity should be derivable")
903-
.execute_is_valid(3, &mut LEGACY_SESSION.create_execution_ctx())
909+
.execute_is_valid(3, &mut ctx)
904910
.unwrap()
905911
); // append_zeros
906912
assert!(
907913
!fsl_array
908914
.validity()
909915
.vortex_expect("fixed-size-list validity should be derivable")
910-
.execute_is_valid(4, &mut LEGACY_SESSION.create_execution_ctx())
916+
.execute_is_valid(4, &mut ctx)
911917
.unwrap()
912918
); // append_nulls
913919
assert!(
914920
fsl_array
915921
.validity()
916922
.vortex_expect("fixed-size-list validity should be derivable")
917-
.execute_is_valid(5, &mut LEGACY_SESSION.create_execution_ctx())
923+
.execute_is_valid(5, &mut ctx)
918924
.unwrap()
919925
); // extend_from_array
920926
}
921927

922928
#[test]
923929
fn test_append_scalar() {
930+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
924931
let dtype: Arc<DType> = Arc::new(I32.into());
925932
let mut builder = FixedSizeListBuilder::with_capacity(Arc::clone(&dtype), 2, Nullable, 10);
926933

@@ -942,19 +949,15 @@ mod tests {
942949

943950
// Check actual values using scalar_at.
944951

945-
let scalar0 = array
946-
.execute_scalar(0, &mut LEGACY_SESSION.create_execution_ctx())
947-
.unwrap();
952+
let scalar0 = array.execute_scalar(0, &mut ctx).unwrap();
948953
let list0 = scalar0.as_list();
949954
assert_eq!(list0.len(), 2);
950955
if let Some(list0_items) = list0.elements() {
951956
assert_eq!(list0_items[0].as_primitive().typed_value::<i32>(), Some(1));
952957
assert_eq!(list0_items[1].as_primitive().typed_value::<i32>(), Some(2));
953958
}
954959

955-
let scalar1 = array
956-
.execute_scalar(1, &mut LEGACY_SESSION.create_execution_ctx())
957-
.unwrap();
960+
let scalar1 = array.execute_scalar(1, &mut ctx).unwrap();
958961
let list1 = scalar1.as_list();
959962
assert_eq!(list1.len(), 2);
960963
if let Some(list1_items) = list1.elements() {
@@ -967,21 +970,21 @@ mod tests {
967970
array
968971
.validity()
969972
.vortex_expect("fixed-size-list validity should be derivable")
970-
.execute_is_valid(0, &mut LEGACY_SESSION.create_execution_ctx())
973+
.execute_is_valid(0, &mut ctx)
971974
.unwrap()
972975
);
973976
assert!(
974977
array
975978
.validity()
976979
.vortex_expect("fixed-size-list validity should be derivable")
977-
.execute_is_valid(1, &mut LEGACY_SESSION.create_execution_ctx())
980+
.execute_is_valid(1, &mut ctx)
978981
.unwrap()
979982
);
980983
assert!(
981984
!array
982985
.validity()
983986
.vortex_expect("fixed-size-list validity should be derivable")
984-
.execute_is_valid(2, &mut LEGACY_SESSION.create_execution_ctx())
987+
.execute_is_valid(2, &mut ctx)
985988
.unwrap()
986989
);
987990

vortex-array/src/builders/list.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -579,21 +579,19 @@ mod tests {
579579
let array = builder.finish_into_list();
580580
assert_eq!(array.len(), 3);
581581

582+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
583+
582584
// Check actual values using scalar_at.
583585

584-
let scalar0 = array
585-
.execute_scalar(0, &mut LEGACY_SESSION.create_execution_ctx())
586-
.unwrap();
586+
let scalar0 = array.execute_scalar(0, &mut ctx).unwrap();
587587
let list0 = scalar0.as_list();
588588
assert_eq!(list0.len(), 2);
589589
if let Some(list0_items) = list0.elements() {
590590
assert_eq!(list0_items[0].as_primitive().typed_value::<i32>(), Some(1));
591591
assert_eq!(list0_items[1].as_primitive().typed_value::<i32>(), Some(2));
592592
}
593593

594-
let scalar1 = array
595-
.execute_scalar(1, &mut LEGACY_SESSION.create_execution_ctx())
596-
.unwrap();
594+
let scalar1 = array.execute_scalar(1, &mut ctx).unwrap();
597595
let list1 = scalar1.as_list();
598596
assert_eq!(list1.len(), 3);
599597
if let Some(list1_items) = list1.elements() {
@@ -602,9 +600,7 @@ mod tests {
602600
assert_eq!(list1_items[2].as_primitive().typed_value::<i32>(), Some(5));
603601
}
604602

605-
let scalar2 = array
606-
.execute_scalar(2, &mut LEGACY_SESSION.create_execution_ctx())
607-
.unwrap();
603+
let scalar2 = array.execute_scalar(2, &mut ctx).unwrap();
608604
let list2 = scalar2.as_list();
609605
assert!(list2.is_null()); // This should be null.
610606

@@ -613,21 +609,21 @@ mod tests {
613609
array
614610
.validity()
615611
.vortex_expect("list validity should be derivable")
616-
.execute_is_valid(0, &mut LEGACY_SESSION.create_execution_ctx())
612+
.execute_is_valid(0, &mut ctx)
617613
.unwrap()
618614
);
619615
assert!(
620616
array
621617
.validity()
622618
.vortex_expect("list validity should be derivable")
623-
.execute_is_valid(1, &mut LEGACY_SESSION.create_execution_ctx())
619+
.execute_is_valid(1, &mut ctx)
624620
.unwrap()
625621
);
626622
assert!(
627623
!array
628624
.validity()
629625
.vortex_expect("list validity should be derivable")
630-
.execute_is_valid(2, &mut LEGACY_SESSION.create_execution_ctx())
626+
.execute_is_valid(2, &mut ctx)
631627
.unwrap()
632628
);
633629

0 commit comments

Comments
 (0)