diff --git a/tools/curate-etl/src/parquet_fundamentals.rs b/tools/curate-etl/src/parquet_fundamentals.rs index 9e804d26..0bc2a9b4 100644 --- a/tools/curate-etl/src/parquet_fundamentals.rs +++ b/tools/curate-etl/src/parquet_fundamentals.rs @@ -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, diff --git a/tools/curate-etl/src/parquet_fundamentals_tests.rs b/tools/curate-etl/src/parquet_fundamentals_tests.rs index 8e15ea38..de8b46e2 100644 --- a/tools/curate-etl/src/parquet_fundamentals_tests.rs +++ b/tools/curate-etl/src/parquet_fundamentals_tests.rs @@ -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,