use std::fmt::Debug;
use std::sync::Arc;
use datafusion_common::Result as DFResult;
use datafusion_datasource::PartitionedFile;
use object_store::ObjectStore;
use vortex::array::memory::MemorySessionExt;
use vortex::io::VortexReadAt;
use vortex::io::object_store::ObjectStoreReadAt;
use vortex::io::session::RuntimeSessionExt;
use vortex::session::VortexSession;
pub trait VortexReaderFactory: Debug + Send + Sync + 'static {
fn create_reader(
&self,
file: &PartitionedFile,
session: &VortexSession,
) -> DFResult<Arc<dyn VortexReadAt>>;
}
#[derive(Debug)]
pub struct DefaultVortexReaderFactory {
object_store: Arc<dyn ObjectStore>,
}
impl DefaultVortexReaderFactory {
pub fn new(object_store: Arc<dyn ObjectStore>) -> Self {
Self { object_store }
}
}
impl VortexReaderFactory for DefaultVortexReaderFactory {
fn create_reader(
&self,
file: &PartitionedFile,
session: &VortexSession,
) -> DFResult<Arc<dyn VortexReadAt>> {
Ok(Arc::new(ObjectStoreReadAt::new_with_allocator(
Arc::clone(&self.object_store),
file.path().as_ref().into(),
session.handle(),
session.allocator(),
)) as _)
}
}