55
66use vortex_error:: VortexExpect ;
77use vortex_error:: VortexResult ;
8+ use vortex_error:: vortex_bail;
89
10+ use crate :: ArrayView ;
911use crate :: Canonical ;
1012use crate :: CanonicalView ;
1113use crate :: ExecutionCtx ;
12- use crate :: IntoArray ;
1314use crate :: arrays:: Bool ;
1415use crate :: arrays:: BoolArray ;
1516use crate :: arrays:: Decimal ;
@@ -20,6 +21,7 @@ use crate::arrays::FixedSizeList;
2021use crate :: arrays:: FixedSizeListArray ;
2122use crate :: arrays:: ListView ;
2223use crate :: arrays:: ListViewArray ;
24+ use crate :: arrays:: Null ;
2325use crate :: arrays:: NullArray ;
2426use crate :: arrays:: Primitive ;
2527use crate :: arrays:: PrimitiveArray ;
@@ -38,148 +40,138 @@ use crate::arrays::variant::VariantArraySlotsExt;
3840/// by looking up each code in the values array.
3941pub ( crate ) fn take_canonical (
4042 values : CanonicalView ,
41- codes : & PrimitiveArray ,
43+ codes : ArrayView < ' _ , Primitive > ,
4244 ctx : & mut ExecutionCtx ,
4345) -> VortexResult < Canonical > {
44- let values = Canonical :: from ( values) ;
4546 Ok ( match values {
46- Canonical :: Null ( a) => Canonical :: Null ( take_null ( & a, codes) ) ,
47- Canonical :: Bool ( a) => Canonical :: Bool ( take_bool ( & a, codes, ctx) ?) ,
48- Canonical :: Primitive ( a) => Canonical :: Primitive ( take_primitive ( & a, codes, ctx) ) ,
49- Canonical :: Decimal ( a) => Canonical :: Decimal ( take_decimal ( & a, codes, ctx) ) ,
50- Canonical :: VarBinView ( a) => Canonical :: VarBinView ( take_varbinview ( & a, codes, ctx) ) ,
51- Canonical :: List ( a) => Canonical :: List ( take_listview ( & a, codes, ctx) ) ,
52- Canonical :: Map ( _) => vortex_error :: vortex_bail!( "Map arrays don't support take" ) ,
53- Canonical :: FixedSizeList ( a) => {
54- Canonical :: FixedSizeList ( take_fixed_size_list ( & a, codes, ctx) )
47+ CanonicalView :: Null ( a) => Canonical :: Null ( take_null ( a, codes) ) ,
48+ CanonicalView :: Bool ( a) => Canonical :: Bool ( take_bool ( a, codes, ctx) ?) ,
49+ CanonicalView :: Primitive ( a) => Canonical :: Primitive ( take_primitive ( a, codes, ctx) ) ,
50+ CanonicalView :: Decimal ( a) => Canonical :: Decimal ( take_decimal ( a, codes, ctx) ) ,
51+ CanonicalView :: VarBinView ( a) => Canonical :: VarBinView ( take_varbinview ( a, codes, ctx) ) ,
52+ CanonicalView :: List ( a) => Canonical :: List ( take_listview ( a, codes, ctx) ) ,
53+ CanonicalView :: Map ( _) => vortex_bail ! ( "Map arrays don't support take" ) ,
54+ CanonicalView :: FixedSizeList ( a) => {
55+ Canonical :: FixedSizeList ( take_fixed_size_list ( a, codes, ctx) )
5556 }
56- Canonical :: Struct ( a) => Canonical :: Struct ( take_struct ( & a, codes) ) ,
57- Canonical :: Union ( _) => {
57+ CanonicalView :: Struct ( a) => Canonical :: Struct ( take_struct ( a, codes) ) ,
58+ CanonicalView :: Union ( _) => {
5859 todo ! (
5960 "TODO(connor)[Union]: implement dictionary execution after Union take supports \
6061 nullable indices and outer null propagation"
6162 )
6263 }
63- Canonical :: Extension ( a) => Canonical :: Extension ( take_extension ( & a, codes, ctx) ) ,
64- Canonical :: Variant ( a) => {
65- let indices = codes. clone ( ) . into_array ( ) ;
64+ CanonicalView :: Extension ( a) => Canonical :: Extension ( take_extension ( a, codes, ctx) ) ,
65+ CanonicalView :: Variant ( a) => {
66+ let indices = codes. array ( ) . clone ( ) ;
6667 let taken_core_storage = a. core_storage ( ) . take ( indices. clone ( ) ) ?;
6768 let taken_shredded = a
6869 . shredded ( )
69- . map ( |shredded| shredded. take ( indices. clone ( ) ) )
70+ . map ( |shredded| shredded. take ( indices) )
7071 . transpose ( ) ?;
7172 Canonical :: Variant ( VariantArray :: try_new ( taken_core_storage, taken_shredded) ?)
7273 }
7374 } )
7475}
7576
7677/// Take for NullArray is trivial - just create a new NullArray with the new length.
77- fn take_null ( _array : & NullArray , codes : & PrimitiveArray ) -> NullArray {
78+ fn take_null ( _array : ArrayView < ' _ , Null > , codes : ArrayView < ' _ , Primitive > ) -> NullArray {
7879 NullArray :: new ( codes. len ( ) )
7980}
8081
81- // TODO(joe): use dict_bool_take
8282fn take_bool (
83- array : & BoolArray ,
84- codes : & PrimitiveArray ,
83+ array : ArrayView < ' _ , Bool > ,
84+ codes : ArrayView < ' _ , Primitive > ,
8585 ctx : & mut ExecutionCtx ,
8686) -> VortexResult < BoolArray > {
87- let codes_ref = codes. clone ( ) . into_array ( ) ;
88- let array = array. as_view ( ) ;
89- Ok ( <Bool as TakeExecute >:: take ( array, & codes_ref, ctx) ?
87+ let codes_ref = codes. array ( ) ;
88+ Ok ( <Bool as TakeExecute >:: take ( array, codes_ref, ctx) ?
9089 . vortex_expect ( "take bool should not return None" )
9190 . as_ :: < Bool > ( )
9291 . into_owned ( ) )
9392}
9493
9594fn take_primitive (
96- array : & PrimitiveArray ,
97- codes : & PrimitiveArray ,
95+ array : ArrayView < ' _ , Primitive > ,
96+ codes : ArrayView < ' _ , Primitive > ,
9897 ctx : & mut ExecutionCtx ,
9998) -> PrimitiveArray {
100- let codes_ref = codes. clone ( ) . into_array ( ) ;
101- let array = array. as_view ( ) ;
102- <Primitive as TakeExecute >:: take ( array, & codes_ref, ctx)
99+ let codes_ref = codes. array ( ) ;
100+ <Primitive as TakeExecute >:: take ( array, codes_ref, ctx)
103101 . vortex_expect ( "take primitive array" )
104102 . vortex_expect ( "take primitive should not return None" )
105103 . as_ :: < Primitive > ( )
106104 . into_owned ( )
107105}
108106
109107fn take_decimal (
110- array : & DecimalArray ,
111- codes : & PrimitiveArray ,
108+ array : ArrayView < ' _ , Decimal > ,
109+ codes : ArrayView < ' _ , Primitive > ,
112110 ctx : & mut ExecutionCtx ,
113111) -> DecimalArray {
114- let codes_ref = codes. clone ( ) . into_array ( ) ;
115- let array = array. as_view ( ) ;
116- <Decimal as TakeExecute >:: take ( array, & codes_ref, ctx)
112+ let codes_ref = codes. array ( ) ;
113+ <Decimal as TakeExecute >:: take ( array, codes_ref, ctx)
117114 . vortex_expect ( "take decimal array" )
118115 . vortex_expect ( "take decimal should not return None" )
119116 . as_ :: < Decimal > ( )
120117 . into_owned ( )
121118}
122119
123120fn take_varbinview (
124- array : & VarBinViewArray ,
125- codes : & PrimitiveArray ,
121+ array : ArrayView < ' _ , VarBinView > ,
122+ codes : ArrayView < ' _ , Primitive > ,
126123 ctx : & mut ExecutionCtx ,
127124) -> VarBinViewArray {
128- let codes_ref = codes. clone ( ) . into_array ( ) ;
129- let array = array. as_view ( ) ;
130- <VarBinView as TakeExecute >:: take ( array, & codes_ref, ctx)
125+ let codes_ref = codes. array ( ) ;
126+ <VarBinView as TakeExecute >:: take ( array, codes_ref, ctx)
131127 . vortex_expect ( "take varbinview array" )
132128 . vortex_expect ( "take varbinview should not return None" )
133129 . as_ :: < VarBinView > ( )
134130 . into_owned ( )
135131}
136132
137133fn take_listview (
138- array : & ListViewArray ,
139- codes : & PrimitiveArray ,
134+ array : ArrayView < ' _ , ListView > ,
135+ codes : ArrayView < ' _ , Primitive > ,
140136 ctx : & mut ExecutionCtx ,
141137) -> ListViewArray {
142- let codes_ref = codes. clone ( ) . into_array ( ) ;
143- let array = array. as_view ( ) ;
144- <ListView as TakeExecute >:: take ( array, & codes_ref, ctx)
138+ let codes_ref = codes. array ( ) ;
139+ <ListView as TakeExecute >:: take ( array, codes_ref, ctx)
145140 . vortex_expect ( "take listview execute" )
146141 . vortex_expect ( "ListView TakeExecute should not return None" )
147142 . as_ :: < ListView > ( )
148143 . into_owned ( )
149144}
150145
151146fn take_fixed_size_list (
152- array : & FixedSizeListArray ,
153- codes : & PrimitiveArray ,
147+ array : ArrayView < ' _ , FixedSizeList > ,
148+ codes : ArrayView < ' _ , Primitive > ,
154149 ctx : & mut ExecutionCtx ,
155150) -> FixedSizeListArray {
156- let codes_ref = codes. clone ( ) . into_array ( ) ;
157- let array = array. as_view ( ) ;
158- <FixedSizeList as TakeExecute >:: take ( array, & codes_ref, ctx)
151+ let codes_ref = codes. array ( ) ;
152+ <FixedSizeList as TakeExecute >:: take ( array, codes_ref, ctx)
159153 . vortex_expect ( "take fixed size list array" )
160154 . vortex_expect ( "take fixed size list should not return None" )
161155 . as_ :: < FixedSizeList > ( )
162156 . into_owned ( )
163157}
164158
165- fn take_struct ( array : & StructArray , codes : & PrimitiveArray ) -> StructArray {
166- let codes_ref = codes. clone ( ) . into_array ( ) ;
167- let array = array. as_view ( ) ;
168- <Struct as TakeReduce >:: take ( array, & codes_ref)
159+ fn take_struct ( array : ArrayView < ' _ , Struct > , codes : ArrayView < ' _ , Primitive > ) -> StructArray {
160+ let codes_ref = codes. array ( ) ;
161+ <Struct as TakeReduce >:: take ( array, codes_ref)
169162 . vortex_expect ( "take struct array" )
170163 . vortex_expect ( "take struct should not return None" )
171164 . as_ :: < Struct > ( )
172165 . into_owned ( )
173166}
174167
175168fn take_extension (
176- array : & ExtensionArray ,
177- codes : & PrimitiveArray ,
169+ array : ArrayView < ' _ , Extension > ,
170+ codes : ArrayView < ' _ , Primitive > ,
178171 ctx : & mut ExecutionCtx ,
179172) -> ExtensionArray {
180- let codes_ref = codes. clone ( ) . into_array ( ) ;
181- let array = array. as_view ( ) ;
182- <Extension as TakeExecute >:: take ( array, & codes_ref, ctx)
173+ let codes_ref = codes. array ( ) ;
174+ <Extension as TakeExecute >:: take ( array, codes_ref, ctx)
183175 . vortex_expect ( "take extension storage" )
184176 . vortex_expect ( "take extension should not return None" )
185177 . as_ :: < Extension > ( )
0 commit comments