Skip to content

Commit 487655e

Browse files
author
Devdutt Shenoi
committed
fix: panic on unexpected filename structure
1 parent 8c2407d commit 487655e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/parseable/streams.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ static ARROWS_NAME_STRUCTURE: Lazy<Regex> = Lazy::new(|| {
7070
Regex::new(r"^[[:alnum:]]+\.(?P<front>\S+)\.\d+\.data\.arrows$").expect("Validated regex")
7171
});
7272

73+
fn arrow_path_to_parquet(path: &Path, random_string: &str) -> Option<PathBuf> {
74+
let filename = path.file_name().unwrap().to_str().unwrap();
75+
let filename = ARROWS_NAME_STRUCTURE
76+
.captures(filename)
77+
.and_then(|c| c.get(1))?
78+
.as_str();
79+
let filename_with_random_number = format!("{filename}.data.{random_string}.arrows");
80+
let mut parquet_path = path.to_owned();
81+
parquet_path.set_file_name(filename_with_random_number);
82+
parquet_path.set_extension("parquet");
83+
84+
Some(parquet_path)
85+
}
86+
7387
#[derive(Debug, thiserror::Error)]
7488
#[error("Stream not found: {0}")]
7589
pub struct StreamNotFound(pub String);
@@ -222,12 +236,13 @@ impl Stream {
222236
&arrow_file_path, self.stream_name
223237
);
224238
remove_file(&arrow_file_path).unwrap();
225-
} else {
226-
let key = Self::arrow_path_to_parquet(&arrow_file_path, &random_string);
239+
} else if let Some(key) = arrow_path_to_parquet(&arrow_file_path, &random_string) {
227240
grouped_arrow_file
228241
.entry(key)
229242
.or_default()
230243
.push(arrow_file_path);
244+
} else {
245+
warn!("Unexpected arrows file: {}", arrow_file_path.display());
231246
}
232247
}
233248
grouped_arrow_file
@@ -286,21 +301,6 @@ impl Stream {
286301
}
287302
}
288303

289-
fn arrow_path_to_parquet(path: &Path, random_string: &str) -> PathBuf {
290-
let filename = path.file_name().unwrap().to_str().unwrap();
291-
let filename = ARROWS_NAME_STRUCTURE
292-
.captures(filename)
293-
.unwrap()
294-
.get(1)
295-
.unwrap()
296-
.as_str();
297-
let filename_with_random_number = format!("{filename}.data.{random_string}.arrows");
298-
let mut parquet_path = path.to_owned();
299-
parquet_path.set_file_name(filename_with_random_number);
300-
parquet_path.set_extension("parquet");
301-
parquet_path
302-
}
303-
304304
/// Converts arrow files in staging into parquet files, does so only for past minutes when run with `!shutdown_signal`
305305
pub fn prepare_parquet(&self, shutdown_signal: bool) -> Result<(), StagingError> {
306306
info!(

0 commit comments

Comments
 (0)