Skip to content

Commit

Permalink
fix: test_fulltext_intm_path (#4314)
Browse files Browse the repository at this point in the history
* fix: test_fulltext_intm_path

Signed-off-by: Zhenchi <[email protected]>

* address comments

Signed-off-by: Zhenchi <[email protected]>

---------

Signed-off-by: Zhenchi <[email protected]>
  • Loading branch information
zhongzc authored Jul 8, 2024
1 parent 9686113 commit 4811fe8
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/mito2/src/sst/index/intermediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ impl IntermediateManager {
#[derive(Debug, Clone)]
pub struct IntermediateLocation {
files_dir: String,
sst_dir: String,
}

impl IntermediateLocation {
Expand All @@ -97,13 +96,12 @@ impl IntermediateLocation {
let uuid = Uuid::new_v4();
Self {
files_dir: format!("{INTERMEDIATE_DIR}/{region_id}/{sst_file_id}/{uuid}/"),
sst_dir: format!("{INTERMEDIATE_DIR}/{region_id}/{sst_file_id}/"),
}
}

/// Returns the directory to clean up when the sorting is done
pub fn dir_to_cleanup(&self) -> &str {
&self.sst_dir
&self.files_dir
}

/// Returns the path of the directory for intermediate files associated with a column:
Expand All @@ -121,6 +119,8 @@ impl IntermediateLocation {

#[cfg(test)]
mod tests {
use std::ffi::OsStr;

use common_test_util::temp_dir;
use regex::Regex;

Expand Down Expand Up @@ -152,11 +152,6 @@ mod tests {
let sst_file_id = FileId::random();
let location = IntermediateLocation::new(&RegionId::new(0, 0), &sst_file_id);

assert_eq!(
location.dir_to_cleanup(),
format!("{INTERMEDIATE_DIR}/0/{sst_file_id}/")
);

let re = Regex::new(&format!(
"{INTERMEDIATE_DIR}/0/{sst_file_id}/{}/",
r"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}"
Expand Down Expand Up @@ -187,21 +182,19 @@ mod tests {
let manager = IntermediateManager::init_fs(&aux_path).await.unwrap();
let region_id = RegionId::new(0, 0);
let sst_file_id = FileId::random();
let column_id = 0;
let column_id = 1;
let fulltext_path = manager.fulltext_path(&region_id, &sst_file_id, column_id);

if cfg!(windows) {
let p = fulltext_path.to_string_lossy().to_string();
let r = Regex::new(&format!(
"{aux_path}\\\\{INTERMEDIATE_DIR}\\\\0\\\\{sst_file_id}\\\\fulltext-0-\\w{{8}}-\\w{{4}}-\\w{{4}}-\\w{{4}}-\\w{{12}}",
)).unwrap();
assert!(r.is_match(&p));
} else {
let p = fulltext_path.to_string_lossy().to_string();
let r = Regex::new(&format!(
"{aux_path}/{INTERMEDIATE_DIR}/0/{sst_file_id}/fulltext-0-\\w{{8}}-\\w{{4}}-\\w{{4}}-\\w{{4}}-\\w{{12}}",
)).unwrap();
assert!(r.is_match(&p));
let mut pi = fulltext_path.iter();
for a in temp_dir.path().iter() {
assert_eq!(a, pi.next().unwrap());
}
assert_eq!(pi.next().unwrap(), INTERMEDIATE_DIR);
assert_eq!(pi.next().unwrap(), "0"); // region id
assert_eq!(pi.next().unwrap(), OsStr::new(&sst_file_id.to_string())); // sst file id
assert!(Regex::new(r"fulltext-1-\w{8}-\w{4}-\w{4}-\w{4}-\w{12}")
.unwrap()
.is_match(&pi.next().unwrap().to_string_lossy())); // fulltext path
assert!(pi.next().is_none());
}
}

0 comments on commit 4811fe8

Please sign in to comment.