From 74a99f079efbfcdd1ebc4adf7d715d5ddb231efb Mon Sep 17 00:00:00 2001 From: WenjunMin Date: Tue, 13 Aug 2024 11:22:24 +0800 Subject: [PATCH] feat(io): Align FileStatus with the Java API. (#45) --- 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..0d31af7 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_modified: 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_modified: 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_modified: Option>, } /// Input file represents a file that can be read from.