T-118: M1.2ah — tools/curate-etl: wire the qmPrices.sharevolume cross-check into curate-bars-1d (zero-copy qmPrices decoder + optional --qm-prices file, re-keyed via provider_mapping) with end-to-end tests and local benchmark (no new crates, no MongoDB connection)
This commit is contained in:
parent
ae00abcee4
commit
87fad608b0
15 changed files with 2151 additions and 46 deletions
|
|
@ -453,6 +453,190 @@ fn curate_bars_1d_cli_happy_path_and_determinism_with_shuffled_bson() {
|
|||
let pq_a = fs::read(out_a.join("bars_1d/year=2024/part.parquet")).unwrap();
|
||||
let pq_b = fs::read(out_b.join("bars_1d/year=2024/part.parquet")).unwrap();
|
||||
assert_eq!(pq_a, pq_b);
|
||||
assert!(text_a.contains("qm_check: qm_prices=absent"), "{text_a}");
|
||||
}
|
||||
|
||||
fn make_qm_price_doc(code: &str, date: &str, share_volume: f64) -> Vec<u8> {
|
||||
let mut doc = RawDocumentBuf::new();
|
||||
doc.append(cstr!("qmSearchCode"), code);
|
||||
doc.append(cstr!("date"), date);
|
||||
doc.append(cstr!("sharevolume"), share_volume);
|
||||
doc.into_bytes()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn curate_bars_1d_cli_qm_prices_cross_check_and_framing_failures() {
|
||||
let dir = CliTempDir::new("qm-prices-cli");
|
||||
let eod_path = dir.path.join("eod.bson");
|
||||
let splits_path = dir.path.join("splits.bson");
|
||||
let qm_path = dir.path.join("qm.bson");
|
||||
let map_path = dir.path.join("map.tsv");
|
||||
let curr_path = dir.path.join("curr.tsv");
|
||||
|
||||
write_file(
|
||||
&map_path,
|
||||
b"eod\tNVDA.US\t2020-01-01\t\t1\nqm\tNVDA:US\t2020-01-01\t\t1\n",
|
||||
);
|
||||
write_file(&curr_path, b"1\tUSD\n");
|
||||
write_file(&splits_path, &make_split_doc("NVDA:US", "2024-06-10", 10.0));
|
||||
let d1 = make_eod_doc("NVDA.US", "2024-06-07", 1208.88, 412_390_000.0);
|
||||
let d2 = make_eod_doc("NVDA.US", "2024-06-10", 121.79, 310_000_000.0);
|
||||
write_file(&eod_path, &[d1.as_slice(), d2.as_slice()].concat());
|
||||
|
||||
// 2024-06-07 matches (41_239_000), 2024-06-10 has an injected >1% mismatch (300_000_000 vs 310_000_000).
|
||||
let q1 = make_qm_price_doc("NVDA:US", "2024-06-07", 41_239_000.0);
|
||||
let q2 = make_qm_price_doc("NVDA:US", "2024-06-10", 300_000_000.0);
|
||||
write_file(&qm_path, &[q1.as_slice(), q2.as_slice()].concat());
|
||||
|
||||
let out_no_qm = dir.path.join("out_no_qm");
|
||||
let out_with_qm = dir.path.join("out_with_qm");
|
||||
let out_eq_qm = dir.path.join("out_eq_qm");
|
||||
|
||||
let run_no_qm = run(&[
|
||||
"curate-bars-1d",
|
||||
"--eod-prices",
|
||||
eod_path.to_str().unwrap(),
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--listing-currencies",
|
||||
curr_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_no_qm.to_str().unwrap(),
|
||||
]);
|
||||
assert!(run_no_qm.status.success(), "{}", stderr(&run_no_qm));
|
||||
assert!(stdout(&run_no_qm).contains("qm_check: qm_prices=absent"));
|
||||
|
||||
// Mismatch still exits 0 and emits byte-identical Parquet.
|
||||
let run_with_qm = run(&[
|
||||
"curate-bars-1d",
|
||||
"--eod-prices",
|
||||
eod_path.to_str().unwrap(),
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--qm-prices",
|
||||
qm_path.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--listing-currencies",
|
||||
curr_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_with_qm.to_str().unwrap(),
|
||||
]);
|
||||
assert!(run_with_qm.status.success(), "{}", stderr(&run_with_qm));
|
||||
assert!(stderr(&run_with_qm).is_empty(), "{}", stderr(&run_with_qm));
|
||||
let out_text = stdout(&run_with_qm);
|
||||
assert!(out_text.contains("qm_bson:"), "{out_text}");
|
||||
assert!(out_text.contains("qm_rekey:"), "{out_text}");
|
||||
assert!(
|
||||
out_text.contains("volume_checked=2 volume_within_tolerance=1 volume_mismatched=1 volume_unchecked=0"),
|
||||
"{out_text}"
|
||||
);
|
||||
assert!(
|
||||
out_text.contains("qm_mismatch: key=NVDA.US session_date=2024-06-10"),
|
||||
"{out_text}"
|
||||
);
|
||||
|
||||
let pq_no_qm = fs::read(out_no_qm.join("bars_1d/year=2024/part.parquet")).unwrap();
|
||||
let pq_with_qm = fs::read(out_with_qm.join("bars_1d/year=2024/part.parquet")).unwrap();
|
||||
assert_eq!(pq_no_qm, pq_with_qm);
|
||||
|
||||
// Equals syntax (`--qm-prices=<path>`) also succeeds.
|
||||
let eq_flag = format!("--qm-prices={}", qm_path.to_str().unwrap());
|
||||
let run_eq = run(&[
|
||||
"curate-bars-1d",
|
||||
"--eod-prices",
|
||||
eod_path.to_str().unwrap(),
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
&eq_flag,
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--listing-currencies",
|
||||
curr_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_eq_qm.to_str().unwrap(),
|
||||
]);
|
||||
assert!(run_eq.status.success(), "{}", stderr(&run_eq));
|
||||
assert_eq!(
|
||||
fs::read(out_eq_qm.join("bars_1d/year=2024/part.parquet")).unwrap(),
|
||||
pq_no_qm
|
||||
);
|
||||
|
||||
// Truncated --qm-prices fails closed with single-line stderr naming path, publishes nothing,
|
||||
// and preserves a pre-existing dataset.
|
||||
let trunc_qm = dir.path.join("trunc_qm.bson");
|
||||
let mut trunc_bytes = q1.clone();
|
||||
trunc_bytes.truncate(trunc_bytes.len() - 4);
|
||||
write_file(&trunc_qm, &trunc_bytes);
|
||||
|
||||
let out_trunc_fresh = dir.path.join("out_trunc_fresh");
|
||||
let res_trunc = run(&[
|
||||
"curate-bars-1d",
|
||||
"--eod-prices",
|
||||
eod_path.to_str().unwrap(),
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--qm-prices",
|
||||
trunc_qm.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--listing-currencies",
|
||||
curr_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_trunc_fresh.to_str().unwrap(),
|
||||
]);
|
||||
assert!(!res_trunc.status.success());
|
||||
assert!(stdout(&res_trunc).is_empty());
|
||||
let err_trunc = stderr(&res_trunc);
|
||||
assert_eq!(err_trunc.lines().count(), 1, "{err_trunc}");
|
||||
assert!(err_trunc.contains("trunc_qm.bson"), "{err_trunc}");
|
||||
assert!(!out_trunc_fresh.join("bars_1d").exists());
|
||||
|
||||
// Pre-existing published output is untouched on failure.
|
||||
let res_preserve = run(&[
|
||||
"curate-bars-1d",
|
||||
"--eod-prices",
|
||||
eod_path.to_str().unwrap(),
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--qm-prices",
|
||||
trunc_qm.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--listing-currencies",
|
||||
curr_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_with_qm.to_str().unwrap(),
|
||||
]);
|
||||
assert!(!res_preserve.status.success());
|
||||
assert_eq!(
|
||||
fs::read(out_with_qm.join("bars_1d/year=2024/part.parquet")).unwrap(),
|
||||
pq_with_qm
|
||||
);
|
||||
|
||||
// Missing --qm-prices file fails closed.
|
||||
let missing_qm = dir.path.join("missing_qm.bson");
|
||||
let res_missing = run(&[
|
||||
"curate-bars-1d",
|
||||
"--eod-prices",
|
||||
eod_path.to_str().unwrap(),
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--qm-prices",
|
||||
missing_qm.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--listing-currencies",
|
||||
curr_path.to_str().unwrap(),
|
||||
"--out",
|
||||
dir.path.join("out_missing").to_str().unwrap(),
|
||||
]);
|
||||
assert!(!res_missing.status.success());
|
||||
let err_missing = stderr(&res_missing);
|
||||
assert_eq!(err_missing.lines().count(), 1, "{err_missing}");
|
||||
assert!(err_missing.contains("missing_qm.bson"), "{err_missing}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -704,7 +888,10 @@ fn bench_curate_bars_cmd_small_run_succeeds_and_reports_splits() {
|
|||
let text = stdout(&out);
|
||||
assert!(text.contains("curate-etl bench-curate-bars-cmd"), "{text}");
|
||||
assert!(text.contains("rows=2000 "), "{text}");
|
||||
assert!(text.contains("qm_docs="), "{text}");
|
||||
assert!(text.contains("decode:"), "{text}");
|
||||
assert!(text.contains("qm:"), "{text}");
|
||||
assert!(text.contains("injected="), "{text}");
|
||||
assert!(text.contains("curate:"), "{text}");
|
||||
assert!(text.contains("write:"), "{text}");
|
||||
assert!(text.contains("total:"), "{text}");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue