Skip to content

Commit e9d56e4

Browse files
committed
encapsulate input and output file better
1 parent 0047470 commit e9d56e4

File tree

7 files changed

+52
-69
lines changed

7 files changed

+52
-69
lines changed

crates/iceberg/src/io/file_io.rs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,28 @@ impl FileRead for opendal::Reader {
303303
/// Input file is used for reading from files.
304304
#[derive(Debug)]
305305
pub struct InputFile {
306-
/// todo doc
307-
pub storage: Arc<dyn Storage>,
308-
// Absolution path of file.
309-
/// todo doc
310-
pub path: String,
311-
// todo should remove this? Should always pass down a full path
312-
// // Relative path of file to uri, starts at [`relative_path_pos`]
313-
// relative_path_pos: usize,
306+
/// Storage backend for this input file.
307+
storage: Arc<dyn Storage>,
308+
/// Absolute path to the file.
309+
path: String,
314310
}
315311

316312
impl InputFile {
313+
/// Creates a new input file.
314+
///
315+
/// # Arguments
316+
///
317+
/// * `storage` - The storage backend to use
318+
/// * `path` - Absolute path to the file
319+
pub fn new(storage: Arc<dyn Storage>, path: String) -> Self {
320+
Self { storage, path }
321+
}
322+
323+
/// Returns the storage backend for this input file.
324+
pub fn storage(&self) -> &Arc<dyn Storage> {
325+
&self.storage
326+
}
327+
317328
/// Absolute path to root uri.
318329
pub fn location(&self) -> &str {
319330
&self.path
@@ -386,20 +397,31 @@ impl FileWrite for Box<dyn FileWrite> {
386397
}
387398
}
388399

389-
/// Output file is used for writing to files..
400+
/// Output file is used for writing to files.
390401
#[derive(Debug)]
391402
pub struct OutputFile {
392-
/// todo fix pub qualifier
393-
pub storage: Arc<dyn Storage>,
394-
// Absolution path of file.
395-
/// todo fix pub qualifier
396-
pub path: String,
397-
// todo should always pass down a full path
398-
// // Relative path of file to uri, starts at [`relative_path_pos`]
399-
// relative_path_pos: usize,
403+
/// Storage backend for this output file.
404+
storage: Arc<dyn Storage>,
405+
/// Absolute path to the file.
406+
path: String,
400407
}
401408

402409
impl OutputFile {
410+
/// Creates a new output file.
411+
///
412+
/// # Arguments
413+
///
414+
/// * `storage` - The storage backend to use
415+
/// * `path` - Absolute path to the file
416+
pub fn new(storage: Arc<dyn Storage>, path: String) -> Self {
417+
Self { storage, path }
418+
}
419+
420+
/// Returns the storage backend for this output file.
421+
pub fn storage(&self) -> &Arc<dyn Storage> {
422+
&self.storage
423+
}
424+
403425
/// Relative path to root uri.
404426
pub fn location(&self) -> &str {
405427
&self.path
@@ -419,10 +441,7 @@ impl OutputFile {
419441

420442
/// Converts into [`InputFile`].
421443
pub fn to_input_file(self) -> InputFile {
422-
InputFile {
423-
storage: self.storage,
424-
path: self.path,
425-
}
444+
InputFile::new(self.storage, self.path)
426445
}
427446

428447
/// Create a new output file with given bytes.

crates/iceberg/src/io/storage_azdls.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,17 +675,11 @@ impl Storage for OpenDALAzdlsStorage {
675675
}
676676

677677
fn new_input(&self, path: &str) -> Result<InputFile> {
678-
Ok(InputFile {
679-
storage: Arc::new(self.clone()),
680-
path: path.to_string(),
681-
})
678+
Ok(InputFile::new(Arc::new(self.clone()), path.to_string()))
682679
}
683680

684681
fn new_output(&self, path: &str) -> Result<OutputFile> {
685-
Ok(OutputFile {
686-
storage: Arc::new(self.clone()),
687-
path: path.to_string(),
688-
})
682+
Ok(OutputFile::new(Arc::new(self.clone()), path.to_string()))
689683
}
690684
}
691685

crates/iceberg/src/io/storage_fs.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,11 @@ impl Storage for OpenDALFsStorage {
110110
}
111111

112112
fn new_input(&self, path: &str) -> Result<InputFile> {
113-
Ok(InputFile {
114-
storage: Arc::new(self.clone()),
115-
path: path.to_string(),
116-
})
113+
Ok(InputFile::new(Arc::new(self.clone()), path.to_string()))
117114
}
118115

119116
fn new_output(&self, path: &str) -> Result<OutputFile> {
120-
Ok(OutputFile {
121-
storage: Arc::new(self.clone()),
122-
path: path.to_string(),
123-
})
117+
Ok(OutputFile::new(Arc::new(self.clone()), path.to_string()))
124118
}
125119
}
126120

crates/iceberg/src/io/storage_gcs.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,11 @@ impl Storage for OpenDALGcsStorage {
187187
}
188188

189189
fn new_input(&self, path: &str) -> Result<InputFile> {
190-
Ok(InputFile {
191-
storage: Arc::new(self.clone()),
192-
path: path.to_string(),
193-
})
190+
Ok(InputFile::new(Arc::new(self.clone()), path.to_string()))
194191
}
195192

196193
fn new_output(&self, path: &str) -> Result<OutputFile> {
197-
Ok(OutputFile {
198-
storage: Arc::new(self.clone()),
199-
path: path.to_string(),
200-
})
194+
Ok(OutputFile::new(Arc::new(self.clone()), path.to_string()))
201195
}
202196
}
203197

crates/iceberg/src/io/storage_memory.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,11 @@ impl Storage for OpenDALMemoryStorage {
9797
}
9898

9999
fn new_input(&self, path: &str) -> Result<InputFile> {
100-
Ok(InputFile {
101-
storage: Arc::new(self.clone()),
102-
path: path.to_string(),
103-
})
100+
Ok(InputFile::new(Arc::new(self.clone()), path.to_string()))
104101
}
105102

106103
fn new_output(&self, path: &str) -> Result<OutputFile> {
107-
Ok(OutputFile {
108-
storage: Arc::new(self.clone()),
109-
path: path.to_string(),
110-
})
104+
Ok(OutputFile::new(Arc::new(self.clone()), path.to_string()))
111105
}
112106
}
113107

crates/iceberg/src/io/storage_oss.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,11 @@ impl Storage for OpenDALOssStorage {
147147
}
148148

149149
fn new_input(&self, path: &str) -> Result<InputFile> {
150-
Ok(InputFile {
151-
storage: Arc::new(self.clone()),
152-
path: path.to_string(),
153-
})
150+
Ok(InputFile::new(Arc::new(self.clone()), path.to_string()))
154151
}
155152

156153
fn new_output(&self, path: &str) -> Result<OutputFile> {
157-
Ok(OutputFile {
158-
storage: Arc::new(self.clone()),
159-
path: path.to_string(),
160-
})
154+
Ok(OutputFile::new(Arc::new(self.clone()), path.to_string()))
161155
}
162156
}
163157

crates/iceberg/src/io/storage_s3.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,11 @@ impl Storage for OpenDALS3Storage {
314314
}
315315

316316
fn new_input(&self, path: &str) -> Result<InputFile> {
317-
Ok(InputFile {
318-
storage: Arc::new(self.clone()),
319-
path: path.to_string(),
320-
})
317+
Ok(InputFile::new(Arc::new(self.clone()), path.to_string()))
321318
}
322319

323320
fn new_output(&self, path: &str) -> Result<OutputFile> {
324-
Ok(OutputFile {
325-
storage: Arc::new(self.clone()),
326-
path: path.to_string(),
327-
})
321+
Ok(OutputFile::new(Arc::new(self.clone()), path.to_string()))
328322
}
329323
}
330324

0 commit comments

Comments
 (0)