T-209: M2.2u — Fix ceoPosts event kind ('ceo_post') and co-publish under <curatedRoot>/events
This commit is contained in:
parent
436616b343
commit
035d18bfad
15 changed files with 1213 additions and 250 deletions
|
|
@ -12,8 +12,9 @@ use parquet::record::RowAccessor;
|
|||
|
||||
const POSTED: i64 = 1_718_460_000;
|
||||
const EDITED: i64 = POSTED + 3_600;
|
||||
const PARTITION: &str = "events/year=2024/part.parquet";
|
||||
const MAPPING: &str = "ceo_alt\tCH_1\t2020-01-01\t\t555\nceo_alt\tCH_2\t2020-01-01\t\t556\n";
|
||||
const PARTITION: &str = "events/year=2024/part-posts.parquet";
|
||||
const EVENTS_PARTITION: &str = "events/year=2024/part.parquet";
|
||||
const MAPPING: &str = "ceo_alt\tCH_1\t2020-01-01\t\t555\nceo_alt\tCH_2\t2020-01-01\t\t556\nqm\tSYM_1\t2020-01-01\t\t555\n";
|
||||
const CUSTOM_FLAGS: &[&str] = &[
|
||||
"--key-field=channel",
|
||||
"--spiel-id-field=id",
|
||||
|
|
@ -75,8 +76,42 @@ fn write_posts(path: &Path, scale: i64, edited_text: &str) {
|
|||
fs::write(path, bytes).expect("write concatenated BSON");
|
||||
}
|
||||
|
||||
fn curate_events(dir: &Path, out: &str) -> Output {
|
||||
Command::new(env!("CARGO_BIN_EXE_curate-etl"))
|
||||
.arg("curate-events")
|
||||
.current_dir(dir)
|
||||
.args([
|
||||
"--qm-filings",
|
||||
"filings.bson",
|
||||
"--qm-earnings",
|
||||
"earnings.bson",
|
||||
"--provider-mapping=mapping.tsv",
|
||||
"--out",
|
||||
out,
|
||||
"--filings-form-type-field",
|
||||
"formType",
|
||||
])
|
||||
.output()
|
||||
.expect("run curate-events")
|
||||
}
|
||||
|
||||
fn write_events_fixtures(dir: &Path) {
|
||||
let filing = doc! {
|
||||
"symbol": "SYM_1",
|
||||
"timefiled": "2024-06-10T16:15:00 EDT",
|
||||
"formType": "8-K",
|
||||
};
|
||||
let earning = doc! {
|
||||
"qmSearchCode": "SYM_1",
|
||||
"reportDate": "2024-06-12",
|
||||
"announceTime": "AMC",
|
||||
};
|
||||
fs::write(dir.join("filings.bson"), filing.to_vec().unwrap()).expect("write filings.bson");
|
||||
fs::write(dir.join("earnings.bson"), earning.to_vec().unwrap()).expect("write earnings.bson");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_publishes_runner_equivalent_posts_and_preserves_an_existing_partition() {
|
||||
fn cli_publishes_runner_equivalent_posts_and_copublishes_with_curate_events() {
|
||||
// Use the runner's fixed custom-field and edited-post fixture, plus a wire and an unmapped row.
|
||||
let path = std::env::temp_dir().join(format!("curate-posts-cli-{}", std::process::id()));
|
||||
fs::create_dir(&path).expect("create isolated test directory");
|
||||
|
|
@ -140,7 +175,7 @@ fn cli_publishes_runner_equivalent_posts_and_preserves_an_existing_partition() {
|
|||
assert_eq!(row.get_int(0).unwrap(), listing);
|
||||
assert_eq!(row.get_timestamp_micros(1).unwrap(), POSTED * 1_000_000);
|
||||
assert_eq!(row.get_timestamp_micros(2).unwrap(), known_at * 1_000_000);
|
||||
assert_eq!(row.get_string(4).unwrap(), "post");
|
||||
assert_eq!(row.get_string(4).unwrap(), "ceo_post");
|
||||
assert_eq!(row.get_string(5).unwrap(), subtype);
|
||||
}
|
||||
|
||||
|
|
@ -153,13 +188,33 @@ fn cli_publishes_runner_equivalent_posts_and_preserves_an_existing_partition() {
|
|||
assert!(!edited_text_visible(EDITED * 1_000_000 - 1));
|
||||
assert!(edited_text_visible(EDITED * 1_000_000));
|
||||
|
||||
// Co-publish curate-events into the same --out and verify part-posts.parquet stays intact.
|
||||
write_events_fixtures(&dir.0);
|
||||
let ev_res = curate_events(&dir.0, "millis");
|
||||
assert!(ev_res.status.success(), "curate-events: {:?}", ev_res);
|
||||
assert!(ev_res.stderr.is_empty());
|
||||
let events_part = dir.0.join("millis").join(EVENTS_PARTITION);
|
||||
let events_bytes = fs::read(&events_part).unwrap();
|
||||
assert_eq!(fs::read(&partition).unwrap(), baseline);
|
||||
|
||||
// Re-running curate-posts updates part-posts.parquet with exit code 0 while preserving part.parquet.
|
||||
write_posts(&bson, 1_000, "replacement");
|
||||
let retry = curate(&dir.0, "millis", "millis");
|
||||
assert_eq!(retry.status.code(), Some(1));
|
||||
assert!(retry.stdout.is_empty());
|
||||
assert!(String::from_utf8_lossy(&retry.stderr)
|
||||
.starts_with("error: refusing to overwrite existing events partition"));
|
||||
assert_eq!(fs::read(partition).unwrap(), baseline);
|
||||
assert!(retry.status.success(), "curate-posts rerun: {:?}", retry);
|
||||
assert!(retry.stderr.is_empty());
|
||||
assert_eq!(fs::read(&events_part).unwrap(), events_bytes);
|
||||
let rerun_reader = SerializedFileReader::new(File::open(&partition).unwrap()).unwrap();
|
||||
let rerun_rows: Vec<_> = rerun_reader
|
||||
.get_row_iter(None)
|
||||
.unwrap()
|
||||
.map(Result::unwrap)
|
||||
.collect();
|
||||
assert_eq!(rerun_rows.len(), 2);
|
||||
assert_eq!(rerun_rows[0].get_string(4).unwrap(), "ceo_post");
|
||||
assert!(rerun_rows[0]
|
||||
.get_string(6)
|
||||
.unwrap()
|
||||
.contains(r#""text":"replacement""#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue