feat(common): opt-in order-field fold in datawarehouse combine (PMT-4302) - #251
Draft
jgrantr wants to merge 1 commit into
Draft
feat(common): opt-in order-field fold in datawarehouse combine (PMT-4302)#251jgrantr wants to merge 1 commit into
jgrantr wants to merge 1 commit into
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
For current-state (merge-type) tables fed from sharded producers, arrival order is not chronological, so the fold's last-arrival-wins can resolve a natural key to a stale row. A field flagged `combineOrder` in the table's dw_fields schema now makes the fold keep the row with the highest value of that field (e.g. source_eid) per key; the arrival counter only breaks ties. - Opt-in and default-off: tables without the flag keep the existing arrival-order fold byte-for-byte (locked by test). - A row with no order value sorts before every row that has one, so backfill rows (no source_eid) always lose the fold against live rows. - Fixes a latent bug where combine()'s caller opts were discarded (Object.assign called with a single argument). Based on feature/aws-sdk-v3-again (the v3 bar is the current line, per CUP Shared Services). Composes with the RPL-5795 combineRecords refactor arriving via the next development sync: this change orders the rows the collapse sees; it does not touch the collapse itself. PMT-4302 / Zero-Inventory design v2 'Sharpened Option E' Change 3 (fold half); the group-scoped merge guard lands separately in the consumers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DhcouH67CgpNGpBZ29ujbk
jgrantr
force-pushed
the
feature/combine-order-field
branch
from
August 27, 2026 16:38
c6358a3 to
49797ed
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an opt-in, default-off ordering mode to the datawarehouse
combine.jsin-batch fold, for current-state (merge-type) tables fed from sharded producers.A field flagged
"combineOrder": truein the table'sdw_fieldsschema makes the fold keep the row with the highest value of that field per natural key (e.g.source_eid), instead of the last row by arrival. The arrival counter remains as tie-breaker. Tables without the flag keep the existing arrival-order fold byte-for-byte — locked by a regression test.Why
item-retailer-events-to-dimrunsbotCount: 8sharded bymd5(eid), so two updates to one item are processed by different instances with independent checkpoints and can reach the queue out of source order. For append-only loads (f_item_change_event) that is harmless. For a current-state table (f_current_inventory_state, natural-key upsert), the fold's last-arrival-wins can resolve a key to a stale row before the SQL merge guard ever sees the fresh one — the guard protects batch-vs-table, but only the fold decides row-vs-row within a batch.This is Change 3 (fold half) of the Zero Inventory Metric design (Sharpened Option E, PMT-4302), and one half of its reviewer Confirmation 8. The group-scoped merge guard is the other half and lands in the consumers (
general#62for Redshift;rstreams-connector-datalakeneeds its own — itsmergeFactcurrently has no predicate).Base branch
Based on
feature/aws-sdk-v3-again— the AWS SDK v3 bar defines the current line (CUP Shared Services). Notes for whoever merges:combineRecordsrefactor), which targetsdevelopmentand will arrive here via the next dev→v3 sync (Mergedevelopment(with our current Datawarehouse code) into the AWS branch. #232-style): this change orders the rows the collapse sees; it does not touch the collapse itself. The delete/reactivate rules incombineRecordsare order-relative, so they remain correct under source-EID order.combine-order.test.jsspecifically to avoid colliding with fix(combine): preserve insert data on same-batch create+delete (RPL-6000) #249'scombine.test.js.development's delete-priority fix — that belongs to the dev→v3 sync, not this PR.Mechanics
load.jsscansstructurefor acombineOrderfield flag (same pattern asnk/sk/scd) and passes{ orderFields: { [table]: field } }tocombine(). Because the flag rides in the shareddw_fieldsentry, every loader that reads the schema folds the same way — Redshift and Databricks cannot diverge at the fold.{md5(nk)}-{48-char order key}-{9-digit arrival}{json}; default tables keep{md5(nk)}-{arrival}{json}. Sort already runs underLC_ALL=C.source_eid(a backfill row) always loses the fold to a live row. Asserted by test, per the design's testing plan.combine()'soptswere discarded (Object.assigncalled with a single argument), sodateFormatcould never be overridden. No in-repo caller passed opts, so no behavior change.Tests
common/test/datawarehouse/combine-order.test.js— 8 passing (npx mocha test/datawarehouse/combine-order.test.js):inversion repair · backfill-loses-in-both-arrival-orders · backfill-only passthrough · explicit-null survives (null is a value, not a gap) · equal-eid tie-break · per-key independence · default mode locked · per-table scoping.
Consumption plan
development-line consumers whenever the branches reconcile (or via cherry-pick if the 4.x line needs it before the 5.x jump — sequencing owned by CUP Shared Services alongside fix(combine): preserve insert data on same-batch create+delete (RPL-6000) #249's release tooling).item-dwadds"combineOrder": truetosource_eidindw_fields/f_current_inventory_state.json(one line on item-dw#23).generalanddata-lake-ingestion-botsbumpleo-connector-commonto a version containing this change.🤖 Generated with Claude Code
https://claude.ai/code/session_01DhcouH67CgpNGpBZ29ujbk