diff --git a/tools/curate-etl/src/parquet_fundamentals.rs b/tools/curate-etl/src/parquet_fundamentals.rs index 0bc2a9b4..38000652 100644 --- a/tools/curate-etl/src/parquet_fundamentals.rs +++ b/tools/curate-etl/src/parquet_fundamentals.rs @@ -17,11 +17,11 @@ //! 12. `total_assets` (`DOUBLE`, `OPTIONAL`) //! 13. `total_equity` (`DOUBLE`, `OPTIONAL`) //! 14. `shares_outstanding` (`DOUBLE`, `OPTIONAL`) -//! 15. `ttm_period_end` (`INT32`, `OPTIONAL`, `DATE`) -//! 16. `ttm_currency` (`BYTE_ARRAY`, `OPTIONAL`, `STRING`) -//! 17. `ttm_revenue` (`DOUBLE`, `OPTIONAL`) -//! 18. `ttm_net_income` (`DOUBLE`, `OPTIONAL`) -//! 19. `ttm_operating_cash_flow` (`DOUBLE`, `OPTIONAL`) +//! 15. `ttm_revenue` (`DOUBLE`, `OPTIONAL`) +//! 16. `ttm_net_income` (`DOUBLE`, `OPTIONAL`) +//! 17. `ttm_operating_cash_flow` (`DOUBLE`, `OPTIONAL`) +//! 18. `ttm_period_end` (`INT32`, `OPTIONAL`, `DATE`) +//! 19. `ttm_currency` (`BYTE_ARRAY`, `OPTIONAL`, `STRING`) //! 20. `ttm_has_estimated_lag` (`BOOLEAN`, `OPTIONAL`) //! //! Each physical row flattens `periods[0]` (the latest visible resolved period) and the @@ -500,21 +500,7 @@ pub fn fundamentals_pit_parquet_schema() -> Result { .with_repetition(Repetition::OPTIONAL) .build()?, ), - // 15. ttm_period_end INT32 DATE OPTIONAL - Arc::new( - Type::primitive_type_builder("ttm_period_end", PhysicalType::INT32) - .with_repetition(Repetition::OPTIONAL) - .with_logical_type(Some(LogicalType::Date)) - .build()?, - ), - // 16. ttm_currency STRING OPTIONAL - Arc::new( - Type::primitive_type_builder("ttm_currency", PhysicalType::BYTE_ARRAY) - .with_repetition(Repetition::OPTIONAL) - .with_logical_type(Some(LogicalType::String)) - .build()?, - ), - // 17-19. TTM flow sums DOUBLE OPTIONAL + // 15-17. TTM flow sums DOUBLE OPTIONAL Arc::new( Type::primitive_type_builder("ttm_revenue", PhysicalType::DOUBLE) .with_repetition(Repetition::OPTIONAL) @@ -530,6 +516,20 @@ pub fn fundamentals_pit_parquet_schema() -> Result { .with_repetition(Repetition::OPTIONAL) .build()?, ), + // 18. ttm_period_end INT32 DATE OPTIONAL + Arc::new( + Type::primitive_type_builder("ttm_period_end", PhysicalType::INT32) + .with_repetition(Repetition::OPTIONAL) + .with_logical_type(Some(LogicalType::Date)) + .build()?, + ), + // 19. ttm_currency STRING OPTIONAL + Arc::new( + Type::primitive_type_builder("ttm_currency", PhysicalType::BYTE_ARRAY) + .with_repetition(Repetition::OPTIONAL) + .with_logical_type(Some(LogicalType::String)) + .build()?, + ), // 20. ttm_has_estimated_lag BOOLEAN OPTIONAL Arc::new( Type::primitive_type_builder("ttm_has_estimated_lag", PhysicalType::BOOLEAN) @@ -998,43 +998,43 @@ impl YearWriter { &self.buf.shares_outstanding_def, ) .map_err(map_pq)?; - // 15. ttm_period_end (INT32, OPTIONAL, DATE) - write_optional_i32_col( - &mut rg_writer, - &self.buf.ttm_period_end_values, - &self.buf.ttm_period_end_def, - ) - .map_err(map_pq)?; - // 16. ttm_currency (BYTE_ARRAY, OPTIONAL, STRING) - write_optional_interned_str_col( - &mut rg_writer, - &self.buf.ttm_currency_ids, - &self.buf.ttm_currency_def, - &self.buf.ttm_currency_interner, - scratch, - ) - .map_err(map_pq)?; - // 17. ttm_revenue (DOUBLE, OPTIONAL) + // 15. ttm_revenue (DOUBLE, OPTIONAL) write_optional_f64_col( &mut rg_writer, &self.buf.ttm_revenue_values, &self.buf.ttm_revenue_def, ) .map_err(map_pq)?; - // 18. ttm_net_income (DOUBLE, OPTIONAL) + // 16. ttm_net_income (DOUBLE, OPTIONAL) write_optional_f64_col( &mut rg_writer, &self.buf.ttm_net_income_values, &self.buf.ttm_net_income_def, ) .map_err(map_pq)?; - // 19. ttm_operating_cash_flow (DOUBLE, OPTIONAL) + // 17. ttm_operating_cash_flow (DOUBLE, OPTIONAL) write_optional_f64_col( &mut rg_writer, &self.buf.ttm_operating_cash_flow_values, &self.buf.ttm_operating_cash_flow_def, ) .map_err(map_pq)?; + // 18. ttm_period_end (INT32, OPTIONAL, DATE) + write_optional_i32_col( + &mut rg_writer, + &self.buf.ttm_period_end_values, + &self.buf.ttm_period_end_def, + ) + .map_err(map_pq)?; + // 19. ttm_currency (BYTE_ARRAY, OPTIONAL, STRING) + write_optional_interned_str_col( + &mut rg_writer, + &self.buf.ttm_currency_ids, + &self.buf.ttm_currency_def, + &self.buf.ttm_currency_interner, + scratch, + ) + .map_err(map_pq)?; // 20. ttm_has_estimated_lag (BOOLEAN, OPTIONAL) write_bool_col( &mut rg_writer, diff --git a/tools/curate-etl/src/parquet_fundamentals_tests.rs b/tools/curate-etl/src/parquet_fundamentals_tests.rs index de8b46e2..922f4435 100644 --- a/tools/curate-etl/src/parquet_fundamentals_tests.rs +++ b/tools/curate-etl/src/parquet_fundamentals_tests.rs @@ -23,7 +23,8 @@ use crate::events::{ }; use crate::fundamentals::{ build_fundamentals_rows, build_fundamentals_snapshots, FinancialObservation, FiscalPeriod, - FundamentalsFields, FundamentalsSnapshot, FundamentalsTtm, StatutoryLagVenue, TtmFlowFields, + FundamentalsFields, FundamentalsPeriodSlot, FundamentalsSnapshot, FundamentalsTtm, + StatutoryLagVenue, TtmFlowFields, }; use crate::split::ymd_to_epoch_days; @@ -113,11 +114,11 @@ struct DecodedFundamentalsPitRow { total_assets: Option, total_equity: Option, shares_outstanding: Option, - ttm_period_end: Option, - ttm_currency: Option, ttm_revenue: Option, ttm_net_income: Option, ttm_operating_cash_flow: Option, + ttm_period_end: Option, + ttm_currency: Option, ttm_has_estimated_lag: Option, } @@ -345,11 +346,11 @@ fn read_parquet_rows(path: &Path) -> Vec { let total_assets = read_opt_f64(11); let total_equity = read_opt_f64(12); let shares_outstanding = read_opt_f64(13); - let ttm_period_end = read_opt_i32(14); - let ttm_currency = read_opt_str(15); - let ttm_revenue = read_opt_f64(16); - let ttm_net_income = read_opt_f64(17); - let ttm_operating_cash_flow = read_opt_f64(18); + let ttm_revenue = read_opt_f64(14); + let ttm_net_income = read_opt_f64(15); + let ttm_operating_cash_flow = read_opt_f64(16); + let ttm_period_end = read_opt_i32(17); + let ttm_currency = read_opt_str(18); let ttm_has_estimated_lag = read_opt_bool(19); for i in 0..rg_rows { @@ -368,11 +369,11 @@ fn read_parquet_rows(path: &Path) -> Vec { total_assets: total_assets[i], total_equity: total_equity[i], shares_outstanding: shares_outstanding[i], - ttm_period_end: ttm_period_end[i], - ttm_currency: ttm_currency[i].clone(), ttm_revenue: ttm_revenue[i], ttm_net_income: ttm_net_income[i], ttm_operating_cash_flow: ttm_operating_cash_flow[i], + ttm_period_end: ttm_period_end[i], + ttm_currency: ttm_currency[i].clone(), ttm_has_estimated_lag: ttm_has_estimated_lag[i], }); } @@ -381,6 +382,80 @@ fn read_parquet_rows(path: &Path) -> Vec { out } +fn assert_decoded_matches_snapshot_bit_for_bit( + actual: &DecodedFundamentalsPitRow, + snapshot: &FundamentalsSnapshot, +) { + let latest = snapshot + .periods + .first() + .expect("snapshot must have at least one period"); + assert_eq!(actual.listing_id, snapshot.key); + assert_eq!( + actual.effective_known_at, + snapshot.effective_known_at_utc_micros + ); + assert_eq!(actual.known_at_source, snapshot.known_at_source); + assert_eq!(actual.has_estimated_lag, snapshot.has_estimated_lag); + assert_eq!(actual.period_end, latest.period_end); + assert_eq!(actual.fiscal_period, latest.fiscal_period.as_str()); + assert_eq!(actual.currency, latest.currency); + assert_eq!(actual.period_known_at, latest.known_at_utc_micros); + + assert_eq!( + actual.revenue.map(f64::to_bits), + latest.fields.revenue.map(f64::to_bits) + ); + assert_eq!( + actual.net_income.map(f64::to_bits), + latest.fields.net_income.map(f64::to_bits) + ); + assert_eq!( + actual.operating_cash_flow.map(f64::to_bits), + latest.fields.operating_cash_flow.map(f64::to_bits) + ); + assert_eq!( + actual.total_assets.map(f64::to_bits), + latest.fields.total_assets.map(f64::to_bits) + ); + assert_eq!( + actual.total_equity.map(f64::to_bits), + latest.fields.total_equity.map(f64::to_bits) + ); + assert_eq!( + actual.shares_outstanding.map(f64::to_bits), + latest.fields.shares_outstanding.map(f64::to_bits) + ); + + match &snapshot.ttm { + Some(ttm) => { + assert_eq!( + actual.ttm_revenue.map(f64::to_bits), + ttm.flows.revenue.map(f64::to_bits) + ); + assert_eq!( + actual.ttm_net_income.map(f64::to_bits), + ttm.flows.net_income.map(f64::to_bits) + ); + assert_eq!( + actual.ttm_operating_cash_flow.map(f64::to_bits), + ttm.flows.operating_cash_flow.map(f64::to_bits) + ); + assert_eq!(actual.ttm_period_end, Some(ttm.ending_period_end)); + assert_eq!(actual.ttm_currency.as_deref(), Some(ttm.currency.as_str())); + assert_eq!(actual.ttm_has_estimated_lag, Some(ttm.has_estimated_lag)); + } + None => { + assert_eq!(actual.ttm_revenue, None); + assert_eq!(actual.ttm_net_income, None); + assert_eq!(actual.ttm_operating_cash_flow, None); + assert_eq!(actual.ttm_period_end, None); + assert_eq!(actual.ttm_currency, None); + assert_eq!(actual.ttm_has_estimated_lag, None); + } + } +} + fn assert_no_transient_files(dir: &Path) { if !dir.exists() { return; @@ -654,20 +729,6 @@ fn schema_matches_contract_zstd_null_ttm_and_nullable_booleans() { None, ConvertedType::NONE, ), - ( - "ttm_period_end", - PhysicalType::INT32, - Repetition::OPTIONAL, - Some(LogicalType::Date), - ConvertedType::DATE, - ), - ( - "ttm_currency", - PhysicalType::BYTE_ARRAY, - Repetition::OPTIONAL, - Some(LogicalType::String), - ConvertedType::UTF8, - ), ( "ttm_revenue", PhysicalType::DOUBLE, @@ -689,6 +750,20 @@ fn schema_matches_contract_zstd_null_ttm_and_nullable_booleans() { None, ConvertedType::NONE, ), + ( + "ttm_period_end", + PhysicalType::INT32, + Repetition::OPTIONAL, + Some(LogicalType::Date), + ConvertedType::DATE, + ), + ( + "ttm_currency", + PhysicalType::BYTE_ARRAY, + Repetition::OPTIONAL, + Some(LogicalType::String), + ConvertedType::UTF8, + ), ( "ttm_has_estimated_lag", PhysicalType::BOOLEAN, @@ -741,19 +816,19 @@ fn schema_matches_contract_zstd_null_ttm_and_nullable_booleans() { assert_eq!(decoded[0].total_assets, None); assert_eq!(decoded[0].total_equity, Some(220.0)); assert_eq!(decoded[0].shares_outstanding, None); - assert_eq!(decoded[0].ttm_period_end, None); - assert_eq!(decoded[0].ttm_currency, None); assert_eq!(decoded[0].ttm_revenue, None); assert_eq!(decoded[0].ttm_net_income, None); assert_eq!(decoded[0].ttm_operating_cash_flow, None); + assert_eq!(decoded[0].ttm_period_end, None); + assert_eq!(decoded[0].ttm_currency, None); assert_eq!(decoded[0].ttm_has_estimated_lag, None); // Row 1: ttm_has_estimated_lag = Some(false) - assert_eq!(decoded[1].ttm_period_end, Some(day(2024, 6, 30))); - assert_eq!(decoded[1].ttm_currency.as_deref(), Some("USD")); assert_eq!(decoded[1].ttm_revenue, Some(370.0)); assert_eq!(decoded[1].ttm_net_income, Some(37.0)); assert_eq!(decoded[1].ttm_operating_cash_flow, Some(55.0)); + assert_eq!(decoded[1].ttm_period_end, Some(day(2024, 6, 30))); + assert_eq!(decoded[1].ttm_currency.as_deref(), Some("USD")); assert_eq!(decoded[1].ttm_has_estimated_lag, Some(false)); // Row 2: ttm_has_estimated_lag = Some(true), partial missing TTM flow, statutory lag source. @@ -761,16 +836,273 @@ fn schema_matches_contract_zstd_null_ttm_and_nullable_booleans() { assert!(decoded[2].has_estimated_lag); assert_eq!(decoded[2].fiscal_period, "FY"); assert_eq!(decoded[2].currency, "CAD"); - assert_eq!(decoded[2].ttm_period_end, Some(day(2024, 9, 30))); - assert_eq!(decoded[2].ttm_currency.as_deref(), Some("CAD")); assert_eq!(decoded[2].ttm_revenue, Some(450.0)); assert_eq!(decoded[2].ttm_net_income, None); assert_eq!(decoded[2].ttm_operating_cash_flow, Some(60.0)); + assert_eq!(decoded[2].ttm_period_end, Some(day(2024, 9, 30))); + assert_eq!(decoded[2].ttm_currency.as_deref(), Some("CAD")); assert_eq!(decoded[2].ttm_has_estimated_lag, Some(true)); assert_no_transient_files(&tmp.path().join("fundamentals_pit")); } +#[test] +fn builder_snapshots_round_trip_bit_for_bit_including_nulls_ttm_and_signed_zero() { + let tmp = TempDirGuard::new("builder-roundtrip-bits"); + + let venues = BTreeMap::from([ + (10_i32, StatutoryLagVenue::UsTsx), + (20_i32, StatutoryLagVenue::TsxvCse), + ]); + + let observations = vec![ + // Listing 10: 5 consecutive quarters (Q1 2023 .. Q1 2024). + // Q1..Q4 2023 all have distinct non-null flow values so Q4 2023's snapshot carries + // three distinct non-null TTM flows (catching any positional TTM column transposition). + // Q1 2024 omits operating_cash_flow so its snapshot has ttm_operating_cash_flow = None + // while ttm_revenue and ttm_net_income remain populated and distinct. + obs( + 10, + day(2023, 3, 31), + FiscalPeriod::Quarterly, + "USD", + Some(day(2023, 5, 2)), + FundamentalsFields { + revenue: Some(95.5), + net_income: Some(9.25), + operating_cash_flow: Some(17.75), + total_assets: Some(960.0), + total_equity: Some(380.0), + shares_outstanding: Some(49_500_000.0), + }, + ), + obs( + 10, + day(2023, 6, 30), + FiscalPeriod::Quarterly, + "USD", + Some(day(2023, 8, 2)), + FundamentalsFields { + revenue: Some(101.25), + net_income: Some(11.5), + operating_cash_flow: Some(19.75), + total_assets: Some(1_000.0), + total_equity: Some(400.0), + shares_outstanding: Some(50_000_000.0), + }, + ), + obs( + 10, + day(2023, 9, 30), + FiscalPeriod::Quarterly, + "USD", + Some(day(2023, 11, 3)), + FundamentalsFields { + revenue: Some(110.5), + net_income: Some(12.25), + operating_cash_flow: Some(21.0), + total_assets: None, + total_equity: Some(415.0), + shares_outstanding: Some(50_100_000.0), + }, + ), + obs( + 10, + day(2023, 12, 31), + FiscalPeriod::Quarterly, + "USD", + Some(day(2024, 2, 14)), + FundamentalsFields { + revenue: Some(125.0), + net_income: Some(14.0), + operating_cash_flow: Some(22.5), + total_assets: Some(1_120.0), + total_equity: None, + shares_outstanding: Some(50_200_000.0), + }, + ), + obs( + 10, + day(2024, 3, 31), + FiscalPeriod::Quarterly, + "USD", + Some(day(2024, 5, 1)), + FundamentalsFields { + revenue: Some(130.75), + net_income: Some(16.5), + operating_cash_flow: None, + total_assets: Some(1_150.0), + total_equity: Some(440.0), + shares_outstanding: None, + }, + ), + // Listing 20: unlinked observation -> statutory_lag_estimate (+60d for TSXV/CSE), + // ttm == None. + obs( + 20, + day(2024, 3, 31), + FiscalPeriod::Quarterly, + "CAD", + None, + FundamentalsFields { + revenue: Some(42.5), + net_income: Some(-3.5), + operating_cash_flow: None, + total_assets: Some(25.0), + total_equity: Some(12.5), + shares_outstanding: Some(8_000_000.0), + }, + ), + ]; + + let filings = vec![ + filing(10, "2023-05-02T16:05:00 EDT", "10-Q"), + filing(10, "2023-08-02T16:10:00 EDT", "10-Q"), + filing(10, "2023-11-03T16:05:00 EDT", "10-Q"), + filing(10, "2024-02-14T16:15:00 EST", "10-Q"), + filing(10, "2024-05-01T16:20:00 EDT", "10-Q"), + ]; + + let built = build_fundamentals_rows(observations, filings, &venues); + let mut snapshots = build_fundamentals_snapshots(&built.rows, 4).expect("build snapshots"); + assert_eq!(snapshots.len(), 6); + + // Append a direct snapshot carrying signed negative zero (-0.0) vs positive zero (+0.0) in + // statement fields (builder normalizes -0.0; this verifies the Parquet writer preserves exact + // IEEE-754 bit patterns without altering them). + snapshots.push(FundamentalsSnapshot { + key: 30_i32, + effective_known_at_utc_micros: utc_micros(2024, 6, 15, 20, 5, 0, 0), + known_at_source: KNOWN_AT_SOURCE_STATUTORY_LAG, + has_estimated_lag: true, + periods: vec![FundamentalsPeriodSlot { + period_end: day(2024, 3, 31), + fiscal_period: FiscalPeriod::Quarterly, + currency: "CAD".to_string(), + known_at_utc_micros: utc_micros(2024, 6, 15, 20, 5, 0, 0), + known_at_source: KNOWN_AT_SOURCE_STATUTORY_LAG, + has_estimated_lag: true, + fields: FundamentalsFields { + revenue: Some(-0.0_f64), + net_income: Some(0.0_f64), + operating_cash_flow: None, + total_assets: Some(10.0), + total_equity: None, + shares_outstanding: Some(1_000_000.0), + }, + }], + ttm: None, + }); + + let rows_from_ref: Vec = snapshots + .iter() + .map(FundamentalsPitParquetRow::from) + .collect(); + let rows_from_owned: Vec = snapshots + .clone() + .into_iter() + .map(FundamentalsPitParquetRow::from) + .collect(); + assert_eq!(rows_from_ref, rows_from_owned); + + let stats = write_fundamentals_pit_dataset( + tmp.path(), + &rows_from_ref, + FundamentalsPitWriteOptions { + row_group_rows: 2, + zstd_level: DEFAULT_ZSTD_LEVEL, + }, + ) + .expect("write builder snapshots"); + + let expected_by_year = BTreeMap::from([(2023, 3), (2024, 4)]); + assert_eq!(stats.rows_written, 7); + assert_eq!(stats.files_written, 2); + assert_eq!(stats.row_groups_written, 4); + assert_eq!(stats.rows_by_year, expected_by_year); + + let mut total_bytes = 0u64; + for (&year, &expected_count) in &expected_by_year { + let path = tmp + .path() + .join(format!("fundamentals_pit/year={year:04}/part.parquet")); + assert!(path.is_file(), "missing {}", path.display()); + total_bytes += fs::metadata(&path).expect("metadata").len(); + + let decoded = read_parquet_rows(&path); + let expected_snapshots: Vec<&FundamentalsSnapshot> = snapshots + .iter() + .filter(|s| partition_year_utc(s.effective_known_at_utc_micros) == year) + .collect(); + assert_eq!(decoded.len(), expected_count); + assert_eq!(decoded.len(), expected_snapshots.len()); + for (actual_row, snap) in decoded.iter().zip(expected_snapshots.iter()) { + assert_decoded_matches_snapshot_bit_for_bit(actual_row, snap); + } + + if year == 2024 { + // Q4 2023 snapshot (filed 2024-02-14): all three TTM flows present and distinct. + let full_ttm = decoded + .iter() + .find(|r| r.listing_id == 10 && r.period_end == day(2023, 12, 31)) + .expect("listing 10 Q4 2023 row"); + assert_eq!(full_ttm.ttm_revenue, Some(432.25)); + assert_eq!(full_ttm.ttm_net_income, Some(47.0)); + assert_eq!(full_ttm.ttm_operating_cash_flow, Some(81.0)); + assert_eq!(full_ttm.ttm_period_end, Some(day(2023, 12, 31))); + assert_eq!(full_ttm.ttm_currency.as_deref(), Some("USD")); + assert_eq!(full_ttm.ttm_has_estimated_lag, Some(false)); + + // Q1 2024 snapshot (filed 2024-05-01): partial null TTM flow. + let partial_ttm = decoded + .iter() + .find(|r| r.listing_id == 10 && r.period_end == day(2024, 3, 31)) + .expect("listing 10 Q1 2024 row"); + assert_eq!(partial_ttm.ttm_revenue, Some(467.5)); + assert_eq!(partial_ttm.ttm_net_income, Some(54.25)); + assert_eq!(partial_ttm.ttm_operating_cash_flow, None); + assert_eq!(partial_ttm.ttm_period_end, Some(day(2024, 3, 31))); + assert_eq!(partial_ttm.ttm_currency.as_deref(), Some("USD")); + assert_eq!(partial_ttm.ttm_has_estimated_lag, Some(false)); + + // Listing 20: statutory lag provenance and ttm == None. + let est_row = decoded + .iter() + .find(|r| r.listing_id == 20) + .expect("listing 20 row"); + assert_eq!(est_row.known_at_source, KNOWN_AT_SOURCE_STATUTORY_LAG); + assert!(est_row.has_estimated_lag); + assert_eq!(est_row.ttm_revenue, None); + assert_eq!(est_row.ttm_net_income, None); + assert_eq!(est_row.ttm_operating_cash_flow, None); + assert_eq!(est_row.ttm_period_end, None); + assert_eq!(est_row.ttm_currency, None); + assert_eq!(est_row.ttm_has_estimated_lag, None); + + // Listing 30: exact IEEE-754 -0.0 vs +0.0 bit preservation across Parquet write/read. + let signed_zero_row = decoded + .iter() + .find(|r| r.listing_id == 30) + .expect("listing 30 row"); + assert_eq!( + signed_zero_row.revenue.map(f64::to_bits), + Some((-0.0_f64).to_bits()) + ); + assert_ne!( + signed_zero_row.revenue.map(f64::to_bits), + Some(0.0_f64.to_bits()) + ); + assert_eq!( + signed_zero_row.net_income.map(f64::to_bits), + Some(0.0_f64.to_bits()) + ); + } + } + + assert_eq!(stats.bytes_written, total_bytes); + assert_no_transient_files(&tmp.path().join("fundamentals_pit")); +} + #[test] fn restatement_of_q1_after_q2_preserves_q2_on_disk_and_updates_ttm() { let listing_id = 42_i32; @@ -1033,6 +1365,11 @@ fn utc_year_partitioning_interleaved_listings_and_midnight_boundary() { let path_2024 = tmp.path().join("fundamentals_pit/year=2024/part.parquet"); assert!(path_2023.is_file()); assert!(path_2024.is_file()); + assert_eq!( + stats.bytes_written, + fs::metadata(&path_2023).expect("meta 2023").len() + + fs::metadata(&path_2024).expect("meta 2024").len() + ); let decoded_2023 = read_parquet_rows(&path_2023); let decoded_2024 = read_parquet_rows(&path_2024); @@ -1264,7 +1601,6 @@ fn publish_failure_on_later_year_rolls_back_replaced_and_new_partitions() { assert_no_transient_files(&tmp.path().join("fundamentals_pit")); } - // --------------------------------------------------------------------------------------------- // QA additions (T-143): full-row round-trip equality, builder estimated-lag provenance, // partial-rewrite semantics, deterministic bytes, and remaining typed validation errors. @@ -1291,11 +1627,11 @@ fn expected_decoded(row: &FundamentalsPitParquetRow) -> DecodedFundamentalsPitRo total_assets: latest.fields.total_assets, total_equity: latest.fields.total_equity, shares_outstanding: latest.fields.shares_outstanding, - ttm_period_end: ttm.map(|t| t.ending_period_end), - ttm_currency: ttm.map(|t| t.currency.clone()), ttm_revenue: ttm.and_then(|t| t.flows.revenue), ttm_net_income: ttm.and_then(|t| t.flows.net_income), ttm_operating_cash_flow: ttm.and_then(|t| t.flows.operating_cash_flow), + ttm_period_end: ttm.map(|t| t.ending_period_end), + ttm_currency: ttm.map(|t| t.currency.clone()), ttm_has_estimated_lag: ttm.map(|t| t.has_estimated_lag), } } @@ -1594,11 +1930,11 @@ fn builder_statutory_lag_snapshots_keep_estimated_provenance_on_disk() { assert_eq!(decoded[1].operating_cash_flow, None); // Only two quarters exist, so TTM is unavailable and every ttm_* column is null. for r in &decoded { - assert_eq!(r.ttm_period_end, None); - assert_eq!(r.ttm_currency, None); assert_eq!(r.ttm_revenue, None); assert_eq!(r.ttm_net_income, None); assert_eq!(r.ttm_operating_cash_flow, None); + assert_eq!(r.ttm_period_end, None); + assert_eq!(r.ttm_currency, None); assert_eq!(r.ttm_has_estimated_lag, None); } }