T-143: M2.2c — tools/curate-etl: Zstd Parquet writer for fundamentals_pit/year=YYYY/part.parquet (flat latest-period + TTM snapshot rows from FundamentalsSnapshot<i32>) with restatement round-trip test (no new crates, no CLI/bench changes)
This commit is contained in:
parent
f1a60dcdd0
commit
288fdec14d
5 changed files with 2619 additions and 2 deletions
|
|
@ -217,9 +217,9 @@ Schemas:
|
|||
- **`adj_factors/part.parquet`**: `(listing_id INT32, ex_date DATE, split_factor DOUBLE, div_cash DOUBLE, div_currency VARCHAR, cum_split_factor DOUBLE, cum_total_factor DOUBLE, known_at TIMESTAMPTZ)`.
|
||||
- **`corporate_actions/part.parquet`**: `(listing_id INT32, ex_date DATE, declared_date DATE, kind VARCHAR, ratio DOUBLE, cash_amount DOUBLE, currency VARCHAR, successor_listing_id INT32, terminal_return DOUBLE, known_at TIMESTAMPTZ, known_at_source VARCHAR)`.
|
||||
- **`fundamentals_bitemporal/part.parquet`**: `(listing_id INT32, period_end DATE, fiscal_period VARCHAR, currency VARCHAR, known_at TIMESTAMPTZ, known_at_source VARCHAR, <standardized statement columns...>)`.
|
||||
- **`fundamentals_pit/year=YYYY/part.parquet`**: Wide pre-resolved point-in-time snapshots keyed by `(listing_id INT32, effective_known_at TIMESTAMPTZ)` where each row computes:
|
||||
- **`fundamentals_pit/year=YYYY/part.parquet`**: Pre-resolved point-in-time snapshots partitioned by the UTC year of `effective_known_at`, sorted and unique by `(listing_id, effective_known_at)`: `(listing_id INT32 NOT NULL, effective_known_at TIMESTAMPTZ NOT NULL, known_at_source VARCHAR NOT NULL, has_estimated_lag BOOLEAN NOT NULL, period_end DATE NOT NULL, fiscal_period VARCHAR NOT NULL, currency VARCHAR NOT NULL, period_known_at TIMESTAMPTZ NOT NULL, revenue DOUBLE, net_income DOUBLE, operating_cash_flow DOUBLE, total_assets DOUBLE, total_equity DOUBLE, shares_outstanding DOUBLE, ttm_period_end DATE, ttm_currency VARCHAR, ttm_revenue DOUBLE, ttm_net_income DOUBLE, ttm_operating_cash_flow DOUBLE, ttm_has_estimated_lag BOOLEAN)` (all `ttm_*` columns are `NULL` when 4 consecutive standalone quarters in one currency are unavailable). Each snapshot computes:
|
||||
$$\text{latest } k \text{ periods by } \texttt{period\_end} \text{ of } \left(\arg\max_{\texttt{known\_at} \le \texttt{effective\_known\_at}} \text{ per } (\texttt{listing\_id}, \texttt{period\_end})\right)$$
|
||||
forward-filling un-restated fields and precomputing 4-quarter TTM sums so a restatement of Q1 never overwrites Q2.
|
||||
forward-filling un-restated fields and precomputing 4-quarter TTM sums so a restatement of Q1 never overwrites Q2; the physical Parquet row flattens the latest visible resolved period (`periods[0]`) alongside the precomputed `ttm_*` columns (lagged slots `periods[1..]` are omitted).
|
||||
- **`events/year=YYYY/part.parquet`**: `(listing_id INT32, ts TIMESTAMPTZ, known_at TIMESTAMPTZ, known_at_source VARCHAR, kind VARCHAR, subtype VARCHAR, payload_json VARCHAR)`.
|
||||
- **`shorts/part.parquet`**: `(listing_id INT32, report_date DATE, known_at TIMESTAMPTZ, shares_short DOUBLE, net_change DOUBLE, pct_float DOUBLE, source VARCHAR)`.
|
||||
- **`macro/part.parquet`**: `(country_iso VARCHAR, indicator VARCHAR, period_date DATE, known_at TIMESTAMPTZ, known_at_source VARCHAR, value DOUBLE)`.
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ pub mod parquet_adj;
|
|||
pub mod parquet_bars;
|
||||
pub mod parquet_corporate_actions;
|
||||
pub mod parquet_events;
|
||||
pub mod parquet_fundamentals;
|
||||
pub mod parquet_fx;
|
||||
mod parquet_publish;
|
||||
pub mod parquet_shorts;
|
||||
|
|
@ -160,6 +161,11 @@ pub use parquet_events::{
|
|||
events_parquet_schema, write_events_dataset, EventsParquetRow, EventsWriteOptions,
|
||||
EventsWriteStats, ParquetEventsError,
|
||||
};
|
||||
pub use parquet_fundamentals::{
|
||||
fundamentals_pit_parquet_schema, write_fundamentals_pit_dataset, FundamentalsPitLatestPeriod,
|
||||
FundamentalsPitParquetRow, FundamentalsPitWriteOptions, FundamentalsPitWriteStats,
|
||||
ParquetFundamentalsError,
|
||||
};
|
||||
pub use parquet_fx::{
|
||||
fx_1d_parquet_schema, write_fx_1d_dataset, Fx1dParquetRow, Fx1dWriteOptions, Fx1dWriteStats,
|
||||
ParquetFxError,
|
||||
|
|
|
|||
1327
tools/curate-etl/src/parquet_fundamentals.rs
Normal file
1327
tools/curate-etl/src/parquet_fundamentals.rs
Normal file
File diff suppressed because it is too large
Load diff
1265
tools/curate-etl/src/parquet_fundamentals_tests.rs
Normal file
1265
tools/curate-etl/src/parquet_fundamentals_tests.rs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -363,6 +363,25 @@ fn next_column<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn write_bool_col(
|
||||
rg_writer: &mut SerializedRowGroupWriter<'_, BufWriter<File>>,
|
||||
values: &[bool],
|
||||
def_levels: Option<&[i16]>,
|
||||
) -> Result<(), ParquetError> {
|
||||
let mut col = next_column(rg_writer)?;
|
||||
match col.untyped() {
|
||||
ColumnWriter::BoolColumnWriter(typed) => {
|
||||
typed.write_batch(values, def_levels, None)?;
|
||||
}
|
||||
_ => {
|
||||
return Err(ParquetError::General(
|
||||
"expected BOOLEAN column writer".to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
col.close()
|
||||
}
|
||||
|
||||
pub(crate) fn write_i32_col(
|
||||
rg_writer: &mut SerializedRowGroupWriter<'_, BufWriter<File>>,
|
||||
values: &[i32],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue