put
Table of Contents
Operator
put — add or modify fields of records
Synopsis
[put] <field>:=<expr> [, <field>:=<expr> ...]
Description
The put
operator modifies its input with
one or more field assignments.
Each expression is evaluated based on the input record
and the result is either assigned to a new field of the input record if it does not
exist, or the existing field is modified in its original location with the result.
New fields are append in left-to-right order to the right of existing record fields while modified fields are mutated in place.
If multiple fields are written in a single put
, all the new field values are
computed first and then they are all written simultaneously. As a result,
a computed value cannot be referenced in another expression. If you need
to re-use a computed result, this can be done by chaining multiple put
operators.
The put
keyword is optional since it is an
implied operator.
Each <field>
expression must be a field reference expressed as a dotted path or one more
constant index operations on this
, e.g., a.b
, this["a"]["b"]
,
etc.
Each right-hand side <expr>
can be any SuperPipe expression.
For any input value that is not a record, an error is emitted.
Note that when the field references are all top level,
put
is a special case of a yield
with a
record literal
using a spread operator of the form:
yield {...this, <field>:<expr> [, <field>:<expr>...]}
Examples
A simple put
put c:=3
{a:1,b:2}
Loading...
The put
keyword may be omitted
c:=3
{a:1,b:2}
Loading...
A put
operation can also be done with a record literal
yield {...this, c:3}
{a:1,b:2}
Loading...
Missing fields show up as missing errors
put d:=e
{a:1,b:2,c:3}
Loading...
Non-record input values generate errors
b:=2
{a:1}
1
Loading...