Expressions, filters and maps

Three processors evaluate an expression over telemetry:

Processor

What it does

processor.expression

computes one or more typed fields from expressions

processor.filter

keeps the records a boolean expression selects

processor.map

projects, renames and drops fields, with optional computed fields

All three take device_telemetry in and emit device_telemetry, so they may sit anywhere a processor may: before or after a window aggregate or a fusion node, or in a chain of their own.

Expressions are written in CEL (the Common Expression Language) under the profile this page defines — dialect thinglogic-expr/v2. The same profile is enforced by pipeline validation, by the deploy compiler, by the worker that executes a deployed pipeline, and by the dry run, so an expression that validates cannot mean something different at runtime.

Referring to fields

A field of the incoming telemetry payload is addressed as in.<field>:

in.value > 30.0 && in.metric == "temperature"

in is reserved: every in.<field> in the author’s text is bound to exactly one flat variable before CEL sees it. The set of addressable fields is the payload schema of the upstream port — the telemetry contract, or the output of an intermediate expression / map node, including the fields it computes and excluding the fields it drops or renames.

A reference to a field that is not on that input schema is refused with expression_unknown_field; a field whose type makes the operation invalid is refused with expression_type_mismatch. Both refusals point at the exact character range in the author’s expression — see Checking an expression.

Field names follow ^[A-Za-z_][A-Za-z0-9_]{0,63}$. A payload field whose name does not match is simply not addressable through in. (it is still carried through untouched).

Types

An expression is statically typed from the input schema and the CEL type inference rules. The JSON-Schema types map as follows:

Schema type

Expression type

string

string

integer

int

number

double

boolean

bool

array

list

object

map

anything else / no type

dyn

dyn is accepted where CEL can decide at evaluation time. The result of a computed field must be representable on the telemetry payload: string, int, double, bool, list, map, or null. A result that is not — a timestamp, bytes, a map with non-string keys, a non-finite float — is a located expression_type_unsupported at compile time when the compiler can see it, and an evaluation error otherwise. A processor can never write a value the delivery path cannot serialise.

Operators and functions

The CEL operator set is available within the profile:

  • arithmetic + - * / %, including + for string concatenation and list concatenation;

  • comparison == != < <= > >=;

  • logical && || ! and the ternary cond ? a : b;

  • list membership: in.metric in ["temperature", "humidity"];

  • membership and indexing on maps and lists with [];

  • the CEL string functions contains(), startsWith(), endsWith(), matches() and size():

in.metric.startsWith("temp")
in.metric.contains("perature")
in.metric.endsWith("ture")
in.metric.matches("^temp.*$")
size(in.metric) > 3

A matches() pattern must be a string literal of at most 512 characters. A dynamic pattern has no static bound, so it is refused with expression_forbidden_construct rather than accepted with an unbounded cost.

The profile adds the trigonometric functions sin(), cos(), tan(), asin(), acos() and atan(). Each takes a double (an INT argument is accepted as well) and produces a double:

sin(in.value) > 0.0
cos(in.value) - atan(in.value)

They are pure: no clock, no I/O, no randomness. An argument outside a function’s domain — asin(2.0), for example — produces a non-finite result, which is an evaluation error on that record: the node counts it and the pipeline continues, the same way a divide by zero is handled.

Time

Two implicit INT variables carry epoch milliseconds:

  • event_time — the record’s event instant;

  • receipt_time — the instant the runtime processed it.

receipt_time - event_time > 60000

They are not part of the input schema, and a schema that declares either name is refused, so a payload field can never shadow them. The wire’s ts field is an ISO-8601 string and there is no permitted way to parse it into an instant in this profile (the timestamp() / duration() constructors are forbidden); use event_time for event-time logic.

Bounds

Evaluation is bounded statically, before anything runs:

Bound

Value

expression length

4,096 characters

expression tokens

512

expression nesting depth

32

matches() pattern length

512 characters

computed fields per expression / map node

16

An expression over a bound is refused with expression_cost_exceeded, located at the token where the budget is exhausted. The bound is the profile’s own lexical budget: the CEL implementation used by the service exposes no cost model, so the service does not pretend to expose one.

Forbidden constructs

These are refused with expression_forbidden_construct:

  • the CEL macros all, exists, exists_one, map, filter and has — the first five expand to comprehensions whose iteration count would escape the static token budget, and this profile has no absent-versus-null distinction for has to test;

  • the constructors now(), timestamp() and duration() — their values are not representable on the pipeline payload;

  • raw and bytes string literals (r"…", b"…");

  • a matches() pattern that is not a string literal.

Runtime behaviour

Expression evaluation never raises into the pipeline. A failure on one record — divide by zero, a dyn value that turned out to be the wrong type, a non-finite result — is an error value for that field:

  • processor.expression and processor.map omit the field that failed, emit the record anyway with expression_status: "error", and list every failed field in expression_errors (field, code = expression_evaluation_error, detail). The record is not dropped and the pipeline is not stopped.

  • processor.filter drops the record when the expression is false or errors — a filter that cannot decide must not pass the record through as though it had. Both outcomes are counted separately, so a broken filter is visible in the node’s metrics rather than silently discarding data.

