T-171: M2.2m — tools/curate-etl: file-to-file fundamentals_pit runner (decode_qm_financials_chunks in bson_stream.rs + run_curate_fundamentals.rs: raw qmFinancials + qmFilings BSON dumps + provider_mapping.tsv + listing-venue TSV → curate_and_write_fundamentals → fundamentals_pit Zstd Parquet) with tests (no new crates, no CLI/bench changes, no live Mongo)
This commit is contained in:
parent
1409805206
commit
a9f153940f
2 changed files with 117 additions and 3 deletions
|
|
@ -657,9 +657,11 @@ fn validate_out_dir_and_inputs(
|
|||
}
|
||||
|
||||
// Check existing `year=YYYY` partition directories and their `part.parquet` targets for:
|
||||
// 1. two distinct `year=*` entries resolving to the same directory or `part.parquet` file
|
||||
// 1. unresolvable / dangling `year=*` symlinks (whose target could be created mid-run and
|
||||
// silently alias another year's partition),
|
||||
// 2. two distinct `year=*` entries resolving to the same directory or `part.parquet` file
|
||||
// (which would cause publishing one year to silently overwrite another year's data), and
|
||||
// 2. aliases to any input path, catching symlinked year directories whose resolved targets
|
||||
// 3. aliases to any input path, catching symlinked year directories whose resolved targets
|
||||
// live outside `<out_dir>/fundamentals_pit`.
|
||||
if fundamentals_dir_exists {
|
||||
let entries = fs::read_dir(&fundamentals_dir).map_err(|source| {
|
||||
|
|
@ -685,7 +687,22 @@ fn validate_out_dir_and_inputs(
|
|||
let mut seen_part_files: BTreeMap<PathBuf, PathBuf> = BTreeMap::new();
|
||||
|
||||
for year_dir in year_dirs {
|
||||
let resolved_year_dir = resolve_normalized_path(&year_dir);
|
||||
let entry_meta = fs::symlink_metadata(&year_dir).map_err(|source| {
|
||||
RunCurateFundamentalsError::InspectOutDir {
|
||||
path: year_dir.clone(),
|
||||
source,
|
||||
}
|
||||
})?;
|
||||
let resolved_year_dir = if entry_meta.file_type().is_symlink() {
|
||||
fs::canonicalize(&year_dir).map_err(|err| {
|
||||
RunCurateFundamentalsError::InvalidOutDir {
|
||||
path: year_dir.clone(),
|
||||
detail: format!("partition symlink target cannot be resolved: {err}"),
|
||||
}
|
||||
})?
|
||||
} else {
|
||||
resolve_normalized_path(&year_dir)
|
||||
};
|
||||
let resolved_part_via_dir = resolved_year_dir.join("part.parquet");
|
||||
let resolved_part = resolve_normalized_path(&year_dir.join("part.parquet"));
|
||||
|
||||
|
|
|
|||
|
|
@ -2080,6 +2080,103 @@ fn fundamentals_rejects_aliased_year_partitions() {
|
|||
assert_eq!(fs::read(&shared_part).unwrap(), shared_part_bytes_before);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn fundamentals_rejects_dangling_year_symlink() {
|
||||
use std::os::unix::fs::symlink;
|
||||
|
||||
let tmp = TempDirGuard::new("dangling-year-symlink");
|
||||
let map_path = tmp.path().join("map.tsv");
|
||||
let venues_path = tmp.path().join("venues.tsv");
|
||||
fs::write(&map_path, "qm\tNVDA\t2020-01-01\t\t101\n").unwrap();
|
||||
fs::write(&venues_path, "101\tus_tsx\n").unwrap();
|
||||
|
||||
// Two-year backfill with 2023 and 2024 snapshots for the same listing.
|
||||
let mut fin_bytes = make_financials_doc(
|
||||
Some("NVDA"),
|
||||
"2023-03-31",
|
||||
Some("2023-05-01"),
|
||||
"Q1",
|
||||
"USD",
|
||||
FundamentalsFields {
|
||||
revenue: Some(80.0),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
fin_bytes.extend_from_slice(&make_financials_doc(
|
||||
Some("NVDA"),
|
||||
"2024-03-31",
|
||||
Some("2024-05-01"),
|
||||
"Q1",
|
||||
"USD",
|
||||
FundamentalsFields {
|
||||
revenue: Some(120.0),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
|
||||
let mut fil_bytes = make_filing_doc(
|
||||
Some("NVDA"),
|
||||
"2023-05-01T16:10:00 EDT",
|
||||
"10-Q",
|
||||
Some("f2023"),
|
||||
None,
|
||||
);
|
||||
fil_bytes.extend_from_slice(&make_filing_doc(
|
||||
Some("NVDA"),
|
||||
"2024-05-01T16:10:00 EDT",
|
||||
"10-Q",
|
||||
Some("f2024"),
|
||||
None,
|
||||
));
|
||||
|
||||
let fin_path = tmp.path().join("fin_backfill.bson");
|
||||
let fil_path = tmp.path().join("fil_backfill.bson");
|
||||
fs::write(&fin_path, &fin_bytes).unwrap();
|
||||
fs::write(&fil_path, &fil_bytes).unwrap();
|
||||
|
||||
// Stale year=2024 symlink pointing to the not-yet-created year=2023 directory.
|
||||
let dangling_out = tmp.path().join("dangling_out");
|
||||
let dangling_ds = dangling_out.join("fundamentals_pit");
|
||||
fs::create_dir_all(&dangling_ds).unwrap();
|
||||
let dangling_link = dangling_ds.join("year=2024");
|
||||
symlink(Path::new("year=2023"), &dangling_link).unwrap();
|
||||
let before = snapshot_tree(&dangling_out);
|
||||
|
||||
let args = default_test_args(
|
||||
fin_path,
|
||||
fil_path,
|
||||
map_path,
|
||||
venues_path,
|
||||
dangling_out.clone(),
|
||||
);
|
||||
|
||||
let err_file = run_curate_fundamentals(&args).unwrap_err();
|
||||
assert!(matches!(
|
||||
err_file,
|
||||
RunCurateFundamentalsError::InvalidOutDir { ref path, .. } if path == &dangling_link
|
||||
));
|
||||
let msg_file = err_file.to_string();
|
||||
assert_single_line(&msg_file);
|
||||
assert!(msg_file.contains("year=2024"));
|
||||
assert_eq!(snapshot_tree(&dangling_out), before);
|
||||
|
||||
let err_reader = run_curate_fundamentals_with_readers(
|
||||
&args,
|
||||
Cursor::new(fin_bytes.as_slice()),
|
||||
Cursor::new(fil_bytes.as_slice()),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(matches!(
|
||||
err_reader,
|
||||
RunCurateFundamentalsError::InvalidOutDir { ref path, .. } if path == &dangling_link
|
||||
));
|
||||
let msg_reader = err_reader.to_string();
|
||||
assert_single_line(&msg_reader);
|
||||
assert!(msg_reader.contains("year=2024"));
|
||||
assert_eq!(snapshot_tree(&dangling_out), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fundamentals_empty_inputs_publish_nothing() {
|
||||
let tmp = TempDirGuard::new("empty");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue