Skip to content

Commit 7571adf

Browse files
committed
test(array): create Decimal and wide integer sessions per test
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 596abbd commit 7571adf

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

‎vortex-array/src/arrays/decimal/tests.rs‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::ArrayPlugin;
1818
use crate::ArrayRef;
1919
use crate::IntoArray;
2020
use crate::RecursiveCanonical;
21-
use crate::TEST_SESSION;
2221
use crate::VTable;
2322
use crate::VortexSessionExecute;
2423
use crate::aggregate_fn::AggregateFnVTableExt;
@@ -32,6 +31,7 @@ use crate::aggregate_fn::fns::min_max::MinMax;
3231
use crate::aggregate_fn::fns::min_max::min_max;
3332
use crate::aggregate_fn::fns::sum::Sum;
3433
use crate::aggregate_fn::session::AggregateFnSessionExt;
34+
use crate::array_session;
3535
use crate::arrays::BoolArray;
3636
use crate::arrays::ConstantArray;
3737
use crate::arrays::DictArray;
@@ -92,7 +92,7 @@ fn rejects_wrong_logical_child_dtype() {
9292
#[case::i128_to_i64(DecimalArray::from_iter([i128::MAX], DecimalDType::new(10, 0)))]
9393
#[case::i256_to_i128(DecimalArray::from_iter([i256::from_parts(0, 1)], DecimalDType::new(38, 0)))]
9494
fn wider_native_input_cast_checks_overflow(#[case] array: DecimalArray) {
95-
let mut ctx = TEST_SESSION.create_execution_ctx();
95+
let mut ctx = array_session().create_execution_ctx();
9696
let err = array.materialize_values(&mut ctx).unwrap_err();
9797
assert!(
9898
err.to_string().contains("Integer does not fit"),
@@ -102,7 +102,7 @@ fn wider_native_input_cast_checks_overflow(#[case] array: DecimalArray) {
102102

103103
#[test]
104104
fn wider_native_input_materializes_at_logical_width() -> VortexResult<()> {
105-
let mut ctx = TEST_SESSION.create_execution_ctx();
105+
let mut ctx = array_session().create_execution_ctx();
106106
let dtype = DecimalDType::new(10, 2);
107107
let array = DecimalArray::from_iter([0i128, 1, -2], dtype).materialize_values(&mut ctx)?;
108108
assert_eq!(array.values_type(), DecimalType::I64);
@@ -121,7 +121,7 @@ fn wider_native_input_materializes_at_logical_width() -> VortexResult<()> {
121121
#[case::wide(DecimalArray::from_iter([-1i128, 1], DecimalDType::new(38, 0)))]
122122
#[case::narrow_wide(DecimalArray::from_option_iter([Some(-1i128), None], DecimalDType::new(76, 0)))]
123123
fn materialization_reuses_native_children(#[case] array: DecimalArray) -> VortexResult<()> {
124-
let mut ctx = TEST_SESSION.create_execution_ctx();
124+
let mut ctx = array_session().create_execution_ctx();
125125
let materialized = array.materialize_values(&mut ctx)?;
126126
assert!(ArrayRef::ptr_eq(array.as_ref(), materialized.as_ref()));
127127

@@ -130,7 +130,7 @@ fn materialization_reuses_native_children(#[case] array: DecimalArray) -> Vortex
130130

131131
#[test]
132132
fn canonicalization_preserves_encoded_child() -> VortexResult<()> {
133-
let mut ctx = TEST_SESSION.create_execution_ctx();
133+
let mut ctx = array_session().create_execution_ctx();
134134
let dtype = DecimalDType::new(76, 2);
135135
let dictionary = DictArray::try_new(
136136
buffer![0u8, 1, 0, 1].into_array(),
@@ -178,7 +178,7 @@ fn canonicalization_preserves_encoded_child() -> VortexResult<()> {
178178

179179
#[test]
180180
fn wide_patch_widens_storage() -> VortexResult<()> {
181-
let mut ctx = TEST_SESSION.create_execution_ctx();
181+
let mut ctx = array_session().create_execution_ctx();
182182
let dtype = DecimalDType::new(39, 0);
183183
let value = 1i128 << 100;
184184
let patches = Patches::new(
@@ -207,7 +207,7 @@ fn wide_patch_widens_storage() -> VortexResult<()> {
207207
#[case::nonnullable(Nullability::NonNullable)]
208208
#[case::nullable(Nullability::Nullable)]
209209
fn fill_null_accepts_a_wider_logical_value(#[case] nullability: Nullability) -> VortexResult<()> {
210-
let mut ctx = TEST_SESSION.create_execution_ctx();
210+
let mut ctx = array_session().create_execution_ctx();
211211
let dtype = DecimalDType::new(39, 0);
212212
let value = 1i128 << 100;
213213
let array = DecimalArray::from_option_iter([Some(1i8), None, Some(-2)], dtype);
@@ -241,7 +241,7 @@ fn nonnullable_cast_checks_encoded_child_validity(
241241
#[case] precision: u8,
242242
#[values(true, false)] second_valid: bool,
243243
) -> VortexResult<()> {
244-
let mut ctx = TEST_SESSION.create_execution_ctx();
244+
let mut ctx = array_session().create_execution_ctx();
245245
let source = DecimalDType::new(39, 2);
246246
let target = DecimalDType::new(precision, 2);
247247
let dictionary = DictArray::try_new(
@@ -282,7 +282,7 @@ fn precision_widening_cast_preserves_encoded_child(
282282
#[case] precision: u8,
283283
#[case] width: DecimalType,
284284
) -> VortexResult<()> {
285-
let mut ctx = TEST_SESSION.create_execution_ctx();
285+
let mut ctx = array_session().create_execution_ctx();
286286
let dictionary = DictArray::try_new(
287287
buffer![0u8, 1, 0].into_array(),
288288
buffer![1i32, -2].into_array(),
@@ -319,7 +319,7 @@ fn precision_widening_cast_preserves_encoded_child(
319319

320320
#[test]
321321
fn aggregates_and_comparisons_keep_decimal_semantics() -> VortexResult<()> {
322-
let mut ctx = TEST_SESSION.create_execution_ctx();
322+
let mut ctx = array_session().create_execution_ctx();
323323
let dtype = DecimalDType::new(39, 2);
324324
let array = DecimalArray::from_iter([-128i8, -1, 0, 127], dtype).into_array();
325325
let bounds = min_max(&array, &mut ctx, NumericalAggregateOpts::default())?
@@ -354,7 +354,7 @@ fn between_outside_storage_range_preserves_nulls(
354354
#[case] lower: i128,
355355
#[case] upper: i128,
356356
) -> VortexResult<()> {
357-
let mut ctx = TEST_SESSION.create_execution_ctx();
357+
let mut ctx = array_session().create_execution_ctx();
358358
let dtype = DecimalDType::new(39, 0);
359359
let array = DecimalArray::from_option_iter([Some(-1i8), None, Some(1)], dtype);
360360
let bound = |value| {
@@ -384,7 +384,8 @@ fn between_outside_storage_range_preserves_nulls(
384384

385385
#[test]
386386
fn partial_aggregates_preserve_decimal_boundaries() -> VortexResult<()> {
387-
let mut ctx = TEST_SESSION.create_execution_ctx();
387+
let session = array_session();
388+
let mut ctx = session.create_execution_ctx();
388389
let dtype = DecimalDType::new(76, 2);
389390
let input_dtype = DType::Decimal(dtype, Nullability::Nullable);
390391
for aggregate in [
@@ -393,7 +394,7 @@ fn partial_aggregates_preserve_decimal_boundaries() -> VortexResult<()> {
393394
IsConstant.bind(EmptyOptions),
394395
] {
395396
assert!(
396-
TEST_SESSION
397+
session
397398
.aggregate_fns()
398399
.find_aggregate_kernel(VTable::id(&Decimal), aggregate.id())
399400
.is_some()
@@ -421,11 +422,12 @@ fn partial_aggregates_preserve_decimal_boundaries() -> VortexResult<()> {
421422

422423
#[test]
423424
fn sum_uses_the_decimal_kernel() -> VortexResult<()> {
424-
let mut ctx = TEST_SESSION.create_execution_ctx();
425+
let session = array_session();
426+
let mut ctx = session.create_execution_ctx();
425427
let dtype = DecimalDType::new(39, 2);
426428
let array = DecimalArray::from_iter([10i8, 20], dtype).into_array();
427429
let aggregate = Sum.bind(NumericalAggregateOpts::default());
428-
let kernel = TEST_SESSION
430+
let kernel = session
429431
.aggregate_fns()
430432
.find_aggregate_kernel(VTable::id(&Decimal), aggregate.id())
431433
.vortex_expect("Decimal registers a fallback aggregate kernel");
@@ -447,7 +449,7 @@ fn sum_uses_the_decimal_kernel() -> VortexResult<()> {
447449

448450
#[test]
449451
fn legacy_wire_keeps_narrow_storage() -> VortexResult<()> {
450-
let session = &TEST_SESSION;
452+
let session = &array_session();
451453
let array =
452454
DecimalArray::from_option_iter([Some(10i32), None, Some(-20)], DecimalDType::new(76, 2))
453455
.into_array();

‎vortex-array/src/arrays/decimal/vtable/operations.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ mod tests {
3434
use vortex_buffer::buffer;
3535

3636
use crate::IntoArray;
37-
use crate::TEST_SESSION;
3837
use crate::VortexSessionExecute;
38+
use crate::array_session;
3939
use crate::arrays::Decimal;
4040
use crate::arrays::DecimalArray;
4141
use crate::arrays::decimal::DecimalArrayExt;
@@ -59,7 +59,7 @@ mod tests {
5959

6060
let decimal = sliced
6161
.as_::<Decimal>()
62-
.materialize_values(&mut TEST_SESSION.create_execution_ctx())
62+
.materialize_values(&mut array_session().create_execution_ctx())
6363
.unwrap();
6464
assert_eq!(decimal.buffer::<i16>(), buffer![200i16, 300i16]);
6565
}
@@ -87,7 +87,7 @@ mod tests {
8787

8888
assert_eq!(
8989
array
90-
.execute_scalar(0, &mut TEST_SESSION.create_execution_ctx())
90+
.execute_scalar(0, &mut array_session().create_execution_ctx())
9191
.unwrap(),
9292
Scalar::decimal(
9393
DecimalValue::I128(100),

‎vortex-array/src/arrays/wide_integer/tests.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use vortex_error::VortexResult;
88

99
use super::WideIntegerArray;
1010
use crate::IntoArray;
11-
use crate::TEST_SESSION;
1211
use crate::VortexSessionExecute;
1312
use crate::aggregate_fn::NumericalAggregateOpts;
1413
use crate::aggregate_fn::fns::is_sorted::is_sorted;
1514
use crate::aggregate_fn::fns::min_max::min_max;
15+
use crate::array_session;
1616
use crate::arrays::BoolArray;
1717
use crate::arrays::Narrow;
1818
use crate::arrays::NarrowArray;
@@ -35,7 +35,7 @@ use crate::validity::Validity;
3535
#[case::i128(DecimalType::I128)]
3636
#[case::i256(DecimalType::I256)]
3737
fn test_signed_order_and_full_integer_range(#[case] width: DecimalType) -> VortexResult<()> {
38-
let mut ctx = TEST_SESSION.create_execution_ctx();
38+
let mut ctx = array_session().create_execution_ctx();
3939
let values = if width == DecimalType::I128 {
4040
WideIntegerArray::try_new(
4141
buffer![i128::MIN, -256, -1, 0, 255, 256, i128::MAX],
@@ -75,7 +75,7 @@ fn test_signed_order_and_full_integer_range(#[case] width: DecimalType) -> Vorte
7575

7676
#[test]
7777
fn test_narrowing_ignores_invalid_wide_payloads() -> VortexResult<()> {
78-
let mut ctx = TEST_SESSION.create_execution_ctx();
78+
let mut ctx = array_session().create_execution_ctx();
7979
let values = WideIntegerArray::try_new(
8080
buffer![127i128, i128::MIN, -128],
8181
Validity::from_iter([true, false, true]),
@@ -97,7 +97,7 @@ fn test_narrowing_ignores_invalid_wide_payloads() -> VortexResult<()> {
9797

9898
#[test]
9999
fn test_integer_cast_checks_valid_lanes() -> VortexResult<()> {
100-
let mut ctx = TEST_SESSION.create_execution_ctx();
100+
let mut ctx = array_session().create_execution_ctx();
101101
let values = WideIntegerArray::try_new(
102102
buffer![127i128, i128::MIN],
103103
Validity::from_iter([true, false]),

0 commit comments

Comments
 (0)