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:
Studio 2026-12-01 22:11:08 -05:00
parent 065af2eade
commit bb1eca42b1
2 changed files with 58 additions and 1 deletions

View file

@ -49,7 +49,9 @@ use parquet::file::properties::{WriterProperties, WriterPropertiesPtr};
use parquet::file::writer::SerializedFileWriter;
use parquet::schema::types::{ColumnPath, Type, TypePtr};
use crate::events::partition_year_utc;
use crate::events::{
partition_year_utc, KNOWN_AT_SOURCE_FILING_TIMESTAMP, KNOWN_AT_SOURCE_STATUTORY_LAG,
};
use crate::fundamentals::{FundamentalsFields, FundamentalsSnapshot, FundamentalsTtm};
pub use crate::parquet_bars::{MAX_PARQUET_YEAR, MIN_PARQUET_YEAR};
use crate::parquet_publish::{
@ -220,6 +222,12 @@ pub enum ParquetFundamentalsError {
listing_id: i32,
effective_known_at_micros: i64,
},
InvalidKnownAtSource {
row_index: usize,
listing_id: i32,
effective_known_at_micros: i64,
value: String,
},
EmptyFiscalPeriod {
row_index: usize,
listing_id: i32,
@ -314,6 +322,15 @@ impl fmt::Display for ParquetFundamentalsError {
f,
"empty known_at_source at row {row_index} for ({listing_id}, {effective_known_at_micros}): must be non-empty"
),
Self::InvalidKnownAtSource {
row_index,
listing_id,
effective_known_at_micros,
value,
} => write!(
f,
"invalid known_at_source {value:?} at row {row_index} for ({listing_id}, {effective_known_at_micros}): expected {KNOWN_AT_SOURCE_FILING_TIMESTAMP:?} or {KNOWN_AT_SOURCE_STATUTORY_LAG:?}"
),
Self::EmptyFiscalPeriod {
row_index,
listing_id,
@ -594,6 +611,16 @@ fn validate_row(
effective_known_at_micros: row.effective_known_at_micros,
});
}
if row.known_at_source.as_ref() != KNOWN_AT_SOURCE_FILING_TIMESTAMP
&& row.known_at_source.as_ref() != KNOWN_AT_SOURCE_STATUTORY_LAG
{
return Err(ParquetFundamentalsError::InvalidKnownAtSource {
row_index,
listing_id: row.listing_id,
effective_known_at_micros: row.effective_known_at_micros,
value: row.known_at_source.to_string(),
});
}
if latest.fiscal_period.trim().is_empty() {
return Err(ParquetFundamentalsError::EmptyFiscalPeriod {
row_index,

View file

@ -1766,6 +1766,36 @@ fn remaining_validation_errors_are_typed_and_publish_nothing() {
"got {err:?}"
);
let mut invalid_source = make_row(1, ts, day(2024, 3, 31), Some(1.0), None);
invalid_source.known_at_source = Cow::Borrowed("manual_override");
let err = run("qa-invalid-source", invalid_source, defaults);
assert!(
matches!(
err,
ParquetFundamentalsError::InvalidKnownAtSource {
row_index: 1,
ref value,
..
} if value == "manual_override"
),
"got {err:?}"
);
let mut padded_source = make_row(1, ts, day(2024, 3, 31), Some(1.0), None);
padded_source.known_at_source = Cow::Borrowed(" filing_timestamp ");
let err = run("qa-padded-source", padded_source, defaults);
assert!(
matches!(
err,
ParquetFundamentalsError::InvalidKnownAtSource {
row_index: 1,
ref value,
..
} if value == " filing_timestamp "
),
"got {err:?}"
);
let blank_ttm_currency = make_row(
1,
ts,