T-212: M2.3t — Add --qm-financials-old merge and Option B --from-mongo streaming for M2 collections in curate-etl
This commit is contained in:
parent
60ab228207
commit
f082aac436
12 changed files with 518 additions and 131 deletions
|
|
@ -1650,6 +1650,69 @@ describe('macroAsOf and crossSection point-in-time edge cases via real DuckDB (Q
|
|||
}
|
||||
});
|
||||
|
||||
test('crossSection caps universe membership at end-of-date when asOf is later, while returning revised features', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'stockbot-duckdb-xsec-late-bar-'));
|
||||
tempDirs.push(root);
|
||||
const curatedRoot = join(root, 'curated');
|
||||
const duckTempDir = join(root, 'duckdb-tmp');
|
||||
await mkdir(join(curatedRoot, 'bars_1d', 'year=2025'), { recursive: true });
|
||||
await mkdir(join(curatedRoot, 'features', 'rev_feat', 'v1', 'year=2025'), { recursive: true });
|
||||
await mkdir(duckTempDir, { recursive: true });
|
||||
|
||||
const vaultCutoffTs = Date.UTC(2025, 5, 20, 0, 0, 0, 0); // 2025-06-20T00:00:00Z
|
||||
const writer = await createNodeDuckDbExecutor();
|
||||
try {
|
||||
// Listing 401: June 7 bar known on June 7 -> member of June 7 universe.
|
||||
// Listing 402: only qualifying June 7 bar was first known on June 10 -> must NOT enter June 7 universe even when asOf is June 10.
|
||||
await writer.run(`
|
||||
COPY (
|
||||
SELECT * FROM (VALUES
|
||||
(401::INTEGER, DATE '2025-06-07', TIMESTAMPTZ '2025-06-07 20:00:00+00', 10.0::DOUBLE, 10.5::DOUBLE, 9.5::DOUBLE, 10.2::DOUBLE, 1000.0::DOUBLE, NULL::DOUBLE, 'USD'::VARCHAR, TIMESTAMPTZ '2025-06-07 20:00:00+00'),
|
||||
(402::INTEGER, DATE '2025-06-07', TIMESTAMPTZ '2025-06-07 20:00:00+00', 20.0::DOUBLE, 20.5::DOUBLE, 19.5::DOUBLE, 20.2::DOUBLE, 1000.0::DOUBLE, NULL::DOUBLE, 'USD'::VARCHAR, TIMESTAMPTZ '2025-06-10 12:00:00+00')
|
||||
) AS t(listing_id, session_date, ts, open, high, low, close, volume, vwap, currency, known_at)
|
||||
) TO '${join(curatedRoot, 'bars_1d', 'year=2025', 'part.parquet')}' (FORMAT PARQUET)
|
||||
`);
|
||||
|
||||
// rev_feat@v1: listing 401 has original (1.0 on June 7) and revision (2.5 on June 10);
|
||||
// listing 402 also has a feature row on June 7/10, but must stay excluded from the universe.
|
||||
await writer.run(`
|
||||
COPY (
|
||||
SELECT * FROM (VALUES
|
||||
(401::INTEGER, TIMESTAMPTZ '2025-06-07 20:00:00+00', TIMESTAMPTZ '2025-06-07 20:00:00+00', 1.0::DOUBLE),
|
||||
(401::INTEGER, TIMESTAMPTZ '2025-06-07 20:00:00+00', TIMESTAMPTZ '2025-06-10 12:00:00+00', 2.5::DOUBLE),
|
||||
(402::INTEGER, TIMESTAMPTZ '2025-06-07 20:00:00+00', TIMESTAMPTZ '2025-06-10 12:00:00+00', 9.9::DOUBLE)
|
||||
) AS t(listing_id, ts, known_at, value)
|
||||
) TO '${join(curatedRoot, 'features', 'rev_feat', 'v1', 'year=2025', 'part.parquet')}' (FORMAT PARQUET)
|
||||
`);
|
||||
} finally {
|
||||
await writer.close();
|
||||
}
|
||||
|
||||
const opened = await openDuckDbMarketDataStore({
|
||||
curatedRoot,
|
||||
vaultCutoffTs,
|
||||
env: budgetEnv(duckTempDir),
|
||||
});
|
||||
try {
|
||||
const sameDay = await opened.store.crossSection({
|
||||
features: ['rev_feat@v1'],
|
||||
date: '2025-06-07',
|
||||
universe: 'US_EQ',
|
||||
});
|
||||
expect(sameDay.rows).toEqual([{ listing_id: 401, 'rev_feat@v1': 1.0 }]);
|
||||
|
||||
const laterAsOf = await opened.store.crossSection({
|
||||
features: ['rev_feat@v1'],
|
||||
date: '2025-06-07',
|
||||
universe: 'US_EQ',
|
||||
asOf: '2025-06-10',
|
||||
});
|
||||
expect(laterAsOf.rows).toEqual([{ listing_id: 401, 'rev_feat@v1': 2.5 }]);
|
||||
} finally {
|
||||
await opened.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('macroAsOf treats known_at == asOf as visible and honours the period_date from bound and country filter', async () => {
|
||||
// Arrange
|
||||
const root = await mkdtemp(join(tmpdir(), 'stockbot-duckdb-macro-pit-'));
|
||||
|
|
|
|||
|
|
@ -2009,11 +2009,15 @@ function planCrossSectionInternal(
|
|||
const lookbackStartDate = formatUtcDate(lookbackStartMs);
|
||||
const endDate = formatUtcDate(fenced.toMs);
|
||||
const fromIso = formatUtcIsoWithMicros(fenced.fromMs, 0);
|
||||
const toIso = formatUtcIsoWithMicros(fenced.toMs, resolveToSubMsMicros(q.date, fenced));
|
||||
const asOfIso = formatUtcIsoWithMicros(
|
||||
fenced.asOfMs,
|
||||
resolveAsOfSubMsMicros(rawAsOf, q.date, fenced)
|
||||
);
|
||||
const toSubMsMicros = resolveToSubMsMicros(q.date, fenced);
|
||||
const asOfSubMsMicros = resolveAsOfSubMsMicros(rawAsOf, q.date, fenced);
|
||||
const toIso = formatUtcIsoWithMicros(fenced.toMs, toSubMsMicros);
|
||||
const asOfIso = formatUtcIsoWithMicros(fenced.asOfMs, asOfSubMsMicros);
|
||||
const universeKnownAtIso =
|
||||
fenced.asOfMs < fenced.toMs ||
|
||||
(fenced.asOfMs === fenced.toMs && asOfSubMsMicros < toSubMsMicros)
|
||||
? asOfIso
|
||||
: toIso;
|
||||
const featureYear = new Date(fenced.fromMs).getUTCFullYear();
|
||||
|
||||
const barsPath = joinCuratedPath(curatedRoot, 'bars_1d/year=*/part.parquet');
|
||||
|
|
@ -2025,7 +2029,13 @@ function planCrossSectionInternal(
|
|||
const ctes: string[] = [
|
||||
`u AS (SELECT DISTINCT b.listing_id FROM read_parquet('${barsPath}', hive_partitioning = true) AS b WHERE ${currencyPredicate} AND b.session_date >= ? AND b.session_date <= ? AND b.ts <= ? AND b.known_at <= ?)`,
|
||||
];
|
||||
const params: DuckDbParam[] = [...currencies, lookbackStartDate, endDate, toIso, asOfIso];
|
||||
const params: DuckDbParam[] = [
|
||||
...currencies,
|
||||
lookbackStartDate,
|
||||
endDate,
|
||||
toIso,
|
||||
universeKnownAtIso,
|
||||
];
|
||||
|
||||
const selectCols: string[] = ['u.listing_id'];
|
||||
const joins: string[] = [];
|
||||
|
|
|
|||
|
|
@ -3464,6 +3464,50 @@ describe('planCrossSectionQuery and store.crossSection', () => {
|
|||
DEFAULT_CTX
|
||||
)
|
||||
).toThrow(VaultHoldoutFenceError);
|
||||
|
||||
// Later explicit asOf caps universe membership at end-of-date while retaining asOf for features.
|
||||
const laterAsOf = planCrossSectionQuery(
|
||||
{
|
||||
features: ['ret_1d@v1'],
|
||||
date: '2025-06-07',
|
||||
universe: 'US_EQ',
|
||||
asOf: '2025-06-10',
|
||||
},
|
||||
DEFAULT_CTX
|
||||
);
|
||||
expect(laterAsOf.params).toEqual([
|
||||
'USD',
|
||||
'2025-05-31',
|
||||
'2025-06-07',
|
||||
'2025-06-07T23:59:59.999999Z',
|
||||
'2025-06-07T23:59:59.999999Z',
|
||||
2025,
|
||||
'2025-06-07T00:00:00.000Z',
|
||||
'2025-06-07T23:59:59.999999Z',
|
||||
'2025-06-10T23:59:59.999999Z',
|
||||
]);
|
||||
|
||||
// Earlier explicit intraday asOf applies to both universe membership and features.
|
||||
const earlierAsOf = planCrossSectionQuery(
|
||||
{
|
||||
features: ['ret_1d@v1'],
|
||||
date: '2025-06-07',
|
||||
universe: 'US_EQ',
|
||||
asOf: '2025-06-07T21:00:00Z',
|
||||
},
|
||||
DEFAULT_CTX
|
||||
);
|
||||
expect(earlierAsOf.params).toEqual([
|
||||
'USD',
|
||||
'2025-05-31',
|
||||
'2025-06-07',
|
||||
'2025-06-07T23:59:59.999999Z',
|
||||
'2025-06-07T21:00:00.000Z',
|
||||
2025,
|
||||
'2025-06-07T00:00:00.000Z',
|
||||
'2025-06-07T23:59:59.999999Z',
|
||||
'2025-06-07T21:00:00.000Z',
|
||||
]);
|
||||
});
|
||||
|
||||
it('maps nullable feature values via store.crossSection and rejects invalid/post-cutoff requests with zero extra calls', async () => {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@
|
|||
|
||||
use std::borrow::Borrow;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
|
|
@ -463,6 +463,12 @@ where
|
|||
/// period bounds so historical `qmFilings` can anchor `qmFinancials-old` periods.
|
||||
/// - Distinct `known_at_utc_micros` vintages across both sources are preserved as separate
|
||||
/// bitemporal versions (historical snapshots and restatements).
|
||||
/// - Undated (`report_date: None`) legacy (`qmFinancials-old`) observations have no evidence
|
||||
/// linking their values to an inferred periodic filing: they are never labeled
|
||||
/// `filing_timestamp`, and any undated legacy observation overlapping a primary or dated vintage
|
||||
/// for the same `(key, period_end, fiscal_period)` is withheld as an unanchored vintage
|
||||
/// (`observations_dropped_unanchored_vintage`) so an overwritten legacy snapshot cannot leak
|
||||
/// revised values before an amendment.
|
||||
/// - Within a `(key, period_end, fiscal_period)` stream, an undated (`report_date: None`) legacy
|
||||
/// `statutory_lag_estimate` candidate arriving after an already-accepted earlier row for the
|
||||
/// same `fiscal_period` is dropped as a stale estimate (`observations_dropped_stale_estimate`).
|
||||
|
|
@ -492,6 +498,7 @@ where
|
|||
.saturating_add(legacy_iter.size_hint().0),
|
||||
);
|
||||
let mut earliest_period_by_key_kind: BTreeMap<(K, FiscalPeriod), i32> = BTreeMap::new();
|
||||
let mut anchored_or_primary_periods: BTreeSet<(K, i32, FiscalPeriod)> = BTreeSet::new();
|
||||
|
||||
let tagged_obs = primary_iter
|
||||
.map(|obs| (obs, false))
|
||||
|
|
@ -531,6 +538,14 @@ where
|
|||
})
|
||||
.or_insert(obs.period_end);
|
||||
|
||||
if !is_legacy || obs.report_date.is_some() {
|
||||
anchored_or_primary_periods.insert((
|
||||
obs.key.clone(),
|
||||
obs.period_end,
|
||||
obs.fiscal_period,
|
||||
));
|
||||
}
|
||||
|
||||
eligible_obs.push(EligibleObservation {
|
||||
key: obs.key,
|
||||
period_end: obs.period_end,
|
||||
|
|
@ -608,6 +623,22 @@ where
|
|||
let mut candidates: Vec<CandidateRow<K>> = Vec::with_capacity(eligible_obs.len());
|
||||
|
||||
for obs in eligible_obs {
|
||||
// An undated legacy (`qmFinancials-old`) observation carries no `report_date` proving
|
||||
// which filing produced its values. If any primary or dated vintage exists for the same
|
||||
// `(key, period_end, fiscal_period)`, withhold the undated legacy row rather than risking
|
||||
// publishing an overwritten revision before an amendment.
|
||||
if obs.is_legacy
|
||||
&& obs.report_date.is_none()
|
||||
&& anchored_or_primary_periods.contains(&(
|
||||
obs.key.clone(),
|
||||
obs.period_end,
|
||||
obs.fiscal_period,
|
||||
))
|
||||
{
|
||||
stats.observations_dropped_unanchored_vintage += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let linked_micros = filing_index
|
||||
.get(&(obs.key.clone(), obs.fiscal_period))
|
||||
.and_then(|bucket| match obs.report_date {
|
||||
|
|
@ -620,6 +651,11 @@ where
|
|||
.filter(|f| f.et_date == rd)
|
||||
.map(|f| f.utc_micros)
|
||||
}
|
||||
None if obs.is_legacy => {
|
||||
// Never treat an undated legacy observation as filing-backed without a
|
||||
// `report_date` linking it to the inferred filing.
|
||||
None
|
||||
}
|
||||
None => {
|
||||
// Earliest matching non-amended periodic filing strictly after `period_end`
|
||||
// and within the inclusive calendar-day inference window.
|
||||
|
|
|
|||
|
|
@ -1168,7 +1168,8 @@ fn legacy_merge_undated_legacy_statutory_lag_does_not_overwrite_earlier_filing_t
|
|||
assert_eq!(built.stats.rows_out, 1);
|
||||
assert_eq!(built.stats.rows_linked_to_filing, 1);
|
||||
assert_eq!(built.stats.rows_statutory_lag_estimate, 0);
|
||||
assert_eq!(built.stats.observations_dropped_stale_estimate, 1);
|
||||
assert_eq!(built.stats.observations_dropped_unanchored_vintage, 1);
|
||||
assert_eq!(built.stats.observations_dropped_stale_estimate, 0);
|
||||
assert_eq!(built.rows[0].fields.revenue, Some(210.0));
|
||||
assert_eq!(
|
||||
built.rows[0].known_at_source,
|
||||
|
|
@ -1176,6 +1177,186 @@ fn legacy_merge_undated_legacy_statutory_lag_does_not_overwrite_earlier_filing_t
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_merge_withholds_undated_legacy_overlapping_later_amendment_and_never_labels_undated_legacy_filing_backed()
|
||||
{
|
||||
let venues = venues_map(&[("ACME", StatutoryLagVenue::UsTsx)]);
|
||||
let q2_23 = day(2023, 6, 30);
|
||||
let q3_23 = day(2023, 9, 30);
|
||||
let q4_23 = day(2023, 12, 31);
|
||||
let q1_24 = day(2024, 3, 31);
|
||||
|
||||
let filings = vec![
|
||||
filing("ACME", "2023-08-05T16:30:00 EDT", "10-Q"),
|
||||
filing("ACME", "2023-11-05T16:30:00 EST", "10-Q"),
|
||||
filing("ACME", "2024-02-20T16:30:00 EST", "10-Q"),
|
||||
filing("ACME", "2024-05-05T16:30:00 EDT", "10-Q"),
|
||||
filing("ACME", "2024-07-10T16:30:00 EDT", "10-Q/A"),
|
||||
];
|
||||
|
||||
// Case 1: Legacy holds revised Q1 with no report_date; primary holds dated July amendment.
|
||||
// Both May original 10-Q and July 10-Q/A exist in qmFilings. The undated legacy Q1 must be
|
||||
// withheld so a June decision never sees revised Q1 values or an early TTM.
|
||||
let legacy_no_orig = vec![
|
||||
obs(
|
||||
"ACME",
|
||||
q2_23,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 8, 5)),
|
||||
fields_rev(90.0),
|
||||
),
|
||||
obs(
|
||||
"ACME",
|
||||
q3_23,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 11, 5)),
|
||||
fields_rev(100.0),
|
||||
),
|
||||
obs(
|
||||
"ACME",
|
||||
q4_23,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 2, 20)),
|
||||
fields_rev(110.0),
|
||||
),
|
||||
obs(
|
||||
"ACME",
|
||||
q1_24,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
None,
|
||||
fields_rev(125.0),
|
||||
),
|
||||
];
|
||||
let primary_amend = vec![obs(
|
||||
"ACME",
|
||||
q1_24,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 7, 10)),
|
||||
fields_rev(125.0),
|
||||
)];
|
||||
|
||||
let built_no_orig = build_fundamentals_rows_with_legacy(
|
||||
primary_amend.clone(),
|
||||
legacy_no_orig,
|
||||
filings.clone(),
|
||||
&venues,
|
||||
);
|
||||
assert_reconciliation(&built_no_orig);
|
||||
assert_eq!(built_no_orig.stats.observations_in, 5);
|
||||
assert_eq!(built_no_orig.stats.rows_out, 4);
|
||||
assert_eq!(built_no_orig.stats.rows_linked_to_filing, 4);
|
||||
assert_eq!(built_no_orig.stats.rows_statutory_lag_estimate, 0);
|
||||
assert_eq!(built_no_orig.stats.observations_dropped_unanchored_vintage, 1);
|
||||
|
||||
let snaps_no_orig = build_fundamentals_snapshots(&built_no_orig.rows, 4).unwrap();
|
||||
let ts_june = utc_micros(2024, 6, 15, 16, 0, 0);
|
||||
let ts_july = utc_micros(2024, 7, 15, 16, 0, 0);
|
||||
|
||||
let at_june = as_of(&snaps_no_orig, "ACME", ts_june).expect("June snapshot");
|
||||
assert_eq!(at_june.periods[0].period_end, q4_23);
|
||||
assert!(at_june.periods.iter().all(|p| p.period_end != q1_24));
|
||||
assert_eq!(at_june.ttm, None);
|
||||
|
||||
let at_july = as_of(&snaps_no_orig, "ACME", ts_july).expect("July snapshot");
|
||||
assert_eq!(at_july.periods[0].period_end, q1_24);
|
||||
assert_eq!(at_july.periods[0].fields.revenue, Some(125.0));
|
||||
assert_eq!(
|
||||
at_july.periods[0].known_at_source,
|
||||
KNOWN_AT_SOURCE_FILING_TIMESTAMP
|
||||
);
|
||||
assert_eq!(at_july.ttm.as_ref().unwrap().flows.revenue, Some(425.0));
|
||||
|
||||
// Case 2: Dated May original Q1 + undated revised legacy Q1 + dated July amendment.
|
||||
// June sees original Q1 (120) and original TTM (420); July sees amended Q1 (125) and TTM (425).
|
||||
let legacy_with_orig = vec![
|
||||
obs(
|
||||
"ACME",
|
||||
q2_23,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 8, 5)),
|
||||
fields_rev(90.0),
|
||||
),
|
||||
obs(
|
||||
"ACME",
|
||||
q3_23,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 11, 5)),
|
||||
fields_rev(100.0),
|
||||
),
|
||||
obs(
|
||||
"ACME",
|
||||
q4_23,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 2, 20)),
|
||||
fields_rev(110.0),
|
||||
),
|
||||
obs(
|
||||
"ACME",
|
||||
q1_24,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 5, 5)),
|
||||
fields_rev(120.0),
|
||||
),
|
||||
obs(
|
||||
"ACME",
|
||||
q1_24,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
None,
|
||||
fields_rev(125.0),
|
||||
),
|
||||
];
|
||||
let built_with_orig = build_fundamentals_rows_with_legacy(
|
||||
primary_amend,
|
||||
legacy_with_orig,
|
||||
filings.clone(),
|
||||
&venues,
|
||||
);
|
||||
assert_reconciliation(&built_with_orig);
|
||||
assert_eq!(built_with_orig.stats.observations_dropped_unanchored_vintage, 1);
|
||||
let snaps_with_orig = build_fundamentals_snapshots(&built_with_orig.rows, 4).unwrap();
|
||||
|
||||
let june_orig = as_of(&snaps_with_orig, "ACME", ts_june).expect("June snapshot with original Q1");
|
||||
assert_eq!(june_orig.periods[0].period_end, q1_24);
|
||||
assert_eq!(june_orig.periods[0].fields.revenue, Some(120.0));
|
||||
assert_eq!(june_orig.ttm.as_ref().unwrap().flows.revenue, Some(420.0));
|
||||
|
||||
let july_amended = as_of(&snaps_with_orig, "ACME", ts_july).expect("July snapshot after amendment");
|
||||
assert_eq!(july_amended.periods[0].period_end, q1_24);
|
||||
assert_eq!(july_amended.periods[0].fields.revenue, Some(125.0));
|
||||
assert_eq!(july_amended.ttm.as_ref().unwrap().flows.revenue, Some(425.0));
|
||||
|
||||
// Case 3: Sole non-overlapping undated legacy statement with an unamended filing in window
|
||||
// must NOT be labeled filing_timestamp; it falls back to statutory_lag_estimate.
|
||||
let sole_legacy = vec![obs(
|
||||
"ACME",
|
||||
q1_24,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
None,
|
||||
fields_rev(120.0),
|
||||
)];
|
||||
let built_sole =
|
||||
build_fundamentals_rows_with_legacy(Vec::new(), sole_legacy, filings, &venues);
|
||||
assert_reconciliation(&built_sole);
|
||||
assert_eq!(built_sole.stats.rows_out, 1);
|
||||
assert_eq!(built_sole.stats.rows_linked_to_filing, 0);
|
||||
assert_eq!(built_sole.stats.rows_statutory_lag_estimate, 1);
|
||||
assert_eq!(
|
||||
built_sole.rows[0].known_at_source,
|
||||
KNOWN_AT_SOURCE_STATUTORY_LAG
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_merge_restatement_of_q1_after_q2_updates_q1_and_ttm_without_overwriting_q2() {
|
||||
let venues = venues_map(&[("ACME", StatutoryLagVenue::UsTsx)]);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::bars_1m::{Bars1mStats, EodIntradayBar};
|
||||
use crate::bars_1m::EodIntradayBar;
|
||||
use crate::bson_eod_intraday::{decode_eod_intraday_buffer, BsonEodIntradayDecodeStats};
|
||||
use crate::bson_qm_actions::BsonQmActionDecodeStats;
|
||||
use crate::bson_stream::{BsonStreamError, BsonStreamOptions, RawBsonChunkReader};
|
||||
|
|
@ -425,36 +425,6 @@ fn load_reference_inputs<RS: io::Read>(
|
|||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn add_bars_1m_stats(total: &mut Bars1mStats, chunk: &Bars1mStats) {
|
||||
total.bars_in += chunk.bars_in;
|
||||
total.rows_out += chunk.rows_out;
|
||||
total.keys_out += chunk.keys_out;
|
||||
total.pre_rows_out += chunk.pre_rows_out;
|
||||
total.rth_rows_out += chunk.rth_rows_out;
|
||||
total.post_rows_out += chunk.post_rows_out;
|
||||
total.dropped_invalid_ohlc += chunk.dropped_invalid_ohlc;
|
||||
total.dropped_inconsistent_ohlc += chunk.dropped_inconsistent_ohlc;
|
||||
total.dropped_invalid_volume += chunk.dropped_invalid_volume;
|
||||
total.dropped_ts_out_of_range += chunk.dropped_ts_out_of_range;
|
||||
total.duplicate_collapsed += chunk.duplicate_collapsed;
|
||||
total.duplicate_conflict_dropped += chunk.duplicate_conflict_dropped;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn add_curate_bars_1m_stats(total: &mut CurateBars1mStats, chunk: &CurateBars1mStats) {
|
||||
add_bars_1m_stats(&mut total.builder, &chunk.builder);
|
||||
total.rows_in += chunk.rows_in;
|
||||
total.rows_out += chunk.rows_out;
|
||||
total.listings_out += chunk.listings_out;
|
||||
total.pre_rows_out += chunk.pre_rows_out;
|
||||
total.rth_rows_out += chunk.rth_rows_out;
|
||||
total.post_rows_out += chunk.post_rows_out;
|
||||
total.dropped_unmapped += chunk.dropped_unmapped;
|
||||
total.listing_collision_collapsed += chunk.listing_collision_collapsed;
|
||||
total.listing_collision_dropped += chunk.listing_collision_dropped;
|
||||
}
|
||||
|
||||
fn stream_intraday_chunks_to_writer<RI, W>(
|
||||
args: &CurateBars1mArgs,
|
||||
reference: LoadedReferenceInputs,
|
||||
|
|
@ -475,13 +445,12 @@ where
|
|||
)?;
|
||||
|
||||
let mut intraday_decode = BsonEodIntradayDecodeStats::default();
|
||||
let mut curate_stats = CurateBars1mStats::default();
|
||||
let mut chunks: usize = 0;
|
||||
let mut max_rows_per_chunk: usize = 0;
|
||||
let mut rows_written: usize = 0;
|
||||
|
||||
// Reusable per-chunk buffers; cleared before each chunk so peak RAM stays bounded by chunk size.
|
||||
let mut chunk_bars: Vec<EodIntradayBar<Arc<str>>> = Vec::new();
|
||||
// Accumulate decoded bars across BSON chunks so global `(listing_id, ts)` ordering and
|
||||
// duplicate/collision resolution are invariant to input document order and chunk boundaries.
|
||||
let mut all_bars: Vec<EodIntradayBar<Arc<str>>> = Vec::new();
|
||||
let mut unknown_keys: HashMap<String, Arc<str>> = HashMap::new();
|
||||
|
||||
while let Some(chunk) =
|
||||
|
|
@ -493,8 +462,7 @@ where
|
|||
source,
|
||||
})?
|
||||
{
|
||||
chunk_bars.clear();
|
||||
unknown_keys.clear();
|
||||
let chunk_start = all_bars.len();
|
||||
|
||||
let chunk_decode = decode_eod_intraday_buffer(
|
||||
chunk.bytes,
|
||||
|
|
@ -508,32 +476,29 @@ where
|
|||
unknown_keys.insert(raw.eod_search_code.to_owned(), Arc::clone(&arc));
|
||||
arc
|
||||
};
|
||||
chunk_bars.push(raw.into_eod_intraday_bar(|_, _| key));
|
||||
all_bars.push(raw.into_eod_intraday_bar(|_, _| key));
|
||||
},
|
||||
|_local_offset, _err| {},
|
||||
);
|
||||
intraday_decode += chunk_decode;
|
||||
|
||||
chunks += 1;
|
||||
let chunk_len = chunk_bars.len();
|
||||
let chunk_len = all_bars.len() - chunk_start;
|
||||
if chunk_len > max_rows_per_chunk {
|
||||
max_rows_per_chunk = chunk_len;
|
||||
}
|
||||
|
||||
let write_report = curate_and_write_bars_1m_by_listing(
|
||||
chunk_bars.drain(..),
|
||||
&reference.splits,
|
||||
&reference.mapping,
|
||||
&args.mapping_source,
|
||||
&mut writer,
|
||||
args.known_at_micros,
|
||||
)
|
||||
.map_err(RunCurateBars1mError::CurateWrite)?;
|
||||
|
||||
add_curate_bars_1m_stats(&mut curate_stats, &write_report.curate_stats);
|
||||
rows_written += write_report.rows_written;
|
||||
}
|
||||
|
||||
let write_report = curate_and_write_bars_1m_by_listing(
|
||||
all_bars,
|
||||
&reference.splits,
|
||||
&reference.mapping,
|
||||
&args.mapping_source,
|
||||
&mut writer,
|
||||
args.known_at_micros,
|
||||
)
|
||||
.map_err(RunCurateBars1mError::CurateWrite)?;
|
||||
|
||||
let intraday_docs_framed = reader.docs_framed();
|
||||
let intraday_bytes_read = reader.bytes_read();
|
||||
let ilp_stats = writer.finish().map_err(RunCurateBars1mError::Ilp)?;
|
||||
|
|
@ -548,8 +513,8 @@ where
|
|||
split_rekey: reference.split_rekey,
|
||||
chunks,
|
||||
max_rows_per_chunk,
|
||||
curate_stats,
|
||||
rows_written,
|
||||
curate_stats: write_report.curate_stats,
|
||||
rows_written: write_report.rows_written,
|
||||
ilp_stats,
|
||||
shard_count: args.shard_count,
|
||||
elapsed_secs: start.elapsed().as_secs_f64(),
|
||||
|
|
|
|||
|
|
@ -955,22 +955,21 @@ fn cross_chunk_duplicate_is_emitted_twice_and_reported() {
|
|||
assert_report_conservation(&report);
|
||||
assert_eq!(report.chunks, 2);
|
||||
assert_eq!(report.max_rows_per_chunk, 1);
|
||||
assert_eq!(report.curate_stats.builder.duplicate_collapsed, 0);
|
||||
assert_eq!(report.curate_stats.builder.duplicate_collapsed, 1);
|
||||
assert_eq!(report.curate_stats.listing_collision_collapsed, 0);
|
||||
assert_eq!(report.curate_stats.listings_out, 2);
|
||||
assert_eq!(report.curate_stats.builder.keys_out, 2);
|
||||
assert_eq!(report.rows_written, 2);
|
||||
assert_eq!(report.curate_stats.listings_out, 1);
|
||||
assert_eq!(report.curate_stats.builder.keys_out, 1);
|
||||
assert_eq!(report.rows_written, 1);
|
||||
|
||||
let rows = decode_ilp_bars_1m(&sink);
|
||||
assert_eq!(rows.len(), 2);
|
||||
assert_eq!(rows[0], rows[1]);
|
||||
assert_eq!(rows.len(), 1);
|
||||
assert_eq!(rows[0].listing_id, 505);
|
||||
assert_eq!(rows[0].ts, ts * 1_000_000);
|
||||
|
||||
let formatted = format_curate_bars_1m_report(&report);
|
||||
assert!(formatted.contains("cross_chunk_dedup=questdb_dedup_upsert_keys(ts,listing_id)"));
|
||||
assert!(formatted.contains("listings_out_per_chunk_sum=2"));
|
||||
assert!(formatted.contains("keys_out_per_chunk_sum=2"));
|
||||
assert!(formatted.contains("dup_collapsed=1"));
|
||||
assert!(formatted.contains("listings_out_per_chunk_sum=1"));
|
||||
assert!(formatted.contains("keys_out_per_chunk_sum=1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -521,19 +521,11 @@ pub fn load_macro_series_map_tsv<R: io::Read>(
|
|||
Ok(map)
|
||||
}
|
||||
|
||||
/// Runs file-mode `curate-macro` from arbitrary [`io::Read`] streams for `teData` BSON and
|
||||
/// the series-map TSV, publishing `<out_dir>/macro/part.parquet` via [`curate_and_write_macro`].
|
||||
///
|
||||
/// The series map is validated in full before `te_data` is decoded or `out_dir` is touched. Any
|
||||
/// map, I/O, structural BSON, or curation error returns before publishing and leaves `out_dir` and
|
||||
/// any pre-existing `<out_dir>/macro/part.parquet` untouched.
|
||||
pub fn run_curate_macro_with_readers<RT: io::Read, RM: io::Read>(
|
||||
fn run_curate_macro_with_map<RT: io::Read>(
|
||||
mut te_data: RT,
|
||||
series_map: RM,
|
||||
map: &MacroSeriesMap,
|
||||
out_dir: &Path,
|
||||
) -> Result<CurateMacroRunReport, RunCurateMacroError> {
|
||||
let map = load_macro_series_map_tsv(series_map)?;
|
||||
|
||||
let mut te_data_buf = Vec::new();
|
||||
te_data
|
||||
.read_to_end(&mut te_data_buf)
|
||||
|
|
@ -577,6 +569,44 @@ pub fn run_curate_macro_with_readers<RT: io::Read, RM: io::Read>(
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn load_macro_series_map_file(
|
||||
series_map_path: &Path,
|
||||
) -> Result<MacroSeriesMap, RunCurateMacroError> {
|
||||
let series_map_file =
|
||||
File::open(series_map_path).map_err(|source| RunCurateMacroError::OpenInput {
|
||||
role: ROLE_SERIES_MAP,
|
||||
path: series_map_path.to_path_buf(),
|
||||
source,
|
||||
})?;
|
||||
load_macro_series_map_tsv(series_map_file)
|
||||
.map_err(|err| err.with_input_paths(Path::new(""), series_map_path))
|
||||
}
|
||||
|
||||
pub(crate) fn run_curate_macro_with_parsed_map<RT: io::Read>(
|
||||
te_data_path: &Path,
|
||||
te_data: RT,
|
||||
map: &MacroSeriesMap,
|
||||
out_dir: &Path,
|
||||
) -> Result<CurateMacroRunReport, RunCurateMacroError> {
|
||||
run_curate_macro_with_map(te_data, map, out_dir)
|
||||
.map_err(|err| err.with_input_paths(te_data_path, Path::new("")))
|
||||
}
|
||||
|
||||
/// Runs file-mode `curate-macro` from arbitrary [`io::Read`] streams for `teData` BSON and
|
||||
/// the series-map TSV, publishing `<out_dir>/macro/part.parquet` via [`curate_and_write_macro`].
|
||||
///
|
||||
/// The series map is validated in full before `te_data` is decoded or `out_dir` is touched. Any
|
||||
/// map, I/O, structural BSON, or curation error returns before publishing and leaves `out_dir` and
|
||||
/// any pre-existing `<out_dir>/macro/part.parquet` untouched.
|
||||
pub fn run_curate_macro_with_readers<RT: io::Read, RM: io::Read>(
|
||||
te_data: RT,
|
||||
series_map: RM,
|
||||
out_dir: &Path,
|
||||
) -> Result<CurateMacroRunReport, RunCurateMacroError> {
|
||||
let map = load_macro_series_map_tsv(series_map)?;
|
||||
run_curate_macro_with_map(te_data, &map, out_dir)
|
||||
}
|
||||
|
||||
/// Runs `curate-macro` from an arbitrary raw-BSON `teData` [`io::Read`] stream (such as a
|
||||
/// read-only MongoDB cursor) and a `series_map_path` TSV on disk, validating `series_map_path`
|
||||
/// before reading `te_data` and attaching `te_data_path` / `series_map_path` to any error.
|
||||
|
|
@ -586,14 +616,8 @@ pub fn run_curate_macro_from_reader<RT: io::Read>(
|
|||
series_map_path: &Path,
|
||||
out_dir: &Path,
|
||||
) -> Result<CurateMacroRunReport, RunCurateMacroError> {
|
||||
let series_map_file =
|
||||
File::open(series_map_path).map_err(|source| RunCurateMacroError::OpenInput {
|
||||
role: ROLE_SERIES_MAP,
|
||||
path: series_map_path.to_path_buf(),
|
||||
source,
|
||||
})?;
|
||||
run_curate_macro_with_readers(te_data, series_map_file, out_dir)
|
||||
.map_err(|err| err.with_input_paths(te_data_path, series_map_path))
|
||||
let map = load_macro_series_map_file(series_map_path)?;
|
||||
run_curate_macro_with_parsed_map(te_data_path, te_data, &map, out_dir)
|
||||
}
|
||||
|
||||
/// Runs file-mode `curate-macro` by opening `args.series_map` and `args.te_data` and delegating
|
||||
|
|
|
|||
|
|
@ -52,11 +52,13 @@
|
|||
//! removes this run's staging files, and leaves pre-existing files untouched. Per-document
|
||||
//! semantic decode errors stay counted-and-skipped in [`BsonQmIntradayDecodeStats`].
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::bars_1m::EodIntradayBar;
|
||||
|
|
@ -70,7 +72,7 @@ use crate::parquet_publish::{next_run_id, StagingFileGuard};
|
|||
use crate::provider_mapping::ProviderMappingTable;
|
||||
use crate::run_curate_bars::{load_provider_mapping_tsv, RunCurateBarsError};
|
||||
use crate::run_curate_bars_1m::{
|
||||
add_curate_bars_1m_stats, create_exclusive_shard_tmp_file_for_table, preflight_shard_out_dir,
|
||||
create_exclusive_shard_tmp_file_for_table, preflight_shard_out_dir,
|
||||
publish_staged_shards_for_table, ShardPublishError, SyncedBufFile,
|
||||
};
|
||||
use crate::run_curate_fx_1m::cleanup_armed_staged_shards;
|
||||
|
|
@ -306,10 +308,13 @@ where
|
|||
)?;
|
||||
|
||||
let mut intraday_decode = BsonQmIntradayDecodeStats::default();
|
||||
let mut curate_stats = CurateBars1mStats::default();
|
||||
let mut chunks: usize = 0;
|
||||
let mut max_rows_per_chunk: usize = 0;
|
||||
let mut rows_written: usize = 0;
|
||||
|
||||
// Accumulate decoded bars across BSON chunks so global `(listing_id, ts)` ordering and
|
||||
// duplicate/collision resolution are invariant to input document order and chunk boundaries.
|
||||
let mut all_bars: Vec<EodIntradayBar<Arc<str>>> = Vec::new();
|
||||
let mut interned_keys: HashMap<String, Arc<str>> = HashMap::new();
|
||||
|
||||
while let Some(chunk) =
|
||||
reader
|
||||
|
|
@ -320,35 +325,40 @@ where
|
|||
source,
|
||||
})?
|
||||
{
|
||||
let mut chunk_bars: Vec<EodIntradayBar<&str>> = Vec::new();
|
||||
let chunk_start = all_bars.len();
|
||||
let chunk_decode = decode_qm_intraday_buffer(
|
||||
chunk.bytes,
|
||||
|raw| {
|
||||
chunk_bars.push(raw.into_eod_intraday_bar(|key, _| key));
|
||||
all_bars.push(raw.into_eod_intraday_bar(|key, _| {
|
||||
if let Some(existing) = interned_keys.get(key) {
|
||||
Arc::clone(existing)
|
||||
} else {
|
||||
let arc: Arc<str> = Arc::from(key);
|
||||
interned_keys.insert(key.to_owned(), Arc::clone(&arc));
|
||||
arc
|
||||
}
|
||||
}));
|
||||
},
|
||||
|_local_offset, _err| {},
|
||||
);
|
||||
intraday_decode.merge(&chunk_decode);
|
||||
|
||||
chunks += 1;
|
||||
let chunk_len = chunk_bars.len();
|
||||
let chunk_len = all_bars.len() - chunk_start;
|
||||
if chunk_len > max_rows_per_chunk {
|
||||
max_rows_per_chunk = chunk_len;
|
||||
}
|
||||
|
||||
let write_report = curate_and_write_qm_bars_1m(
|
||||
chunk_bars,
|
||||
mapping,
|
||||
&args.mapping_source,
|
||||
&mut writer,
|
||||
args.known_at_micros,
|
||||
)
|
||||
.map_err(RunCurateQmBars1mError::CurateWrite)?;
|
||||
|
||||
add_curate_bars_1m_stats(&mut curate_stats, &write_report.curate_stats);
|
||||
rows_written += write_report.rows_written;
|
||||
}
|
||||
|
||||
let write_report = curate_and_write_qm_bars_1m(
|
||||
all_bars,
|
||||
mapping,
|
||||
&args.mapping_source,
|
||||
&mut writer,
|
||||
args.known_at_micros,
|
||||
)
|
||||
.map_err(RunCurateQmBars1mError::CurateWrite)?;
|
||||
|
||||
let intraday_docs_framed = reader.docs_framed();
|
||||
let intraday_bytes_read = reader.bytes_read();
|
||||
let ilp_stats = writer.finish().map_err(RunCurateQmBars1mError::Ilp)?;
|
||||
|
|
@ -359,8 +369,8 @@ where
|
|||
intraday_decode,
|
||||
chunks,
|
||||
max_rows_per_chunk,
|
||||
curate_stats,
|
||||
rows_written,
|
||||
curate_stats: write_report.curate_stats,
|
||||
rows_written: write_report.rows_written,
|
||||
ilp_stats,
|
||||
shard_count: args.shard_count,
|
||||
elapsed_secs: start.elapsed().as_secs_f64(),
|
||||
|
|
|
|||
|
|
@ -800,8 +800,8 @@ fn conservation_counts_unmapped_semantic_decode_errors_collisions_and_cross_chun
|
|||
assert_eq!(report.curate_stats.post_rows_out, 1);
|
||||
assert_eq!(report.rows_written, 3);
|
||||
|
||||
// Cross-chunk duplicate semantics: the same (listing_id, ts) in two separate chunks emits both
|
||||
// rows (relying on QuestDB DEDUP UPSERT KEYS(ts, listing_id)) and sums listings_out/keys_out.
|
||||
// Cross-chunk duplicate semantics: the same (listing_id, ts) in two separate chunks collapses
|
||||
// globally before ILP publication so output is invariant to chunk boundaries.
|
||||
let dup_doc = make_qm_intraday_doc("ALIAS_A", ts_rth_same, 11.0, 11.5, 10.8, 11.2, 200.0);
|
||||
let doc_len = dup_doc.as_bytes().len();
|
||||
let cross_chunk_bytes = concat_docs(&[dup_doc.clone(), dup_doc]);
|
||||
|
|
@ -827,12 +827,13 @@ fn conservation_counts_unmapped_semantic_decode_errors_collisions_and_cross_chun
|
|||
.expect("cross-chunk duplicate run should succeed");
|
||||
assert_report_conservation(&cross_report);
|
||||
assert_eq!(cross_report.chunks, 2);
|
||||
assert_eq!(cross_report.rows_written, 2);
|
||||
assert_eq!(cross_report.curate_stats.listings_out, 2);
|
||||
assert_eq!(cross_report.curate_stats.builder.keys_out, 2);
|
||||
assert_eq!(cross_report.rows_written, 1);
|
||||
assert_eq!(cross_report.curate_stats.builder.duplicate_collapsed, 1);
|
||||
assert_eq!(cross_report.curate_stats.listings_out, 1);
|
||||
assert_eq!(cross_report.curate_stats.builder.keys_out, 1);
|
||||
let emitted = decode_ilp_bars_1m(&sinks[0].bytes.lock().unwrap());
|
||||
assert_eq!(emitted.len(), 2);
|
||||
assert_eq!(emitted[0], emitted[1]);
|
||||
assert_eq!(emitted.len(), 1);
|
||||
assert_eq!(emitted[0].listing_id, 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ use crate::run_curate_fx_1m::{
|
|||
run_curate_fx_1m_from_reader_to_dir, CurateFx1mArgs, CurateFx1mRunReport, RunCurateFx1mError,
|
||||
};
|
||||
use crate::run_curate_macro::{
|
||||
run_curate_macro_from_reader, CurateMacroRunReport, RunCurateMacroError,
|
||||
load_macro_series_map_file, run_curate_macro_from_reader, run_curate_macro_with_parsed_map,
|
||||
CurateMacroRunReport, RunCurateMacroError,
|
||||
};
|
||||
use crate::run_curate_posts::{
|
||||
run_curate_posts_with_reader, CuratePostsRunReport, RunCuratePostsError,
|
||||
|
|
@ -863,10 +864,14 @@ pub fn run_curate_macro_mongo(
|
|||
&args.mongo,
|
||||
&[(SourceCollection::TeData, te_spec.clone())],
|
||||
|client| {
|
||||
let map = load_macro_series_map_file(&args.series_map)
|
||||
.map_err(RunMongoCurateError::Macro)?;
|
||||
let te_reader = client
|
||||
.open_raw_cursor(SourceCollection::TeData, &te_spec)
|
||||
.map_err(RunMongoCurateError::Mongo)?;
|
||||
run_curate_macro_mongo_with_reader(args, te_reader)
|
||||
let te_path = mongo_virtual_path(SourceCollection::TeData);
|
||||
run_curate_macro_with_parsed_map(&te_path, te_reader, &map, &args.out_dir)
|
||||
.map_err(RunMongoCurateError::Macro)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1428,7 +1428,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
ts_1331,
|
||||
make_eod_1m_doc("AAPL.US", ts_1331, 196.0, 197.0, 195.0, 196.5, 900.0),
|
||||
),
|
||||
// In-window CAD.FOREX rows.
|
||||
// In-window CAD.FOREX rows (including a cross-chunk duplicate at ts_1330).
|
||||
(
|
||||
"CAD.FOREX",
|
||||
ts_1330,
|
||||
|
|
@ -1439,6 +1439,11 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
ts_1331,
|
||||
make_eod_1m_doc("CAD.FOREX", ts_1331, 1.371, 1.372, 1.370, 1.3715, 0.0),
|
||||
),
|
||||
(
|
||||
"CAD.FOREX",
|
||||
ts_1330,
|
||||
make_eod_1m_doc("CAD.FOREX", ts_1330, 1.370, 1.371, 1.369, 1.3705, 0.0),
|
||||
),
|
||||
];
|
||||
|
||||
let qm_corpus: Vec<(&str, i64, Vec<u8>)> = vec![
|
||||
|
|
@ -1472,6 +1477,12 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
ts_1331,
|
||||
make_qm_1m_doc("AAPL:US", ts_1331, 196.0, 197.0, 195.0, 196.5, 900.0),
|
||||
),
|
||||
// Cross-chunk duplicate for NVDA:US at ts_1330.
|
||||
(
|
||||
"NVDA:US",
|
||||
ts_1330,
|
||||
make_qm_1m_doc("NVDA:US", ts_1330, 1200.0, 1210.0, 1190.0, 1205.0, 100.0),
|
||||
),
|
||||
];
|
||||
|
||||
let date_opts = MongoCliOptions {
|
||||
|
|
@ -1529,7 +1540,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
let b1m_filtered_path = tmp.path().join("eodIntraday1M_filtered.bson");
|
||||
fs::write(&b1m_filtered_path, concat_docs(&b1m_filtered_pinned)).unwrap();
|
||||
let b1m_file_out = tmp.path().join("b1m_file_pinned");
|
||||
run_curate_bars_1m(&CurateBars1mArgs {
|
||||
let b1m_file_rep = run_curate_bars_1m(&CurateBars1mArgs {
|
||||
intraday_path: b1m_filtered_path,
|
||||
splits_path,
|
||||
provider_mapping_path: map_path.clone(),
|
||||
|
|
@ -1541,7 +1552,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
ilp_options: IlpWriterOptions::default(),
|
||||
})
|
||||
.expect("file bars_1m pinned");
|
||||
run_curate_bars_1m_mongo_with_readers(
|
||||
let b1m_pinned_rep = run_curate_bars_1m_mongo_with_readers(
|
||||
&b1m_mongo_args,
|
||||
CappedRead::new(
|
||||
RawBsonCursorReader::new(VecRawDocumentSource::new(b1m_filtered_pinned.clone())),
|
||||
|
|
@ -1550,12 +1561,17 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
RawBsonCursorReader::new(VecRawDocumentSource::new(split_docs.clone())),
|
||||
)
|
||||
.expect("mongo bars_1m pinned");
|
||||
assert_eq!(b1m_pinned_rep.rows_written, 4);
|
||||
assert_eq!(b1m_pinned_rep.curate_stats, b1m_file_rep.curate_stats);
|
||||
assert_eq!(b1m_pinned_rep.ilp_stats, b1m_file_rep.ilp_stats);
|
||||
assert_eq!(
|
||||
snapshot_files(&b1m_mongo_args.out_dir),
|
||||
snapshot_files(&b1m_file_out)
|
||||
);
|
||||
|
||||
// Reordered `$in` key-grouped cursor order (all AAPL docs before NVDA docs, reversed ts).
|
||||
// Reordered `$in` key-grouped cursor order (all AAPL docs before NVDA docs, reversed ts)
|
||||
// with duplicates straddling BSON chunk boundaries must produce byte-identical shards and
|
||||
// identical row counts.
|
||||
let mut b1m_reordered: Vec<(&str, i64, Vec<u8>)> = eod_corpus
|
||||
.iter()
|
||||
.filter(|(k, ts, _)| eod_keys.contains(*k) && *ts >= b1m_gte && *ts < b1m_lt)
|
||||
|
|
@ -1565,7 +1581,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
let b1m_reordered_docs: Vec<Vec<u8>> = b1m_reordered.into_iter().map(|(_, _, b)| b).collect();
|
||||
let mut b1m_reordered_args = b1m_mongo_args;
|
||||
b1m_reordered_args.out_dir = tmp.path().join("b1m_mongo_reordered");
|
||||
run_curate_bars_1m_mongo_with_readers(
|
||||
let b1m_reordered_rep = run_curate_bars_1m_mongo_with_readers(
|
||||
&b1m_reordered_args,
|
||||
CappedRead::new(
|
||||
RawBsonCursorReader::new(VecRawDocumentSource::new(b1m_reordered_docs)),
|
||||
|
|
@ -1575,6 +1591,16 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
)
|
||||
.expect("mongo bars_1m reordered");
|
||||
|
||||
assert!(b1m_reordered_rep.chunks > 1);
|
||||
assert_eq!(b1m_reordered_rep.rows_written, b1m_file_rep.rows_written);
|
||||
assert_eq!(b1m_reordered_rep.rows_written, 4);
|
||||
assert_eq!(b1m_reordered_rep.curate_stats, b1m_file_rep.curate_stats);
|
||||
assert_eq!(b1m_reordered_rep.ilp_stats, b1m_file_rep.ilp_stats);
|
||||
assert_eq!(
|
||||
snapshot_files(&b1m_reordered_args.out_dir),
|
||||
snapshot_files(&b1m_file_out)
|
||||
);
|
||||
|
||||
let b1m_file_rows = collect_ilp_bars_1m_rows(&b1m_file_out, "bars_1m.shard-");
|
||||
let b1m_reordered_rows = collect_ilp_bars_1m_rows(&b1m_reordered_args.out_dir, "bars_1m.shard-");
|
||||
assert_eq!(b1m_reordered_rows, b1m_file_rows);
|
||||
|
|
@ -1630,7 +1656,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
})
|
||||
.map(|(_, _, b)| b.clone())
|
||||
.collect();
|
||||
assert_eq!(qm_filtered_pinned.len(), 4);
|
||||
assert_eq!(qm_filtered_pinned.len(), 5);
|
||||
assert!(
|
||||
concat_docs(&qm_filtered_pinned).len() > small_chunks.chunk_capacity_bytes,
|
||||
"filtered qm_bars_1m fixture must cross a BSON chunk boundary"
|
||||
|
|
@ -1639,7 +1665,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
let qm_filtered_path = tmp.path().join("qmIntraday_filtered.bson");
|
||||
fs::write(&qm_filtered_path, concat_docs(&qm_filtered_pinned)).unwrap();
|
||||
let qm_file_out = tmp.path().join("qm_file_pinned");
|
||||
run_curate_qm_bars_1m(&CurateQmBars1mArgs {
|
||||
let qm_file_rep = run_curate_qm_bars_1m(&CurateQmBars1mArgs {
|
||||
intraday_path: qm_filtered_path,
|
||||
provider_mapping_path: map_path,
|
||||
out_dir: qm_file_out.clone(),
|
||||
|
|
@ -1650,7 +1676,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
ilp_options: IlpWriterOptions::default(),
|
||||
})
|
||||
.expect("file qm_bars_1m pinned");
|
||||
run_curate_qm_bars_1m_mongo_with_reader(
|
||||
let qm_pinned_rep = run_curate_qm_bars_1m_mongo_with_reader(
|
||||
&qm_mongo_args,
|
||||
CappedRead::new(
|
||||
RawBsonCursorReader::new(VecRawDocumentSource::new(qm_filtered_pinned)),
|
||||
|
|
@ -1658,6 +1684,9 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
),
|
||||
)
|
||||
.expect("mongo qm_bars_1m pinned");
|
||||
assert_eq!(qm_pinned_rep.rows_written, 4);
|
||||
assert_eq!(qm_pinned_rep.curate_stats, qm_file_rep.curate_stats);
|
||||
assert_eq!(qm_pinned_rep.ilp_stats, qm_file_rep.ilp_stats);
|
||||
assert_eq!(
|
||||
snapshot_files(&qm_mongo_args.out_dir),
|
||||
snapshot_files(&qm_file_out)
|
||||
|
|
@ -1673,7 +1702,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
qm_reordered.sort_by(|a, b| a.0.cmp(b.0).then_with(|| b.1.cmp(&a.1)));
|
||||
let mut qm_reordered_args = qm_mongo_args;
|
||||
qm_reordered_args.out_dir = tmp.path().join("qm_mongo_reordered");
|
||||
run_curate_qm_bars_1m_mongo_with_reader(
|
||||
let qm_reordered_rep = run_curate_qm_bars_1m_mongo_with_reader(
|
||||
&qm_reordered_args,
|
||||
CappedRead::new(
|
||||
RawBsonCursorReader::new(VecRawDocumentSource::new(
|
||||
|
|
@ -1683,6 +1712,15 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
),
|
||||
)
|
||||
.expect("mongo qm_bars_1m reordered");
|
||||
assert!(qm_reordered_rep.chunks > 1);
|
||||
assert_eq!(qm_reordered_rep.rows_written, qm_file_rep.rows_written);
|
||||
assert_eq!(qm_reordered_rep.rows_written, 4);
|
||||
assert_eq!(qm_reordered_rep.curate_stats, qm_file_rep.curate_stats);
|
||||
assert_eq!(qm_reordered_rep.ilp_stats, qm_file_rep.ilp_stats);
|
||||
assert_eq!(
|
||||
snapshot_files(&qm_reordered_args.out_dir),
|
||||
snapshot_files(&qm_file_out)
|
||||
);
|
||||
let qm_file_rows = collect_ilp_bars_1m_rows(&qm_file_out, "bars_1m_qm.shard-");
|
||||
let qm_reordered_rows =
|
||||
collect_ilp_bars_1m_rows(&qm_reordered_args.out_dir, "bars_1m_qm.shard-");
|
||||
|
|
@ -1722,7 +1760,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
.filter(|(k, ts, _)| *k == fx_key && *ts >= fx_gte && *ts < fx_lt)
|
||||
.map(|(_, _, b)| b.clone())
|
||||
.collect();
|
||||
assert_eq!(fx_filtered_pinned.len(), 2);
|
||||
assert_eq!(fx_filtered_pinned.len(), 3);
|
||||
assert!(
|
||||
concat_docs(&fx_filtered_pinned).len() > fx_mongo_args.stream_options.chunk_capacity_bytes,
|
||||
"filtered fx_1m fixture must cross a BSON chunk boundary"
|
||||
|
|
@ -1731,7 +1769,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
let fx_filtered_path = tmp.path().join("fx_filtered.bson");
|
||||
fs::write(&fx_filtered_path, concat_docs(&fx_filtered_pinned)).unwrap();
|
||||
let fx_file_out = tmp.path().join("fx_file_pinned");
|
||||
run_curate_fx_1m(&CurateFx1mArgs {
|
||||
let fx_file_rep = run_curate_fx_1m(&CurateFx1mArgs {
|
||||
intraday_path: fx_filtered_path,
|
||||
out_dir: fx_file_out.clone(),
|
||||
shard_count: 2,
|
||||
|
|
@ -1739,7 +1777,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
ilp_options: IlpWriterOptions::default(),
|
||||
})
|
||||
.expect("file fx_1m pinned");
|
||||
run_curate_fx_1m_mongo_with_reader(
|
||||
let fx_pinned_rep = run_curate_fx_1m_mongo_with_reader(
|
||||
&fx_mongo_args,
|
||||
CappedRead::new(
|
||||
RawBsonCursorReader::new(VecRawDocumentSource::new(fx_filtered_pinned.clone())),
|
||||
|
|
@ -1747,6 +1785,9 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
),
|
||||
)
|
||||
.expect("mongo fx_1m pinned");
|
||||
assert_eq!(fx_pinned_rep.rows_written, 2);
|
||||
assert_eq!(fx_pinned_rep.curate_stats, fx_file_rep.curate_stats);
|
||||
assert_eq!(fx_pinned_rep.ilp_stats, fx_file_rep.ilp_stats);
|
||||
assert_eq!(
|
||||
snapshot_files(&fx_mongo_args.out_dir),
|
||||
snapshot_files(&fx_file_out)
|
||||
|
|
@ -1756,7 +1797,7 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
fx_reversed.reverse();
|
||||
let mut fx_reordered_args = fx_mongo_args;
|
||||
fx_reordered_args.out_dir = tmp.path().join("fx_mongo_reordered");
|
||||
run_curate_fx_1m_mongo_with_reader(
|
||||
let fx_reordered_rep = run_curate_fx_1m_mongo_with_reader(
|
||||
&fx_reordered_args,
|
||||
CappedRead::new(
|
||||
RawBsonCursorReader::new(VecRawDocumentSource::new(fx_reversed)),
|
||||
|
|
@ -1764,6 +1805,14 @@ fn parity_curate_1m_ilp_filtered_multi_key_cross_chunk_matches_economic_rows_and
|
|||
),
|
||||
)
|
||||
.expect("mongo fx_1m reordered");
|
||||
assert_eq!(fx_reordered_rep.rows_written, fx_file_rep.rows_written);
|
||||
assert_eq!(fx_reordered_rep.rows_written, 2);
|
||||
assert_eq!(fx_reordered_rep.curate_stats, fx_file_rep.curate_stats);
|
||||
assert_eq!(fx_reordered_rep.ilp_stats, fx_file_rep.ilp_stats);
|
||||
assert_eq!(
|
||||
snapshot_files(&fx_reordered_args.out_dir),
|
||||
snapshot_files(&fx_file_out)
|
||||
);
|
||||
let fx_file_rows = collect_ilp_fx_1m_rows(&fx_file_out, "fx_1m.shard-");
|
||||
let fx_reordered_rows = collect_ilp_fx_1m_rows(&fx_reordered_args.out_dir, "fx_1m.shard-");
|
||||
assert_eq!(fx_reordered_rows, fx_file_rows);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue