@@ -146,127 +146,6 @@ pub mod layout {
146146
147147}
148148
149- pub use container:: Column ;
150- mod container {
151-
152- /// A container based on a columnar store, encoded in aligned bytes.
153- pub enum Column < C > {
154- /// The typed variant of the container.
155- Typed ( C ) ,
156- /// The binary variant of the container.
157- Bytes ( timely:: bytes:: arc:: Bytes ) ,
158- /// Relocated, aligned binary data, if `Bytes` doesn't work for some reason.
159- ///
160- /// Reasons could include misalignment, cloning of data, or wanting
161- /// to release the `Bytes` as a scarce resource.
162- Align ( std:: sync:: Arc < [ u64 ] > ) ,
163- }
164-
165- impl < C : Default > Default for Column < C > {
166- fn default ( ) -> Self { Self :: Typed ( Default :: default ( ) ) }
167- }
168-
169- impl < C > Column < C > {
170- pub fn as_mut ( & mut self ) -> & mut C { if let Column :: Typed ( c) = self { c } else { panic ! ( ) } }
171- }
172-
173- // The clone implementation moves out of the `Bytes` variant into `Align`.
174- // This is optional and non-optimal, as the bytes clone is relatively free.
175- // But, we don't want to leak the uses of `Bytes`, is why we do this I think.
176- impl < C : columnar:: Container > Clone for Column < C > where C : Clone {
177- fn clone ( & self ) -> Self {
178- match self {
179- Column :: Typed ( t) => Column :: Typed ( t. clone ( ) ) ,
180- Column :: Bytes ( b) => {
181- assert ! ( b. len( ) % 8 == 0 ) ;
182- let mut alloc: Vec < u64 > = vec ! [ 0 ; b. len( ) / 8 ] ;
183- bytemuck:: cast_slice_mut ( & mut alloc[ ..] ) . copy_from_slice ( & b[ ..] ) ;
184- Self :: Align ( alloc. into ( ) )
185- } ,
186- Column :: Align ( a) => Column :: Align ( std:: sync:: Arc :: clone ( & a. clone ( ) ) ) ,
187- }
188- }
189- fn clone_from ( & mut self , other : & Self ) {
190- match ( self , other) {
191- ( Column :: Typed ( t0) , Column :: Typed ( t1) ) => {
192- // Derived `Clone` implementations for e.g. tuples cannot be relied on to call `clone_from`.
193- let t1 = t1. borrow ( ) ;
194- t0. clear ( ) ;
195- t0. extend_from_self ( t1, 0 ..t1. len ( ) ) ;
196- }
197- ( Column :: Align ( a0) , Column :: Align ( a1) ) => { a0. clone_from ( a1) ; }
198- ( x, y) => { * x = y. clone ( ) ; }
199- }
200- }
201- }
202-
203- use columnar:: { Len , FromBytes } ;
204- use columnar:: bytes:: { EncodeDecode , Indexed } ;
205-
206- impl < C : columnar:: ContainerBytes > Column < C > {
207- /// Borrows the contents no matter their representation.
208- ///
209- /// This function is meant to be efficient, but it cannot be relied on to be zero-cost.
210- /// Ideal uses would borrow a container infrequently, and access the borrowed form repeatedly.
211- #[ inline( always) ] pub fn borrow ( & self ) -> C :: Borrowed < ' _ > {
212- match self {
213- Column :: Typed ( t) => t. borrow ( ) ,
214- Column :: Bytes ( b) => <C :: Borrowed < ' _ > as FromBytes >:: from_bytes ( & mut Indexed :: decode ( bytemuck:: cast_slice ( b) ) ) ,
215- Column :: Align ( a) => <C :: Borrowed < ' _ > as FromBytes >:: from_bytes ( & mut Indexed :: decode ( a) ) ,
216- }
217- }
218-
219- pub fn into_typed ( self ) -> C where C : Default {
220- if let Column :: Typed ( c) = self { c }
221- else {
222- let mut result = C :: default ( ) ;
223- let borrow = self . borrow ( ) ;
224- result. extend_from_self ( borrow, 0 .. borrow. len ( ) ) ;
225- result
226- }
227- }
228- }
229-
230- impl < C : columnar:: Container , T > timely:: container:: PushInto < T > for Column < C > where C : columnar:: Push < T > {
231- #[ inline]
232- fn push_into ( & mut self , item : T ) {
233- match self {
234- Column :: Typed ( t) => t. push ( item) ,
235- Column :: Align ( _) | Column :: Bytes ( _) => {
236- // We really oughtn't be calling this in this case.
237- // We could convert to owned, but need more constraints on `C`.
238- unimplemented ! ( "Pushing into Column::Bytes without first clearing" ) ;
239- }
240- }
241- }
242- }
243-
244- impl < C : columnar:: ContainerBytes > timely:: dataflow:: channels:: ContainerBytes for Column < C > {
245- fn from_bytes ( bytes : timely:: bytes:: arc:: Bytes ) -> Self {
246- // Our expectation / hope is that `bytes` is `u64` aligned and sized.
247- // If the alignment is borked, we can relocate. IF the size is borked,
248- // not sure what we do in that case.
249- assert ! ( bytes. len( ) % 8 == 0 ) ;
250- if bytemuck:: try_cast_slice :: < _ , u64 > ( & bytes) . is_ok ( ) {
251- Self :: Bytes ( bytes)
252- }
253- else {
254- println ! ( "Re-locating bytes for alignment reasons" ) ;
255- let mut alloc: Vec < u64 > = vec ! [ 0 ; bytes. len( ) / 8 ] ;
256- bytemuck:: cast_slice_mut ( & mut alloc[ ..] ) . copy_from_slice ( & bytes[ ..] ) ;
257- Self :: Align ( alloc. into ( ) )
258- }
259- }
260-
261- // Borrow rather than trust the sizes of the bytes themselves.
262- fn length_in_bytes ( & self ) -> usize { 8 * Indexed :: length_in_words ( & self . borrow ( ) ) }
263-
264- // Borrow rather than trust the sizes of the bytes themselves.
265- fn into_bytes < W : :: std:: io:: Write > ( & self , writer : & mut W ) { Indexed :: write ( writer, & self . borrow ( ) ) . unwrap ( ) }
266- }
267- }
268-
269-
270149pub use updates:: Updates ;
271150
272151/// A thin wrapper around `Updates` that tracks the pre-consolidation record count
@@ -488,7 +367,7 @@ pub mod arrangement {
488367 /// A builder for columnar storage.
489368 pub type ValBuilder < K , V , T , R > = RcBuilder < ValMirror < ( K , V , T , R ) > > ;
490369
491- /// A batch container implementation for Column <C>.
370+ /// A batch container implementation for Coltainer <C>.
492371 pub use batch_container:: Coltainer ;
493372 pub mod batch_container {
494373
0 commit comments