File tree Expand file tree Collapse file tree
vortex-layout/src/layouts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ const ONE_MEG: u64 = 1 << 20;
2323/// Vortex provides an out-of-the-box file writer that optimizes the layout of chunks on-disk,
2424/// repartitioning and compressing them to strike a balance between size on-disk,
2525/// bulk decoding performance, and IOPS required to perform an indexed read.
26+ #[ derive( Debug , Clone ) ]
2627pub struct WriteStrategyBuilder {
2728 compressor : Option < Arc < dyn CompressorPlugin > > ,
2829 row_block_size : usize ,
Original file line number Diff line number Diff line change @@ -45,9 +45,14 @@ pub struct VortexWriteOptions {
4545pub trait WriteOptionsSessionExt : SessionExt {
4646 /// Create [`VortexWriteOptions`] for writing to a Vortex file.
4747 fn write_options ( & self ) -> VortexWriteOptions {
48+ let maybe_write_strategy_builder = self . get_opt :: < WriteStrategyBuilder > ( ) ;
49+ let strategy = maybe_write_strategy_builder
50+ . map ( |opt| opt. clone ( ) . build ( ) )
51+ . unwrap_or_else ( || WriteStrategyBuilder :: new ( ) . build ( ) ) ;
52+
4853 VortexWriteOptions {
4954 session : self . session ( ) ,
50- strategy : WriteStrategyBuilder :: new ( ) . build ( ) ,
55+ strategy,
5156 exclude_dtype : false ,
5257 file_statistics : PRUNING_STATS . to_vec ( ) ,
5358 max_variable_length_statistics_size : 64 ,
@@ -431,3 +436,20 @@ impl WriteSummary {
431436 self . footer . row_count ( )
432437 }
433438}
439+
440+ #[ cfg( test) ]
441+ mod tests {
442+ use super :: * ;
443+
444+ #[ test]
445+ fn test_write_options_from_session_vars ( ) {
446+ let session = VortexSession :: empty ( ) ;
447+ let fetched_write_strategy = session. get_opt :: < WriteStrategyBuilder > ( ) ;
448+ assert ! ( fetched_write_strategy. is_none( ) ) ;
449+ drop ( fetched_write_strategy) ;
450+
451+ let session = session. set ( WriteStrategyBuilder :: new ( ) ) ;
452+ let fetched_write_strategy = session. get_opt :: < WriteStrategyBuilder > ( ) ;
453+ assert ! ( fetched_write_strategy. is_some( ) ) ;
454+ }
455+ }
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ use crate::{LayoutRef, LayoutStrategy};
2323/// meet this interface.
2424///
2525/// API consumers are also free to implement this trait to provide new plugin compressors.
26- pub trait CompressorPlugin : Send + Sync + ' static {
26+ pub trait CompressorPlugin : std :: fmt :: Debug + Send + Sync + ' static {
2727 fn compress_chunk ( & self , chunk : & dyn Array ) -> VortexResult < ArrayRef > ;
2828}
2929
@@ -35,7 +35,7 @@ impl CompressorPlugin for Arc<dyn CompressorPlugin> {
3535
3636impl < F > CompressorPlugin for F
3737where
38- F : Fn ( & dyn Array ) -> VortexResult < ArrayRef > + Send + Sync + ' static ,
38+ F : Fn ( & dyn Array ) -> VortexResult < ArrayRef > + Send + Sync + ' static + std :: fmt :: Debug ,
3939{
4040 fn compress_chunk ( & self , chunk : & dyn Array ) -> VortexResult < ArrayRef > {
4141 self ( chunk)
Original file line number Diff line number Diff line change @@ -46,6 +46,26 @@ impl VortexSession {
4646 }
4747 self
4848 }
49+
50+ /// Inserts a new session variable of type `V` with the supplied value.
51+ ///
52+ /// # Panics
53+ ///
54+ /// If a variable of that type already exists.
55+ pub fn set < V : SessionVar > ( self , val : V ) -> Self {
56+ match self . 0 . entry ( TypeId :: of :: < V > ( ) ) {
57+ Entry :: Occupied ( _) => {
58+ vortex_panic ! (
59+ "Session variable of type {} already exists" ,
60+ type_name:: <V >( )
61+ ) ;
62+ }
63+ Entry :: Vacant ( e) => {
64+ e. insert ( Box :: new ( val) ) ;
65+ }
66+ }
67+ self
68+ }
4969}
5070
5171/// Trait for accessing and modifying the state of a Vortex session.
You can’t perform that action at this time.
0 commit comments