refactor(users/edef/weave): simplify OwningRef handling
We switch to working with the underlying Arc<Bytes<u8>> type, since Buffer<u8> is already essentially an OwningRef-esque subslice. Because we're now working with an exposed Arc directly, we don't need to have our own `unsafe impl StableAddress` any more. Change-Id: I9ce2edc6899177145e15b72aa5380f708a62173c Reviewed-on: https://cl.tvl.fyi/c/depot/+/12668 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									549c51f200
								
							
						
					
					
						commit
						bdc2891053
					
				
					 2 changed files with 12 additions and 32 deletions
				
			
		| 
						 | 
				
			
			@ -1,27 +0,0 @@
 | 
			
		|||
use owning_ref::{OwningRef, StableAddress};
 | 
			
		||||
use polars::export::arrow::buffer::Buffer;
 | 
			
		||||
use std::ops::Deref;
 | 
			
		||||
 | 
			
		||||
/// An shared `[[u8; N]]` backed by a Polars [Buffer].
 | 
			
		||||
pub type FixedBytes<const N: usize> = OwningRef<'static, Bytes, [[u8; N]]>;
 | 
			
		||||
 | 
			
		||||
/// Wrapper struct to make [Buffer] implement [StableAddress].
 | 
			
		||||
/// TODO(edef): upstream the `impl`
 | 
			
		||||
pub struct Bytes(pub Buffer<u8>);
 | 
			
		||||
 | 
			
		||||
/// SAFETY: [Buffer] is always an Arc+Vec indirection.
 | 
			
		||||
unsafe impl StableAddress for Bytes {}
 | 
			
		||||
 | 
			
		||||
impl Bytes {
 | 
			
		||||
    pub fn map<U: ?Sized>(self, f: impl FnOnce(&[u8]) -> &U) -> OwningRef<'static, Self, U> {
 | 
			
		||||
        OwningRef::new(self).map(f)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Deref for Bytes {
 | 
			
		||||
    type Target = [u8];
 | 
			
		||||
 | 
			
		||||
    fn deref(&self) -> &Self::Target {
 | 
			
		||||
        &*self.0
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use owning_ref::ArcRef;
 | 
			
		||||
use rayon::prelude::*;
 | 
			
		||||
use std::{fs::File, ops::Range, slice};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -8,8 +9,9 @@ use polars::{
 | 
			
		|||
    prelude::{ParquetReader, SerReader},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub use crate::bytes::*;
 | 
			
		||||
mod bytes;
 | 
			
		||||
/// An shared `[[u8; N]]` backed by a Polars [Buffer].
 | 
			
		||||
pub type FixedBytes<const N: usize> =
 | 
			
		||||
    ArcRef<'static, polars::export::arrow::buffer::Bytes<u8>, [[u8; N]]>;
 | 
			
		||||
 | 
			
		||||
pub const INDEX_NULL: u32 = !0;
 | 
			
		||||
pub const DONE: &str = "\u{2714}";
 | 
			
		||||
| 
						 | 
				
			
			@ -60,10 +62,15 @@ fn into_fixed_binary_rechunk<const N: usize>(chunked: &BinaryChunked) -> FixedBy
 | 
			
		|||
    let chunked = chunked.rechunk();
 | 
			
		||||
    let mut iter = chunked.downcast_iter();
 | 
			
		||||
    let array = iter.next().unwrap();
 | 
			
		||||
    assert!(iter.next().is_none());
 | 
			
		||||
 | 
			
		||||
    let (buf, off, len) = {
 | 
			
		||||
        let range = assert_fixed_dense::<N>(array);
 | 
			
		||||
    Bytes(array.values().clone().sliced(range.start, range.len()))
 | 
			
		||||
        .map(|buf| exact_chunks(buf).unwrap())
 | 
			
		||||
        array.values().clone().sliced(range.start, range.len())
 | 
			
		||||
    }
 | 
			
		||||
    .into_inner();
 | 
			
		||||
 | 
			
		||||
    ArcRef::new(buf).map(|bytes| exact_chunks(&bytes[off..off + len]).unwrap())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Ensures that the supplied Arrow array consists of densely packed bytestrings of length `N`.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue