Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/common/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ anyhow = { workspace = true }
async-trait = "0.1"
bytes = "1"
chrono = { workspace = true }
flagset = "0.4"
futures = "0.3"
opendal = { workspace = true }
regex = "1.6.0"
Expand Down
1 change: 0 additions & 1 deletion src/common/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub use parquet::read_parquet_schema_async;

mod stage;
pub use stage::init_stage_operator;
pub use stage::FileWithMeta;
pub use stage::StageFileInfo;
pub use stage::StageFileStatus;
pub use stage::StageFilesInfo;
50 changes: 17 additions & 33 deletions src/common/storage/src/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ use regex::Regex;
use crate::init_operator;
use crate::DataOperator;

pub struct FileWithMeta {
pub path: String,
pub metadata: Metadata,
}

impl FileWithMeta {
fn new(path: &str, meta: Metadata) -> Self {
Self {
path: path.to_string(),
metadata: meta,
}
}
}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
pub enum StageFileStatus {
NeedCopy,
Expand Down Expand Up @@ -79,11 +65,10 @@ impl StageFileInfo {
creator: None,
}
}
}

impl From<FileWithMeta> for StageFileInfo {
fn from(value: FileWithMeta) -> Self {
StageFileInfo::new(value.path, &value.metadata)
/// NOTE: update this query when add new meta
pub fn meta_query() -> flagset::FlagSet<Metakey> {
Metakey::ContentLength | Metakey::ContentMd5 | Metakey::LastModified | Metakey::Etag
}
}

Expand Down Expand Up @@ -122,7 +107,7 @@ impl StageFilesInfo {
}
}

pub async fn list(&self, operator: &Operator, first_only: bool) -> Result<Vec<FileWithMeta>> {
pub async fn list(&self, operator: &Operator, first_only: bool) -> Result<Vec<StageFileInfo>> {
if let Some(files) = &self.files {
let mut res = Vec::new();
for file in files {
Expand All @@ -132,7 +117,7 @@ impl StageFilesInfo {
.to_string();
let meta = operator.stat(&full_path).await?;
if meta.mode().is_file() {
res.push(FileWithMeta::new(&full_path, meta))
res.push(StageFileInfo::new(full_path, &meta))
} else {
return Err(ErrorCode::BadArguments(format!(
"{full_path} is not a file"
Expand All @@ -149,15 +134,15 @@ impl StageFilesInfo {
}
}

pub async fn first_file(&self, operator: &Operator) -> Result<FileWithMeta> {
pub async fn first_file(&self, operator: &Operator) -> Result<StageFileInfo> {
let mut files = self.list(operator, true).await?;
match files.pop() {
None => Err(ErrorCode::BadArguments("no file found")),
Some(f) => Ok(f),
}
}

pub fn blocking_first_file(&self, operator: &Operator) -> Result<FileWithMeta> {
pub fn blocking_first_file(&self, operator: &Operator) -> Result<StageFileInfo> {
let mut files = self.blocking_list(operator, true)?;
match files.pop() {
None => Err(ErrorCode::BadArguments("no file found")),
Expand All @@ -169,7 +154,7 @@ impl StageFilesInfo {
&self,
operator: &Operator,
first_only: bool,
) -> Result<Vec<FileWithMeta>> {
) -> Result<Vec<StageFileInfo>> {
if let Some(files) = &self.files {
let mut res = Vec::new();
for file in files {
Expand All @@ -179,7 +164,7 @@ impl StageFilesInfo {
.to_string();
let meta = operator.blocking().stat(&full_path)?;
if meta.mode().is_file() {
res.push(FileWithMeta::new(&full_path, meta))
res.push(StageFileInfo::new(full_path, &meta))
} else {
return Err(ErrorCode::BadArguments(format!(
"{full_path} is not a file"
Expand All @@ -201,11 +186,11 @@ impl StageFilesInfo {
path: &str,
pattern: Option<Regex>,
first_only: bool,
) -> Result<Vec<FileWithMeta>> {
) -> Result<Vec<StageFileInfo>> {
let root_meta = operator.stat(path).await;
match root_meta {
Ok(meta) => match meta.mode() {
EntryMode::FILE => return Ok(vec![FileWithMeta::new(path, meta)]),
EntryMode::FILE => return Ok(vec![StageFileInfo::new(path.to_string(), &meta)]),
EntryMode::DIR => {}
EntryMode::Unknown => {
return Err(ErrorCode::BadArguments("object mode is unknown"));
Expand All @@ -224,10 +209,9 @@ impl StageFilesInfo {
let mut files = Vec::new();
let mut list = operator.scan(path).await?;
while let Some(obj) = list.try_next().await? {
// todo(youngsofun): not always need Metakey::Complete
let meta = operator.metadata(&obj, Metakey::Complete).await?;
let meta = operator.metadata(&obj, StageFileInfo::meta_query()).await?;
if check_file(obj.path(), meta.mode(), &pattern) {
files.push(FileWithMeta::new(obj.path(), meta));
files.push(StageFileInfo::new(obj.path().to_string(), &meta));
if first_only {
return Ok(files);
}
Expand All @@ -253,13 +237,13 @@ fn blocking_list_files_with_pattern(
path: &str,
pattern: Option<Regex>,
first_only: bool,
) -> Result<Vec<FileWithMeta>> {
) -> Result<Vec<StageFileInfo>> {
let operator = operator.blocking();

let root_meta = operator.stat(path);
match root_meta {
Ok(meta) => match meta.mode() {
EntryMode::FILE => return Ok(vec![FileWithMeta::new(path, meta)]),
EntryMode::FILE => return Ok(vec![StageFileInfo::new(path.to_string(), &meta)]),
EntryMode::DIR => {}
EntryMode::Unknown => return Err(ErrorCode::BadArguments("object mode is unknown")),
},
Expand All @@ -277,9 +261,9 @@ fn blocking_list_files_with_pattern(
let list = operator.list(path)?;
for obj in list {
let obj = obj?;
let meta = operator.metadata(&obj, Metakey::Complete)?;
let meta = operator.metadata(&obj, StageFileInfo::meta_query())?;
if check_file(obj.path(), meta.mode(), &pattern) {
files.push(FileWithMeta::new(obj.path(), meta));
files.push(StageFileInfo::new(obj.path().to_string(), &meta));
if first_only {
return Ok(files);
}
Expand Down
7 changes: 1 addition & 6 deletions src/query/service/src/interpreters/interpreter_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ impl Interpreter for ListInterpreter {
files: None,
pattern,
};
let files: Vec<StageFileInfo> = files_info
.list(&op, false)
.await?
.into_iter()
.map(|file_with_meta| file_with_meta.into())
.collect::<Vec<_>>();
let files: Vec<StageFileInfo> = files_info.list(&op, false).await?;

let names: Vec<Vec<u8>> = files
.iter()
Expand Down
27 changes: 8 additions & 19 deletions src/query/sql/src/planner/binder/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use common_exception::Result;
use common_meta_app::principal::OnErrorMode;
use common_meta_app::principal::StageInfo;
use common_storage::init_stage_operator;
use common_storage::StageFileInfo;
use common_storage::StageFileStatus;
use common_storage::StageFilesInfo;
use common_users::UserApiProvider;
Expand Down Expand Up @@ -540,18 +539,13 @@ impl<'a> Binder {
}

let operator = init_stage_operator(&stage_info)?;
let files = if operator.info().can_blocking() {
let mut files = if operator.info().can_blocking() {
files_info.blocking_list(&operator, false)
} else {
files_info.list(&operator, false).await
}?;

let mut all_source_file_infos = files
.into_iter()
.map(|file_with_meta| StageFileInfo::new(file_with_meta.path, &file_with_meta.metadata))
.collect::<Vec<_>>();

info!("end to list files: {}", all_source_file_infos.len());
info!("end to list files: {}", files.len());

if !stmt.force {
// Status.
Expand All @@ -561,29 +555,24 @@ impl<'a> Binder {
info!(status);
}

all_source_file_infos = self
files = self
.ctx
.color_copied_files(
dst_catalog_name,
dst_database_name,
dst_table_name,
all_source_file_infos,
)
.color_copied_files(dst_catalog_name, dst_database_name, dst_table_name, files)
.await?;

info!("end to color copied files: {}", all_source_file_infos.len());
info!("end to color copied files: {}", files.len());
}

let mut need_copy_file_infos = vec![];
for file in &all_source_file_infos {
for file in &files {
if file.status == StageFileStatus::NeedCopy {
need_copy_file_infos.push(file.clone());
}
}

info!(
"copy: read all files finished, all:{}, need copy:{}, elapsed:{}",
all_source_file_infos.len(),
files.len(),
need_copy_file_infos.len(),
start.elapsed().as_secs()
);
Expand Down Expand Up @@ -630,7 +619,7 @@ impl<'a> Binder {
schema: dst_table.schema(),
from: Box::new(query_plan),
stage_info: Box::new(stage_info),
all_source_file_infos,
all_source_file_infos: files,
need_copy_file_infos,
validation_mode,
})))
Expand Down
2 changes: 1 addition & 1 deletion src/query/storages/parquet/src/parquet_table/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl ParquetTable {
self.files_info.list(&self.operator, false).await
}?
.into_iter()
.map(|f| (f.path, f.metadata.content_length()))
.map(|f| (f.path, f.size))
.collect::<Vec<_>>(),
};

Expand Down
1 change: 0 additions & 1 deletion src/query/storages/stage/src/stage_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ impl StageTable {
.list(&op, false)
.await?
.into_iter()
.map(|file_with_meta| StageFileInfo::new(file_with_meta.path, &file_with_meta.metadata))
.collect::<Vec<_>>();
Ok(infos)
}
Expand Down