Problems / Backfill Missing Snapshots / Editorial
calendar × DISTINCT product_id
last_value(stock IGNORE NULLS)
PARTITION BY product_id ORDER BY day ROWS UNBOUNDED PRECEDING → CURRENT ROW
F.expr
F.last(..., ignorenulls=True)
Densification is a two-tool job: a spine join to *create* the missing observations, then a forward-fill to *value* them — and the choice of fill encodes real-world semantics. Fill counts with zero (nothing happened), fill *state* with the last observation (the shelf didn't empty because nobody counted it). Choosing wrong is invisible in the query and very visible in the inventory report. The composition also explains why snapshot tables in production warehouses are often stored sparse and densified on read: the spine is cheap to regenerate, the state semantics live in one window expression.
Solve Backfill Missing Snapshots yourself →