vortex_layout/
strategy.rs1use vortex_array::ArrayContext;
7use vortex_dtype::DType;
8use vortex_error::VortexResult;
9
10use crate::layouts::flat::FlatLayout;
11use crate::layouts::flat::writer::FlatLayoutWriter;
12use crate::layouts::struct_::writer::StructLayoutWriter;
13use crate::writer::{LayoutWriter, LayoutWriterExt};
14
15pub trait LayoutStrategy: 'static + Send + Sync {
17 fn new_writer(&self, ctx: &ArrayContext, dtype: &DType) -> VortexResult<Box<dyn LayoutWriter>>;
18}
19
20impl LayoutStrategy for FlatLayout {
22 fn new_writer(&self, ctx: &ArrayContext, dtype: &DType) -> VortexResult<Box<dyn LayoutWriter>> {
23 Ok(FlatLayoutWriter::new(ctx.clone(), dtype.clone(), Default::default()).boxed())
24 }
25}
26
27pub struct StructStrategy;
29
30impl LayoutStrategy for StructStrategy {
31 fn new_writer(&self, ctx: &ArrayContext, dtype: &DType) -> VortexResult<Box<dyn LayoutWriter>> {
32 if let DType::Struct(..) = dtype {
33 StructLayoutWriter::try_new_with_strategy(ctx, dtype, StructStrategy).map(|w| w.boxed())
34 } else {
35 Ok(FlatLayoutWriter::new(ctx.clone(), dtype.clone(), Default::default()).boxed())
36 }
37 }
38}