[STRATCONN-6533] Fix inconsistent field ordering in LiveRamp CSV generation#3587
[STRATCONN-6533] Fix inconsistent field ordering in LiveRamp CSV generation#3587
Conversation
Previously, the order of fields in generated CSV files depended on the order payloads were processed, leading to inconsistent column positions across different batches sent to LiveRamp. Changes: - Modified generateFile() to sort fields alphabetically (after audience_key) - Ensures consistent field ordering regardless of payload order - audience_key always remains the first column - All other fields are sorted alphabetically for predictability Testing: - Added 2 new test cases demonstrating consistent field ordering - Updated 8 existing test cases with new alphabetically sorted expectations - All 36 tests passing Ticket: STRATCONN-6533 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes inconsistent CSV header ordering in the LiveRamp Audiences destination by making the header generation deterministic across batches, preventing schema/column drift when payload ordering varies.
Changes:
- Sort CSV headers alphabetically while keeping
audience_keyas the first column. - Update CSV generation to use the new sorted header array for row alignment and header output.
- Update and add tests to validate consistent header ordering across different payload orders.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/destination-actions/src/destinations/liveramp-audiences/operations.ts | Ensures deterministic CSV header ordering by sorting non-audience_key fields alphabetically. |
| packages/destination-actions/src/destinations/liveramp-audiences/tests/operations.test.ts | Updates expected outputs and adds coverage to confirm consistent ordering across batches. |
packages/destination-actions/src/destinations/liveramp-audiences/operations.ts
Show resolved
Hide resolved
sayan-das-in
left a comment
There was a problem hiding this comment.
Changes looks good.
Can we check with LR Support if changing field order impacts existing configured audiences ?
|
thing to note
|
confirmed with Liveramp team, this is not a problem. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3587 +/- ##
==========================================
+ Coverage 80.31% 80.35% +0.03%
==========================================
Files 1283 1283
Lines 23567 23604 +37
Branches 4726 4742 +16
==========================================
+ Hits 18928 18967 +39
+ Misses 3757 3753 -4
- Partials 882 884 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Adds a metric that tracks whether incoming payload headers are naturally in alphabetical order before any sorting is applied. This helps monitor data patterns and understand the impact of the alphabetical field ordering feature. The metric 'liveramp_audiences.incoming_header_order' is emitted with tags: - order:alphabetical - when incoming headers are already alphabetically sorted - order:non_alphabetical - when they are not Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Added 7 new tests in operations.test.ts to verify isIncomingAlphabetical detection - Added 4 integration tests in liveramp.test.ts to verify stats client metrics - Achieves 100% coverage for operations.ts across all metrics - Maintains >95% coverage for action handlers (S3 and SFTP) - Tests cover alphabetical detection, default parameters, and edge cases Total test count increased from 79 to 80 tests, all passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract tag enrichment logic to shared enrichStatsContextWithMetadata() function in operations.ts - Update S3 and SFTP actions to use common function for DRY code - Add comprehensive test assertions to verify all metadata tags are properly included in metrics - Improve efficiency with single array assignment instead of multiple reassignments Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Problem
The LiveRamp Audiences destination was generating CSV files with inconsistent field ordering across different batches. The field order depended on which payload was processed first in each batch, leading to:
Solution
Modified the
generateFile()function inoperations.tsto sort fields alphabetically (afteraudience_key):audience_keywhich always comes first)Changes
operations.ts:53-57to add alphabetical sorting logicheaderArraytosortedHeaderArrayField Ordering
Before: Field order varied based on payload processing order
After:
audience_key(always first)age,city,email,first_name,phone, etc.)Testing
Tested in stage with instruction here
Generated dummy data with 2 batches with randomly missing properties. When this fix was not applied the CSV looked like below where the headers are not alphabetically ordered.


After applying the fix, the data is ordered.
Ticket
STRATCONN-6533