T-162: M2.2h — tools/curate-etl: pure posts curation stage (CeoPost<K> → build_posts → provider_mapping on Eastern post date → EventsParquetRows → events Zstd Parquet) in curate_posts.rs with tests (no new crates, no CLI/bench changes, no live Mongo)
This commit is contained in:
parent
52306675df
commit
ffd41b209f
4 changed files with 1284 additions and 1 deletions
|
|
@ -142,7 +142,7 @@ Rules:
|
|||
4. **Global `spiel_id` deduplication & deterministic tie-break:** Deduplicates globally on `spiel_id` before splitting into `newswire` and `retail`. Within each `spiel_id` group, the survivor is the row with the greatest `known_at`, breaking ties by the maximum lexicographic tuple `(posted_at, is_edited, is_bot, key, user_id, text)` (`None < Some` for `user_id`), with zero dependence on input order. The remaining `group_len - 1` rows are counted in `stats.duplicates_dropped`.
|
||||
5. **Sort order & invariants:** Both `newswire` and `retail` are sorted strictly ascending by `(key, known_at, spiel_id)`. Any input permutation yields identical `newswire`, `retail`, and `stats`, and `input == newswire + retail + duplicates_dropped + rejected_invalid`.
|
||||
|
||||
Deferred out of `src/posts.rs`: `ceoPosts` raw-BSON decoding (pending live `edited` BSON type verification), `provider_mapping` resolution, Parquet writing, CLI subcommand, and benchmarks.
|
||||
Deferred out of `src/posts.rs`: `curate-posts` CLI subcommand, benchmark, live `ceoPosts` verification (including live `edited` BSON type verification), and co-publishing with `curate-events` output (offline raw-BSON decoding lives in `src/bson_ceo_posts.rs`, `events` Parquet row mapping in `src/parquet_posts.rs`, and `provider_mapping` listing resolution + Parquet writing in `src/curate_posts.rs`).
|
||||
|
||||
## `events` Builder (`M1.2g`)
|
||||
|
||||
|
|
@ -890,6 +890,30 @@ Command (`2026-11-28`, two back-to-back runs with identical checksum `0x0a1b7ace
|
|||
- Parquet write: `elapsed=682.82 ms`, `throughput=709419 rows/s`
|
||||
- Combined (stage → Parquet): `elapsed=1272.06 ms`, `throughput=393065 rows/s`
|
||||
|
||||
## `posts` Curation Stage (`M2.2h`)
|
||||
|
||||
`curate_posts` and `curate_and_write_posts` (`src/curate_posts.rs`) join `build_posts`, `ProviderMappingTable`, `parquet_posts`, and `write_events_dataset` into contract `EventsParquetRow` records strictly ascending in the 7-field writer sort key `(listing_id, ts_micros, kind, subtype, payload_json, known_at_micros, known_at_source)`.
|
||||
|
||||
1. **Contract & Eastern-posting-date mapping rules:**
|
||||
- Validates that `mapping_source` is non-blank before consuming the input iterator (`CuratePostsError::EmptyMappingSource`), then runs `build_posts` unchanged on source keys so global `spiel_id` deduplication, `bot == "1"` newswire vs. retail splitting, and the `edited` text `known_at` guard execute before listing resolution.
|
||||
- **Mapping date (`posted_at` in `America/Toronto`):** resolves `(mapping_source, key, et_date) -> listing_id` where `et_date` is the Eastern local calendar date of `posted_at` computed via `session_close::utc_micros_to_et_local` (supported Eastern calendar range `1976-01-01..=2030-12-31`, i.e. `1976-01-01T05:00:00Z..=2031-01-01T04:59:59.999999Z`). Never uses the UTC date and never uses the `known_at` date, so a post edited days later stays on the listing active when it was posted while its text remains guarded by `known_at`.
|
||||
- Uses one `ProviderMappingTable::cursor_for` per contiguous `key` run in each builder stream (`newswire`, then `retail`); because `build_posts` sorts by `(key, known_at, spiel_id)` rather than `posted_at`, backward `et_date` steps use `ProviderMappingCursor::resolve`'s binary-search fallback automatically.
|
||||
- Converts each mapped `PostRow<i32>` via `EventsParquetRow::from` (reusing `parquet_posts` labels `kind = "post"`, `subtype = "newswire" | "retail"`, `known_at_source = "post_timestamp" | "post_edited"`, and its RFC 8259 `payload_json` encoder), then sorts in place by the 7-field writer key and collapses exact 7-field duplicates into `listing_duplicate_collapsed`.
|
||||
- `curate_and_write_posts` publishes Zstd Parquet partitions to `<out_dir>/events/year=YYYY/part.parquet` (partitioned by UTC calendar year of `ts_micros`). Any `CuratePostsError` returns before `write_events_dataset` is called, leaving `out_dir` untouched.
|
||||
2. **Drop policy & stats conservation invariants (`CuratePostsStats`):**
|
||||
- Posts whose `posted_at` falls outside `utc_micros_to_et_local`'s supported range are dropped and counted in `dropped_unsupported_date` (checked before mapping coverage) without aborting or panicking.
|
||||
- Posts whose `(mapping_source, key, et_date)` has no covering `provider_mapping` range are dropped into `dropped_unmapped`.
|
||||
- Exact conservation invariants:
|
||||
- `rows_in == builder.newswire + builder.retail`
|
||||
- `rows_in == rows_out + dropped_unmapped + dropped_unsupported_date + listing_duplicate_collapsed`
|
||||
- `rows_out == newswire_out + retail_out`
|
||||
- Typed errors: `CuratePostsError` (`Posts(PostsError)`, `EmptyMappingSource`) and `CuratePostsWriteError` (`Curate(CuratePostsError)`, `Parquet(ParquetEventsError)`).
|
||||
3. **Known limits & deferred work:**
|
||||
- **Global `spiel_id` deduplication & `listing_duplicate_collapsed`:** because `build_posts` deduplicates globally on `spiel_id` (keeping the greatest `known_at` and breaking ties by the maximum `(posted_at, is_edited, is_bot, key, user_id, text)` tuple) and `payload_json` carries `spiel_id`, `listing_duplicate_collapsed` is expected to be `0` for real input and exists only as a defensive writer-key uniqueness guard; when the same `spiel_id` appears under two source keys, the surviving key is chosen by `build_posts`'s existing tie-break.
|
||||
- **In-memory buffering:** both `build_posts` and the final 7-field sort buffer all rows in RAM; full-corpus memory and throughput over the 14.8M-row `ceoPosts` dataset remain unverified.
|
||||
- **Separate output root (no co-publishing with `curate-events`):** `write_events_dataset` writes and replaces `<out_dir>/events/year=YYYY/part.parquet` partitions, so publishing curated posts alongside `curate-events` filings/earnings in the same `events/` directory is not handled here; pass a dedicated `out_dir` until a unified publisher exists.
|
||||
- **Not done / deferred:** the `curate-posts` CLI subcommand, benchmark, live `ceoPosts` run/verification, and co-publishing posts with `curate-events` output remain deferred to follow-up tasks.
|
||||
|
||||
## `fx_1d` Curation Stage (`M1.2t`)
|
||||
|
||||
`curate_fx_1d` and `curate_and_write_fx_1d` (`src/curate_fx.rs`) join `build_fx_1d` and `write_fx_1d_dataset` into contract `Fx1dParquetRow` records sorted and unique by `session_date` (no `provider_mapping` lookup is needed because FX rows are keyed by `pair = "USDCAD"`, not `listing_id`).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue