| Ocalt Query Language
Pricing Dashboard ocalt.com v1.0

Multivariable & COLLAPSE

A multivariable is created when two or more AND branches bind to the same variable name. Using a multivariable as the operand to any verb or operation triggers parallel execution across all branches simultaneously. This is the core mechanic — one verb call, running in parallel over every branch result.

When you don't need a multivariable

Different variable names per branch — just regular variables, emit directly.

UPPER "hello" SET ?a AND UPPER "world" SET ?b AND UPPER "foo" SET ?c AFTER EMIT ?a & " | " & ?b & " | " & ?c
Try it ›

Creating a multivariable

Use the same variable name across AND branches. OQL stores each result at its branch index.

UPPER "alpha" SET ?r AND UPPER "beta" SET ?r AND UPPER "gamma" SET ?r (* ?r: branch 0 = "ALPHA", branch 1 = "BETA", branch 2 = "GAMMA" *)

Operand fan-out — parallel execution

When you pass a multivariable as the operand to any verb, OQL executes that verb in parallel across all active branches. The output is a new multivariable — one result per branch. This is not a loop. All branches run simultaneously.

UPPER "hello" SET ?r AND UPPER "world" SET ?r AND UPPER "foo" SET ?r AFTER LOWER ?r SET ?low (* LOWER fired in parallel on all 3 branches at once: branch 0: "HELLO" → "hello" branch 1: "WORLD" → "world" branch 2: "FOO" → "foo" ?low is a new multivariable with those 3 results *) AFTER EMIT ?low (* → one of "hello", "world", "foo" at random *)
Try it ›

This chains — each subsequent verb that receives a multivariable keeps fanning out in parallel:

FETCH "https://httpbin.org/uuid" SET ?r AND FETCH "https://httpbin.org/uuid" SET ?r AND FETCH "https://httpbin.org/uuid" SET ?r AFTER EXTRACT ?r WHERE "uuid" SET ?ids (* EXTRACT fired in parallel on all 3 fetch results simultaneously *) COLLAPSE ?ids SET ?all AFTER EMIT ?all
Try it ›

EMIT on a multivariable — one result at random

EMIT does not fan-out. It returns one active branch result at random. This is intentional — useful when parallel sources are redundant and any result will do.

FETCH "https://replica1.example.com/data" SET ?r AND FETCH "https://replica2.example.com/data" SET ?r AND FETCH "https://replica3.example.com/data" SET ?r AFTER EMIT ?r (* → returns whichever replica responded — any one result is acceptable *)
Try it ›

COLLAPSE — all branches as an ordered array

Each element has branch (0-based index) and result. Failed branches have result: null, failed: true, plus code and message.

UPPER "alpha" SET ?r AND UPPER "beta" SET ?r AND UPPER "gamma" SET ?r COLLAPSE ?r SET ?all AFTER EMIT ?all
Try it ›

Accessing collapsed branches

UPPER "alpha" SET ?r AND UPPER "beta" SET ?r COLLAPSE ?r SET ?all AFTER EMIT ?all(0)(result) & " / " & ?all(1)(result) (* → "ALPHA / BETA" *)
Try it ›

FOREACH over collapsed results

UPPER "red" SET ?r AND UPPER "green" SET ?r AND UPPER "blue" SET ?r COLLAPSE ?r SET ?all AFTER FOREACH ?all AS ?item OPEN NEST EMIT ?item(result) CLOSE NEST
Try it ›

Failed branches

A failed branch is pruned — it does not fail the entire chain. The remaining branches continue normally.

FETCH "https://httpbin.org/uuid" SET ?r AND FETCH "https://this-will-fail.invalid/" SET ?r COLLAPSE ?r SET ?all AFTER EMIT ?all(0)(result)(uuid) (* OK — real UUID *) AFTER EMIT ?all(1)(failed) (* true — branch errored *)
Try it ›
PatternVariable namesBehaviour
Independent parallelDifferent: SET ?a, SET ?bRegular vars — emit directly
Multivariable + EMITSame: SET ?rOne random active branch result
Multivariable + verb operandSame: SET ?rVerb fires in parallel on every branch
Multivariable + COLLAPSESame: SET ?rAll results as ordered array