Working with Arrays

AMPS supports filters that operate on arrays in messages. There are two simple principles behind how AMPS treats arrays:

  1. Binary operators that yield true or false (for example, =, <, LIKE) are array aware, as is the IN operator. These operators work on arrays as a whole, and evaluate every element in the array.

  2. Arithmetic operators, functions, user-defined functions and other scalar operators, are not array aware, and use the first element in the array.

With these simple principles, you can predict how AMPS will evaluate an expression that uses an array. For any operator, an empty array evaluates to NULL.

Let's look at some examples. For the purposes of this section, we will consider the following JSON document:

{
    "data"  : [1, 2, 3, "zebra", 5],
    "other" : [14, 34, 23, 5]
}

While these arrays are presented using JSON format for simplicity, the same principles apply to arrays in other message formats.

Here are some examples of ways to use an array in an AMPS filter:

Determining if any element in an array meets a criteria

To determine this, you provide the identifier for the array, and use a comparison operator.

Determine whether a specific value is at a specific position

To determine this, use the subscript operator [] on the XPath identifier to specify the position, and use the equality operator to check the value at that position.

Determine whether any value in one array is present in another array

Determine whether an array contains one of a set of values

These patterns and principles hold regardless of the original representation of the array in a document.

When creating an expression that uses a field in a compound value, keep in mind that AMPS represents compound values as described in the section on Compound Data Types in AMPS.

Last updated

Copyright 2013-2024 60East Technologies, Inc.