Expressions for real-time

Amperity Expression Language (AEL) defines how real-time events and profiles are recognized, filtered, and computed. This page describes the subset of AEL used to configure real-time features; it is not a complete AEL reference.

Where expressions are used

You write expressions in these real-time settings:

  • Event streams – a routing expression recognizes each incoming event and determines its event type. A stream may also define expressions for the event timestamp and event ID.

  • Event types – each field in an event type uses an expression to extract and coerce a value from the raw event payload.

  • Real-time segments – a segment is defined by a boolean expression that is evaluated against a profile’s attributes.

  • Real-time attributes – aggregation and computed attributes use expressions over a profile’s events and attributes.

Referencing fields

Reference a field by name. Enclose a name that contains spaces or other non-identifier characters in backticks, reach a nested field with dot notation, and reach an array item with bracket notation and a zero-based index:

email
`loyalty tier`
address.city
items[0]

Important

Use bracket notation for array indexes (items[0]). Dot notation followed by a number (items.0) is not valid.

Comparing and combining values

Real-time segment expressions and aggregation conditions are boolean expressions. The following operators are available:

  • Comparison: =, !=, <, <=, >, >=

  • Membership: in, not in

  • Null checks: is null, is not null

  • Logical: and, or, not

Parsing event values

Event type field expressions often coerce raw payload values into the field’s type. Commonly used functions include:

  • to_timestamp and timestamp_from_millis – produce a timestamp from a string or an epoch-milliseconds value.

  • to_int and to_string – cast a value to an integer or a string.

  • coalesce – return the first non-null value from a list.

Working with time windows

Time-windowed expressions–such as those used in real-time segments and aggregation attributes–take a unit argument. The valid values are SECONDS, MINUTES, and HOURS.

Beyond this subset

AEL includes many additional operators and functions–arithmetic, decimal precision, array operations, and more–that are beyond the subset needed for real-time configuration.