Per-node counters — records_seen, records_emitted, fields_computed, evaluation_errors, and for map fields_renamed / fields_dropped, and for filter filtered_out — are reported in the dry-run receipt and in the runtime status beacon. The dry run and the worker run the same evaluator, so the counts describe the same program.

The three processors

Compute fields — processor.expression

{"id": "e1", "type": "processor", "subtype": "expression",
 "config": {"fields": [
   {"name": "temp_f", "expression": "in.value * 9.0 / 5.0 + 32.0"},
   {"name": "hot",    "expression": "in.value > 30.0"}
 ]}}
  • fields is required and carries 1 to 16 {name, expression} entries; name must be a valid field name and the config is closed (additionalProperties: false).

  • Every expression is evaluated against the input payload; results are added to the record with the computed names.

  • Replacing value is allowed when the expression’s static type is numeric — that is what a math expression is for. The telemetry identity fields (device_id, scope_id, metric, ts) cannot be replaced.

  • The output always carries expression_status (ok | error) and expression_errors, written last so an input field of the same name cannot spoof them.

Keep records — processor.filter

{"id": "f1", "type": "processor", "subtype": "filter",
 "config": {"expression": "in.metric == \"temperature\" && in.value > 10.0"}}
  • expression is required and must be statically boolean. An expression whose type could be a string is refused at validation.

  • A passing record is emitted unchanged, with filter_status: "passed" written last.

Project, rename, drop — processor.map

{"id": "m1", "type": "processor", "subtype": "map",
 "config": {
   "fields": [{"name": "temp_f", "expression": "in.value * 1.8 + 32.0"}],
   "rename": {"value": "raw_value"},
   "drop":   ["device_id"]
 }}
  • At least one of fields, rename or drop must be present.

  • The order is fixed: computed fields are evaluated against the input payload; the input is then copied with rename and drop applied; computed values are written last. A computed field may therefore replace a retained field of the same name (value included, when numeric).

  • rename maps an input field to a new name. The telemetry required fields (device_id, scope_id, metric, value, ts) cannot be renamed away or dropped; a rename target cannot collide with a retained field, map two sources to one name, or claim a field the runtime writes (expression_status, expression_errors, filter_status). A renamed-away source is removed from the output.

  • drop names input fields to remove; it cannot name a required telemetry field or a field that is also renamed.

  • The output carries expression_status / expression_errors as for processor.expression.

Checking an expression

POST /api/v1/expressions/check answers what an expression means — validity, result type, referenced fields and located errors — without saving a pipeline or executing anything. It is gated by the same thinglogic:Pipeline:Validate action a pipeline validation needs.

The request is one of two forms: against a published input schema by reference, or against an inline JSON Schema.

{"expression": "in.value > 5.0",
 "input_schema_ref": "source.device-mqtt-stream.out",
 "dialect": "thinglogic-expr/v2"}
{"expression": "in.value > 5.0",
 "input_schema": {"type": "object",
                  "properties": {"value": {"type": "number"}},
                  "required": ["value"]}}
  • Exactly one of input_schema_ref or input_schema is required; expression is required; dialect is optional and, when present, must be thinglogic-expr/v2.

  • input_schema_ref values are the catalog’s own output-port names, <node_type_id>.<port> — for example source.device-mqtt-stream.out. Calling GET /api/v1/catalog lists the node types and their ports; a ref is valid when that node type publishes a non-empty schema for that output port.

A well-formed request is answered 200 whether or not the expression is valid — the answer is the payload. For in.metric > 5 against the telemetry schema (where metric is a string) the answer is:

{
  "valid": false,
  "dialect": "thinglogic-expr/v2",
  "output_type": null,
  "referenced_fields": ["metric"],
  "errors": [
    {"code": "expression_type_mismatch",
     "detail": "found no matching overload for '_>_' applied to '(string, int)'",
     "span": {"start": 10, "end": 11, "line": 1, "column": 11}}
  ]
}

For a valid expression, valid is true, output_type is one of string, int, double, bool, list, map or null, and errors is empty. The span is a character range in the author’s own expression — start/end plus 1-based line/column — so an editor can underline exactly the offending token. input_schema_ref is echoed when the caller supplied one; it is null for an inline schema.

A request that cannot be posed is refused with 400 and a PLT-0095 application/problem+json document carrying a machine code:

Code

Meaning

expression_request_invalid

the body is not an object, carries an unknown member, lacks expression, or supplies zero or two input schemas

expression_schema_invalid

the inline schema cannot be turned into an expression field map

expression_schema_ref_unknown

the ref is not a published output-port schema; the detail names the vocabulary

expression_dialect_unsupported

the named dialect is not thinglogic-expr/v2

Parity with StreamPipes

The three processors cover the StreamPipes pipeline vocabulary in one language rather than one processor per transformation:

StreamPipes element

ThingLogic

Math Expression

processor.expression — several computed fields, each typed

Numerical / Text / Boolean / List filters

processor.filter — a boolean expression with comparisons, membership and string functions

Projection

processor.map — computed fields, rename and drop

Text Filter (==, contains, prefix, regex)

filter expressions using ==, contains(), startsWith(), matches()

List membership (in)

the CEL in operator

Field Renamer

processor.map rename

Measurement Unit Converter

the math operators — conversion is an expression, not a node type

A later measurement-unit converter node, if one is added, is an ordinary node type; the expression profile does not need to know about units.