Skip to content

Commit 984c91e

Browse files
ZENOTMEZENOTME
and
ZENOTME
authored
avoid to create memory schema operator every time (apache#635)
Co-authored-by: ZENOTME <[email protected]>
1 parent 4171275 commit 984c91e

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

crates/iceberg/src/io/file_io.rs

+19
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ mod tests {
368368
use std::io::Write;
369369
use std::path::Path;
370370

371+
use bytes::Bytes;
371372
use futures::io::AllowStdIo;
372373
use futures::AsyncReadExt;
373374
use tempfile::TempDir;
@@ -490,4 +491,22 @@ mod tests {
490491
let io = FileIO::from_path("tmp/||c");
491492
assert!(io.is_err());
492493
}
494+
495+
#[tokio::test]
496+
async fn test_memory_io() {
497+
let io = FileIOBuilder::new("memory").build().unwrap();
498+
499+
let path = format!("{}/1.txt", TempDir::new().unwrap().path().to_str().unwrap());
500+
501+
let output_file = io.new_output(&path).unwrap();
502+
output_file.write("test".into()).await.unwrap();
503+
504+
assert!(io.is_exist(&path.clone()).await.unwrap());
505+
let input_file = io.new_input(&path).unwrap();
506+
let content = input_file.read().await.unwrap();
507+
assert_eq!(content, Bytes::from("test"));
508+
509+
io.delete(&path).await.unwrap();
510+
assert!(!io.is_exist(&path).await.unwrap());
511+
}
493512
}

crates/iceberg/src/io/storage.rs

+5-7
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")]
@@ -96,13 +96,11 @@ impl Storage {
9696
let path = path.as_ref();
9797
match self {
9898
#[cfg(feature = "storage-memory")]
99-
Storage::Memory => {
100-
let op = super::memory_config_build()?;
101-
99+
Storage::Memory(op) => {
102100
if let Some(stripped) = path.strip_prefix("memory:/") {
103-
Ok((op, stripped))
101+
Ok((op.clone(), stripped))
104102
} else {
105-
Ok((op, &path[1..]))
103+
Ok((op.clone(), &path[1..]))
106104
}
107105
}
108106
#[cfg(feature = "storage-fs")]

0 commit comments

Comments
 (0)