Skip to content

Commit

Permalink
feat(io): Align FileStatus with the Java API. (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitozi authored Aug 13, 2024
1 parent 6dc72e0 commit 74a99f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/paimon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ serde_json = "1.0.120"
serde_with = "3.9.0"
snafu = "0.8.3"
typed-builder = "^0.19"
opendal = "0.48"
pretty_assertions = "1"
opendal = { version = "0.48",features = ["services-fs"] }
pretty_assertions = "1"
17 changes: 14 additions & 3 deletions crates/paimon/src/io/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use crate::error::*;
use std::collections::HashMap;

use opendal::services::MemoryConfig;
use chrono::offset::Utc;
use chrono::DateTime;
use opendal::services::Fs;
use opendal::{Metakey, Operator};
use snafu::ResultExt;

Expand All @@ -34,7 +36,7 @@ impl FileIO {
///
/// TODO: Support building Operator from HashMap via options.
pub fn new(_: HashMap<String, String>) -> Result<Self> {
let op = Operator::from_config(MemoryConfig::default())
let op = Operator::new(Fs::default().root("/"))
.context(IoUnexpectedSnafu {
message: "Failed to create operator".to_string(),
})?
Expand Down Expand Up @@ -72,6 +74,9 @@ impl FileIO {

Ok(FileStatus {
size: meta.content_length(),
is_dir: meta.is_dir(),
last_modified: meta.last_modified(),
path: path.to_string(),
})
}

Expand All @@ -84,7 +89,7 @@ impl FileIO {
let entries = self
.op
.list_with(path)
.metakey(Metakey::ContentLength)
.metakey(Metakey::ContentLength | Metakey::LastModified)
.await
.context(IoUnexpectedSnafu {
message: "Failed to list file status".to_string(),
Expand All @@ -94,6 +99,9 @@ impl FileIO {
.into_iter()
.map(|meta| FileStatus {
size: meta.metadata().content_length(),
is_dir: meta.metadata().is_dir(),
last_modified: meta.metadata().last_modified(),
path: format!("{}{}", path, meta.name()),
})
.collect())
}
Expand Down Expand Up @@ -155,6 +163,9 @@ impl FileIO {
#[derive(Clone, Debug)]
pub struct FileStatus {
pub size: u64,
pub is_dir: bool,
pub path: String,
pub last_modified: Option<DateTime<Utc>>,
}

/// Input file represents a file that can be read from.
Expand Down

0 comments on commit 74a99f0

Please sign in to comment.