over

Table of Contents

Operator

over — traverse nested values as a lateral query

Synopsis

over <expr> [, <expr>...]
over <expr> [, <expr>...] [with <var>=<expr> [, ... <var>[=<expr>]] => ( <lateral> )

The over operator traverses complex values to create a new sequence of derived values (e.g., the elements of an array) and either (in the first form) sends the new values directly to its output or (in the second form) sends the values to a scoped computation as indicated by <lateral>, which may represent any SuperPipe subquery operating on the derived sequence of values as this.

Each expression <expr> is evaluated in left-to-right order and derived sequences are generated from each such result depending on its types:

  • an array value generates each of its elements,
  • a map value generates a sequence of records of the form {key:<key>,value:<value>} for each entry in the map, and
  • all other values generate a single value equal to itself.

Records can be converted to maps with the flatten function resulting in a map that can be traversed, e.g., if this is a record, it can be traversed with over flatten(this).

The nested subquery depicted as <lateral> is called a lateral subquery.

Examples

Over evaluates each expression and emits it

over 1,2,"foo"
true
Loading...

The over clause is evaluated once per each input value

over 1,2
true
Loading...

Array elements are enumerated

over [1,2],[3,4,5]
true
Loading...

Over traversing an array

over a
{a:[1,2,3]}
Loading...

Filter the traversed values

over a |> this % 2 == 0
{a:[6,5,4]}
{a:[3,2,1]}
Loading...

Aggregate the traversed values

over a |> sum(this)
{a:[1,2]}
{a:[3,4,5]}
Loading...

Aggregate the traversed values in a lateral query

over a => ( sum(this) )
{a:[1,2]}
{a:[3,4,5]}
Loading...

Access the outer values in a lateral query

over a with s => (sum(this) |> yield {s,sum:this})
{a:[1,2],s:"foo"}
{a:[3,4,5],s:"bar"}
Loading...

Traverse a record by flattening it

over flatten(r) with s => (yield {s,key:key[0],value})
{s:"foo",r:{a:1,b:2}}
{s:"bar",r:{a:3,b:4}}
Loading...
Next: pass

SuperDB