-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathreader.rs
More file actions
54 lines (47 loc) · 1.58 KB
/
Copy pathreader.rs
File metadata and controls
54 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Factory for creating [`VortexReadAt`][vortex::io::VortexReadAt] instances
//! from [`PartitionedFile`]s.
use std::fmt::Debug;
use std::sync::Arc;
use datafusion_common::Result as DFResult;
use datafusion_datasource::PartitionedFile;
use object_store::ObjectStore;
use vortex::io::VortexReadAt;
use vortex::io::object_store::ObjectStoreReadAt;
use vortex::io::session::RuntimeSessionExt;
use vortex::session::VortexSession;
/// Factory to create [`VortexReadAt`] instances to read the target file.
pub trait VortexReaderFactory: Debug + Send + Sync + 'static {
/// Create a reader for a target object.
fn create_reader(
&self,
file: &PartitionedFile,
session: &VortexSession,
) -> DFResult<Arc<dyn VortexReadAt>>;
}
/// Default factory, creates [`ObjectStore`] backed readers for files,
/// works with multiple cloud providers.
#[derive(Debug)]
pub struct DefaultVortexReaderFactory {
object_store: Arc<dyn ObjectStore>,
}
impl DefaultVortexReaderFactory {
/// Creates new instance
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(
self.object_store.clone(),
file.path().as_ref().into(),
session.handle(),
)) as _)
}
}