22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
44use std:: sync:: Arc ;
5+ use std:: sync:: LazyLock ;
56
67use rstest:: rstest;
78use vortex_buffer:: buffer;
89use vortex_error:: VortexResult ;
10+ use vortex_session:: VortexSession ;
911
1012use super :: ListTransform ;
1113use super :: ListTransformOptions ;
@@ -14,7 +16,6 @@ use crate::ArrayRef;
1416use crate :: IntoArray ;
1517use crate :: RecursiveCanonical ;
1618use crate :: VortexSessionExecute ;
17- use crate :: array_session;
1819use crate :: arrays:: BoolArray ;
1920use crate :: arrays:: Dict ;
2021use crate :: arrays:: DictArray ;
@@ -42,12 +43,13 @@ use crate::expr::list_transform;
4243use crate :: expr:: lit;
4344use crate :: expr:: proto:: ExprSerializeProtoExt ;
4445use crate :: expr:: root;
45- use crate :: expr:: transform:: replace;
4646use crate :: expr:: var;
4747use crate :: scalar:: Scalar ;
4848use crate :: scalar_fn:: ScalarFnVTable ;
4949use crate :: validity:: Validity ;
5050
51+ static SESSION : LazyLock < VortexSession > = LazyLock :: new ( VortexSession :: empty) ;
52+
5153/// `[[1, 2], null (hiding [i32::MAX]), [3, null]]`
5254fn lists ( ) -> VortexResult < ArrayRef > {
5355 list_of (
@@ -68,7 +70,7 @@ fn rows(l: ArrayRef) -> VortexResult<ArrayRef> {
6870}
6971
7072fn list_of ( values : ArrayRef , offsets : & [ u32 ] , validity : Validity ) -> VortexResult < ArrayRef > {
71- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
73+ let mut ctx = SESSION . create_execution_ctx ( ) ;
7274 Ok ( ListArray :: try_new (
7375 values,
7476 PrimitiveArray :: from_iter ( offsets. iter ( ) . copied ( ) ) . into_array ( ) ,
@@ -94,7 +96,7 @@ fn plus_one() -> VortexResult<Lambda> {
9496
9597fn assert_applies ( input : ArrayRef , expr : & Expression , expected : ArrayRef ) -> VortexResult < ( ) > {
9698 let actual = input. apply ( expr) ?;
97- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
99+ let mut ctx = SESSION . create_execution_ctx ( ) ;
98100 assert_arrays_eq ! ( actual, expected, & mut ctx) ;
99101 Ok ( ( ) )
100102}
@@ -160,7 +162,7 @@ fn sliced_list_with_leftovers() -> VortexResult<ArrayRef> {
160162
161163/// `[[1], [2]]` over `[MAX, 1, 2]`: the lists are back to back, after a leftover.
162164fn list_view_with_a_leftover_in_front ( ) -> VortexResult < ArrayRef > {
163- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
165+ let mut ctx = SESSION . create_execution_ctx ( ) ;
164166 let view = ListViewArray :: try_new (
165167 buffer ! [ i32 :: MAX , 1_i32 , 2 ] . into_array ( ) ,
166168 buffer ! [ 1_u32 , 2 ] . into_array ( ) ,
@@ -174,7 +176,7 @@ fn list_view_with_a_leftover_in_front() -> VortexResult<ArrayRef> {
174176
175177/// `[[1], [2]]` over `[1, MAX, 2]`: the lists skip an element.
176178fn list_view_with_a_gap ( ) -> VortexResult < ArrayRef > {
177- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
179+ let mut ctx = SESSION . create_execution_ctx ( ) ;
178180 Ok ( ListViewArray :: try_new (
179181 buffer ! [ 1_i32 , i32 :: MAX , 2 ] . into_array ( ) ,
180182 buffer ! [ 0_u32 , 2 ] . into_array ( ) ,
@@ -204,7 +206,7 @@ fn a_lambda_that_can_fail_sees_only_the_lists_elements(
204206#[ test]
205207fn a_lambda_that_can_fail_runs_on_a_slice_without_its_leftovers ( ) -> VortexResult < ( ) > {
206208 // Canonicalizing the result drops the leftovers too, so look at what the lambda runs on.
207- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
209+ let mut ctx = SESSION . create_execution_ctx ( ) ;
208210 let lists = Lists :: visible_elements_only ( sliced_list_with_leftovers ( ) ?, & mut ctx) ?;
209211 lists. with_elements ( |elements| {
210212 assert_arrays_eq ! ( elements. clone( ) , buffer![ 1_i32 , 2 ] . into_array( ) , & mut ctx) ;
@@ -217,7 +219,7 @@ fn a_lambda_that_can_fail_runs_on_a_slice_without_its_leftovers() -> VortexResul
217219fn a_lambda_that_cannot_fail_runs_on_the_elements_in_place ( ) -> VortexResult < ( ) > {
218220 // `x = 3` cannot fail, so it runs over the whole elements buffer, the null list's `i32::MAX`
219221 // included, and nothing is copied.
220- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
222+ let mut ctx = SESSION . create_execution_ctx ( ) ;
221223 let result = lists ( ) ?
222224 . apply ( & list_transform (
223225 root ( ) ,
@@ -251,7 +253,7 @@ fn a_failure_in_a_valid_list_is_an_error() -> VortexResult<()> {
251253 & [ 0 , 1 , 2 ] ,
252254 Validity :: from_iter ( [ false , true ] ) ,
253255 ) ?;
254- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
256+ let mut ctx = SESSION . create_execution_ctx ( ) ;
255257 let error = lists
256258 . apply ( & list_transform ( root ( ) , plus_one ( ) ?) ) ?
257259 . execute :: < RecursiveCanonical > ( & mut ctx)
@@ -403,7 +405,7 @@ fn three_nested_lambdas() -> VortexResult<()> {
403405fn sliced_list_views ( ) -> VortexResult < ( ) > {
404406 // `[[1, 2], [3], [4, 5]]` as a list view, sliced to `[[3], [4, 5]]`, which leaves unused
405407 // elements.
406- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
408+ let mut ctx = SESSION . create_execution_ctx ( ) ;
407409 let view = list_of (
408410 buffer ! [ 1_i32 , 2 , 3 , 4 , 5 ] . into_array ( ) ,
409411 & [ 0 , 2 , 3 , 5 ] ,
@@ -423,7 +425,7 @@ fn sliced_list_views() -> VortexResult<()> {
423425#[ test]
424426fn overlapping_list_views ( ) -> VortexResult < ( ) > {
425427 // `[[3, 4], [1], [2, 3]]`, sharing element 3.
426- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
428+ let mut ctx = SESSION . create_execution_ctx ( ) ;
427429 let view = ListViewArray :: try_new (
428430 buffer ! [ 1_i32 , 2 , 3 , 4 ] . into_array ( ) ,
429431 buffer ! [ 2_u32 , 0 , 1 ] . into_array ( ) ,
@@ -518,7 +520,7 @@ fn applying_the_bound_node() -> VortexResult<()> {
518520 let expected = transformed (
519521 PrimitiveArray :: from_option_iter ( [ Some ( 2_i32 ) , Some ( 3 ) , Some ( 4 ) , None ] ) . into_array ( ) ,
520522 ) ?;
521- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
523+ let mut ctx = SESSION . create_execution_ctx ( ) ;
522524 assert_arrays_eq ! ( input. apply_bound( & bound) ?, expected, & mut ctx) ;
523525 Ok ( ( ) )
524526}
@@ -552,19 +554,16 @@ fn a_lambda_bound_to_another_element_dtype_is_an_error() -> VortexResult<()> {
552554}
553555
554556#[ test]
555- fn replacing_the_root_rereads_the_list ( ) -> VortexResult < ( ) > {
556- // Rows `{s: {l}}`: re-rooting the transform at `$.s` changes where the list is read. The body
557- // is in the options, which rewrites of the expression leave alone.
557+ fn a_list_in_a_nested_field ( ) -> VortexResult < ( ) > {
558+ // Rows `{s: {l}}`.
558559 let input = StructArray :: try_new (
559560 FieldNames :: from ( [ "s" ] ) ,
560561 vec ! [ rows( lists( ) ?) ?] ,
561562 3 ,
562563 Validity :: NonNullable ,
563564 ) ?
564565 . into_array ( ) ;
565- let expr = list_transform ( col ( "l" ) , plus_one ( ) ?) ;
566- assert_eq ! ( replace( expr. clone( ) , & var( "x" ) , lit( 0_i32 ) ) , expr) ;
567- let expr = replace ( expr, & root ( ) , col ( "s" ) ) ;
566+ let expr = list_transform ( get_item ( "l" , col ( "s" ) ) , plus_one ( ) ?) ;
568567 assert_eq ! (
569568 expr. to_string( ) ,
570569 "vortex.list.transform($.s.l, (x) -> (@x + 1i32))"
@@ -592,7 +591,7 @@ fn an_infallible_transform_pushes_into_dictionary_values() -> VortexResult<()> {
592591 & [ 0 , 2 , 3 , 5 , 6 ] ,
593592 Validity :: NonNullable ,
594593 ) ?;
595- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
594+ let mut ctx = SESSION . create_execution_ctx ( ) ;
596595 assert_arrays_eq ! ( actual, expected, & mut ctx) ;
597596 Ok ( ( ) )
598597}
0 commit comments