From bdcf15397e2f94fca7edc8ee9907388a8d28eecf Mon Sep 17 00:00:00 2001 From: Aitozi Date: Thu, 8 Aug 2024 23:21:54 +0800 Subject: [PATCH 1/2] feat(io): Align FileStatus with the Java API. --- crates/paimon/Cargo.toml | 4 ++-- crates/paimon/src/io/file_io.rs | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/paimon/Cargo.toml b/crates/paimon/Cargo.toml index a285c2e..9e741fa 100644 --- a/crates/paimon/Cargo.toml +++ b/crates/paimon/Cargo.toml @@ -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" \ No newline at end of file +opendal = { version = "0.48",features = ["services-fs"] } +pretty_assertions = "1" diff --git a/crates/paimon/src/io/file_io.rs b/crates/paimon/src/io/file_io.rs index 5247b4f..2043fca 100644 --- a/crates/paimon/src/io/file_io.rs +++ b/crates/paimon/src/io/file_io.rs @@ -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; @@ -34,7 +36,7 @@ impl FileIO { /// /// TODO: Support building Operator from HashMap via options. pub fn new(_: HashMap) -> Result { - let op = Operator::from_config(MemoryConfig::default()) + let op = Operator::new(Fs::default().root("/")) .context(IoUnexpectedSnafu { message: "Failed to create operator".to_string(), })? @@ -72,6 +74,9 @@ impl FileIO { Ok(FileStatus { size: meta.content_length(), + is_dir: meta.is_dir(), + last_modification_time: meta.last_modified(), + path: path.to_string(), }) } @@ -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(), @@ -94,6 +99,9 @@ impl FileIO { .into_iter() .map(|meta| FileStatus { size: meta.metadata().content_length(), + is_dir: meta.metadata().is_dir(), + last_modification_time: meta.metadata().last_modified(), + path: format!("{}{}", path, meta.name()), }) .collect()) } @@ -155,6 +163,9 @@ impl FileIO { #[derive(Clone, Debug)] pub struct FileStatus { pub size: u64, + pub is_dir: bool, + pub path: String, + pub last_modification_time: Option>, } /// Input file represents a file that can be read from. From eaa9a5e4bd62df8de38dac03c44911d0e835246b Mon Sep 17 00:00:00 2001 From: Aitozi Date: Tue, 13 Aug 2024 10:44:03 +0800 Subject: [PATCH 2/2] rename --- crates/paimon/src/io/file_io.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/paimon/src/io/file_io.rs b/crates/paimon/src/io/file_io.rs index 2043fca..0d31af7 100644 --- a/crates/paimon/src/io/file_io.rs +++ b/crates/paimon/src/io/file_io.rs @@ -75,7 +75,7 @@ impl FileIO { Ok(FileStatus { size: meta.content_length(), is_dir: meta.is_dir(), - last_modification_time: meta.last_modified(), + last_modified: meta.last_modified(), path: path.to_string(), }) } @@ -100,7 +100,7 @@ impl FileIO { .map(|meta| FileStatus { size: meta.metadata().content_length(), is_dir: meta.metadata().is_dir(), - last_modification_time: meta.metadata().last_modified(), + last_modified: meta.metadata().last_modified(), path: format!("{}{}", path, meta.name()), }) .collect()) @@ -165,7 +165,7 @@ pub struct FileStatus { pub size: u64, pub is_dir: bool, pub path: String, - pub last_modification_time: Option>, + pub last_modified: Option>, } /// Input file represents a file that can be read from.