bag_merge
function in APL (Axiom Processing Language) to merge two or more dynamic (JSON-like) bags into a single dynamic value. This function is useful when you want to aggregate multiple properties from different sources or rows into one unified structure. The function is especially valuable in scenarios involving flexible schemas, such as semi-structured log or trace data, where each record might contain partial metadata that you want to consolidate.
Use bag_merge
to combine dynamic values across groups or time ranges. When multiple input bags share the same property name, bag_merge
returns the last one by default, replacing earlier ones.
bag_merge
is currently in private preview. To try it out, contact Axiom.For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
In Splunk, you use
spath
, mvcombine
, or eval
with json_object
and json_merge
-style logic to work with JSON objects. APL’s bag_merge
provides a simpler and more direct way to merge dynamic values (bags) across rows or groups.ANSI SQL users
ANSI SQL users
ANSI SQL doesn’t have a built-in equivalent to APL’s
bag_merge
because it lacks native support for dynamic (JSON-like) objects and merging them. You often need to write complex expressions using JSON_OBJECT
, JSON_MERGE
, or user-defined functions. APL handles this use case natively with bag_merge
.Usage
Syntax
Parameters
Name | Type | Description |
---|---|---|
Bag1, Bag2, ... | dynamic | The bags you want to merge. |
Returns
A single dynamic value that merges all bags in the group. If the same key appears in multiple bags, the value from the last bag takes precedence.Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Combine metadata from multiple logs for each user into a single object to simplify downstream analysis.QueryOutput
Each row shows merged HTTP metadata for each unique user.
id | merged_metadata |
---|---|
user1 | {'uri': '/home', 'status': '200', 'method': 'GET'} |
user2 | {'uri': '/cart', 'status': '404', 'method': 'POST'} |
List of related functions
- bag_has_key: Checks whether a dynamic property bag contains a specific key.
- bag_keys: Returns all keys in a dynamic property bag. Use it when you need to enumerate available keys.
- bag_pack: Converts a list of key-value pairs to a dynamic property bag. Use when you need to build a bag.