Skip to content

Commit 6e90efa

Browse files
committed
avoid to create memory schema operator every time
1 parent cde35ab commit 6e90efa

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

crates/iceberg/src/io/file_io.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ mod tests {
332332
use std::io::Write;
333333
use std::path::Path;
334334

335+
use bytes::Bytes;
335336
use futures::io::AllowStdIo;
336337
use futures::AsyncReadExt;
337338
use tempfile::TempDir;
@@ -444,4 +445,22 @@ mod tests {
444445
let io = FileIO::from_path("tmp/||c");
445446
assert!(io.is_err());
446447
}
448+
449+
#[tokio::test]
450+
async fn test_memory_io() {
451+
let io = FileIOBuilder::new("memory").build().unwrap();
452+
453+
let path = format!("{}/1.txt", TempDir::new().unwrap().path().to_str().unwrap());
454+
455+
let output_file = io.new_output(&path).unwrap();
456+
output_file.write("test".into()).await.unwrap();
457+
458+
assert!(io.is_exist(&path.clone()).await.unwrap());
459+
let input_file = io.new_input(&path).unwrap();
460+
let content = input_file.read().await.unwrap();
461+
assert_eq!(content, Bytes::from("test"));
462+
463+
io.delete(&path).await.unwrap();
464+
assert!(!io.is_exist(&path).await.unwrap());
465+
}
447466
}

crates/iceberg/src/io/storage.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{Error, ErrorKind};
3030
#[derive(Debug)]
3131
pub(crate) enum Storage {
3232
#[cfg(feature = "storage-memory")]
33-
Memory,
33+
Memory(Operator),
3434
#[cfg(feature = "storage-fs")]
3535
LocalFs,
3636
#[cfg(feature = "storage-s3")]
@@ -56,7 +56,7 @@ impl Storage {
5656

5757
match scheme {
5858
#[cfg(feature = "storage-memory")]
59-
Scheme::Memory => Ok(Self::Memory),
59+
Scheme::Memory => Ok(Self::Memory(super::memory_config_build()?)),
6060
#[cfg(feature = "storage-fs")]
6161
Scheme::Fs => Ok(Self::LocalFs),
6262
#[cfg(feature = "storage-s3")]
@@ -95,13 +95,11 @@ impl Storage {
9595
let path = path.as_ref();
9696
match self {
9797
#[cfg(feature = "storage-memory")]
98-
Storage::Memory => {
99-
let op = super::memory_config_build()?;
100-
98+
Storage::Memory(op) => {
10199
if let Some(stripped) = path.strip_prefix("memory:/") {
102-
Ok((op, stripped))
100+
Ok((op.clone(), stripped))
103101
} else {
104-
Ok((op, &path[1..]))
102+
Ok((op.clone(), &path[1..]))
105103
}
106104
}
107105
#[cfg(feature = "storage-fs")]

0 commit comments

Comments
 (0)