T-186: M2.3n — tools/curate-etl: curate-bars-1m CLI command (file mode) wiring run_curate_bars_1m into cli.rs + main.rs with parser tests (no new crates, no bench changes, no --from-mongo, no live Mongo/QuestDB)

This commit is contained in:
Studio 2026-12-02 19:35:23 -05:00
parent f1a9915cdf
commit eebbdd511c
4 changed files with 851 additions and 1 deletions

View file

@ -1673,7 +1673,28 @@ See [apps/stock/data-pipeline/README.md](../../apps/stock/data-pipeline/README.m
- **Bounded-memory chunking & listing-keyed splits:** Drives `RawBsonChunkReader::with_options`, `next_chunk()`, and `decode_eod_intraday_buffer` directly (the same reader and decoder wrapped by `decode_eod_intraday_chunks`, which hides chunk boundaries), resolving each bar's `listing_id` on its Eastern Time `session_date` before applying `listing_id`-keyed `qmSplits` un-adjustment (preventing split leakage across reused tickers) into one shared `IlpShardedWriter` and calling `finish()` once after EOF. Peak memory is bounded by the reference tables, `BsonStreamOptions::chunk_capacity_bytes` (growing only for a single document up to `max_doc_bytes`), per-chunk curation buffers, and one ILP batch buffer per shard.
- **Cross-chunk semantics & reporting:** `mapping_source` must be `"eod"`. Collision collapse/drop and `(listing_id, ts)` ordering apply per chunk; the same `(listing_id, ts)` appearing in two chunks is emitted twice and relies on QuestDB `DEDUP UPSERT KEYS(ts, listing_id)`. Aggregated `curate_stats.listings_out` and `curate_stats.builder.keys_out` are sums of per-chunk counts (not global distinct counts). `known_at_micros` is caller-supplied and supplies no evidence of earlier market availability.
- **Fail-closed publication:** Preflight scans `out_dir` for any pre-existing `bars_1m.shard-<digits>.ilp` file (regardless of `shard_count`) and rejects before staging, writes to exclusively created temp files in `out_dir`, flushes and `sync_all`s on `finish`, publishes via same-directory `hard_link` + temp removal, and rolls back only final files created by the current run on any publication error. CLI wiring, `--from-mongo`, and live QuestDB ingestion are separate follow-ups.
- **Fail-closed publication:** Preflight scans `out_dir` for any pre-existing `bars_1m.shard-<digits>.ilp` file (regardless of `shard_count`) and rejects before staging, writes to exclusively created temp files in `out_dir`, flushes and `sync_all`s on `finish`, publishes via same-directory `hard_link` + temp removal, and rolls back only final files created by the current run on any publication error. File-mode CLI wiring is available via `curate-bars-1m` below; `--from-mongo` and live QuestDB ingestion remain follow-ups.
### `curate-bars-1m` Command (`M2.3n`)
File-mode CLI command wiring `run_curate_bars_1m` into the `curate-etl` binary:
```bash
curate-etl curate-bars-1m \
--eod-intraday eodIntraday1M.bson \
--qm-splits qmSplits.bson \
--provider-mapping provider_mapping.tsv \
--out ./out \
--shards 4 \
--known-at-micros 1750000000000000 \
[--mapping-source eod]
```
- **Required flags:** `--eod-intraday <path>`, `--qm-splits <path>`, `--provider-mapping <path>`, `--out <dir>`, `--shards <N>` (positive base-10 integer, no default), and `--known-at-micros <i64>` (positive base-10 UTC microsecond timestamp, no default).
- **Optional flag:** `--mapping-source <name>` (defaults to `eod`; only `eod` is accepted by the runner).
- **Timestamp semantics:** `--known-at-micros` records the caller-supplied curation run timestamp verbatim in each ILP row's `known_at` column; it does not establish historical market availability.
- **Outputs & fail-closed publication:** writes `<out>/bars_1m.shard-<NN>.ilp` (`00`..`<shards-1>`) and prints the `format_curate_bars_1m_report` summary to stdout. Inherits the runner's fail-closed preflight and staging/rollback guarantees (refuses to overwrite existing `bars_1m.shard-*.ilp` files and leaves no partial shard or staging files on error).
- **File mode only:** MongoDB streaming flags (such as `--from-mongo` and `--mongo-uri`) are rejected; `--from-mongo` streaming and live QuestDB ingestion remain follow-ups.
## `run_curate_fx_1m` File-to-File Runner (`M2.3l`)