I’m using multiple logging branches in a SnapLogic pipeline (for example pipeline_start, pipeline_end, and extraction) which are later combined using a Union Snap. { "logging": { "pipeline_start": { "status": "started" } } } { "logging": { "pipeline_end": { "status": "success" } } } { "logging": { "extraction": { "status": "success" } } } After Union, these remain as separate documents, but I want to combine them into a single payload with the key "logging" { "logging": { "pipeline_start": { "status": "started" }, "pipeline_end": { "status": "success" }, "extraction": { "status": "success" } } } I need a clean way (preferably simple Mapper expression) to merge all logging objects into one structured object, ideally an expression that could be dynamic.
What settings should be selected here for the Aggregate snap?
Here's a comprehensive overview of all the settings available in the Aggregate Snap: --- ⚙️ Aggregate Snap Settings 🔤 General | Field | Type | Description | |---|---|---| | Label | String | (Required) A unique name for the Snap. Default: Aggregate | --- 📊 Aggregate Fields (Required Field Set) Defines the aggregate function(s) to apply on input data. | Field | Type | Description | |---|---|---| | Function | Dropdown | (Required) The aggregate function to apply. Options: SUM, COUNT, MIN, MAX, AVG, CONCAT, UNIQUE_CONCAT. Default: SUM | | Field | String/Expression | (Required) JSON path to the field to aggregate (e.g., $Total). | | Result field | String | (Required) The output field name for the computed result (e.g., Revenue). |
💡 Note on AVG: Numeric values with more than 16 digits are rounded up.
--- 🗂️ GROUP-BY Fields (Optional Field Set) Groups the aggregation results. If left blank, the Snap produces a single output document. | Field | Type | Description | |---|---|---| | Field | String/Expression | JSON path for the GROUP-BY field (e.g., $.Product.Name). | | Output field | String | The field name to use in the output. If blank, the Field path is used. | --- 🔧 Additional Settings | Field | Type | Description | |---|---|---| | Integer mode | Checkbox | If selected, produces integer results rounded half up. Ignored for COUNT. Default: Deselected | | Sorted streams | Dropdown | Specifies if input is sorted. Options: Unsorted, Ascending, Descending. Default: Unsorted | | Minimum memory (MB) | String/Expression | Pauses processing if available memory drops below this value. Set to 0 to disable. Default: 500 | | Out-of-memory timeout (minutes) | String/Expression | Throws an exception if the Snap waits longer than this for memory. Default: 30 | | Snap execution | Dropdown | Execution mode: Validate & Execute, Execute only, or Disabled. Default: Validate & Execute | --- ⚠️ Important Notes - Unsorted input with GROUP-BY fields → Use a Sort Snap upstream and set Sorted streams to Ascending or Descending to avoid out-of-memory errors. - CONCAT separates values with a pipe (|); UNIQUE_CONCAT does the same but only for unique values. - This Snap does not support Ultra Tasks. - Does not support list and map objects referenced in JSON paths. --- 🚨 Common Errors | Error | Reason | Resolution | |---|---|---| | EXPRESSIONS_DETECTED | Expressions found in Aggregate fields | Remove all expressions | | ERR_UNSUPPORTED_AGGR_FUNCTION | Invalid aggregate function selected | Choose a valid function | | ERR_MAPDB_VALUE_NULL | MapDB retrieves null for non-null value | Use Sort Snap upstream | --- Let me know if you'd like help configuring a specific setting or building a pipeline with the Aggregate Snap! 😊
What settings should be selected here for the Aggregate snap?
It looks like no Snap is currently selected in the designer. To get specific guidance on configuring the Aggregate Snap, please: 1. Click on the Aggregate Snap in your pipeline canvas to select/focus it. 2. Then ask your question again, and I'll be able to provide tailored configuration advice! --- In the meantime, here's a general overview of the key settings in the Aggregate Snap: 🔧 Aggregate Snap – Key Settings | Setting | Description | |---|---| | Group By Fields | Fields used to group records (similar to SQL GROUP BY). Leave empty to aggregate all records into one. | | Aggregate Fields | Define the aggregation operations (e.g., SUM, COUNT, AVG, MIN, MAX) on specific fields. | | Output Field Name | The name of the output field that will hold the aggregated result. | | Pass Through | When enabled, passes non-aggregated fields through to the output. | 📝 Tips - Group By is optional — omitting it will aggregate all incoming records as a single group. - You can add multiple aggregate columns to compute several metrics at once. - Make sure your input data is sorted by the Group By fields if you're working with large datasets for optimal performance. Select the Aggregate Snap and feel free to ask again for more specific configuration help! 😊
Group by N (with group size of 0, and target field of data) and then mapper with expression below worked perfectly $data.map(item => item.logging).reduce((acc, val) => acc.extend(val), {})
Great to hear that your pipeline is working! 🎉 Let me break down why this combination works so well and what each part is doing: --- ✅ How It Works 1. Group by N (Group Size: 0, Target Field: data) - A group size of 0 means all incoming documents are grouped together into a single array — no limit on group size. - The target field data wraps all grouped documents into a single output document like:
json
{
"data": [
{ "logging": { "key1": "val1", ... } },
{ "logging": { "key2": "val2", ... } },
...
]
}
--- 2. Mapper Expression
javascript
$data.map(item => item.logging).reduce((acc, val) => acc.extend(val), {})
Here's what each step does: | Step | Operation | Description | |------|-----------|-------------| | $data | Field reference | Accesses the grouped array of documents | | .map(item => item.logging) | Array .map() | Extracts the logging object from each item, producing an array of logging objects | | .reduce((acc, val) => acc.extend(val), {}) | Array .reduce() | Merges all logging objects into a single flat object, starting from {} | | .extend(val) | Object extend | Merges each val object's properties into the accumulator acc | --- 🔑 Key Insight: .extend() The .extend() method is a SnapLogic-specific object method that merges the properties of one object into another — similar to Object.assign() in standard JavaScript. This is what makes the reduce work cleanly to flatten multiple objects into one. --- 📌 Summary Flow
Multiple docs → Group by N (all into "data" array) → Mapper merges all "logging" fields into one object
This is a clean and efficient pattern for merging/aggregating nested objects across multiple documents. Let me know if you'd like to adapt this for other use cases! 😊
