Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(io): Align FileStatus with the Java API. #45

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("/"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better not to hard-code fs here, but I think it's a good starting point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think here should construct the fileIO according to the scheme. I'd like to do it in another pr.

.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
Loading