Different pipes. One standard.

Type to search this site.

Search runs in your browser against a static index built with this site (Pagefind). Nothing you type is sent to a server.

TransformExperimental

std:map #

Emits the value of a Starlark expression for every item.

For example: compute a new value from every record.

A pipe is a data processing step with declared inputs and outputs; standard pipes are built into the runner.

Ports #

std:map takes in and produces out.std:mapinrecordsoutrecords
std:map takes in and produces out.std:mapinrecordsoutrecords
Named ports from the latest published contract. Dashed lines are optional ports.
Ports of std:map
PortDirectionKindRequiredDescription
ininputrecordsyes
outoutputrecordsyes

Parameters #

Parameters of std:map
NameTypeDefaultRequiredDescription
exprstringnoneyesStarlark expression over item and params.

When to use it #

  • Add a derived member — dict(item, total = item['price'] * item['qty']) turns {"price":2,"qty":3} into {"price":2,"qty":3,"total":6}.
  • Pull one value out of each record — item['email'] gives a stream of addresses for a pipe that expects plain strings.
  • Reshape records into the form the next pipe expects: exactly one item comes out for every item that goes in.

When to use something else

A tested example #

Nothing here is invented: this is the test “maps scalars” from the pipe's own portable test file, which every conformant runner must pass.

Parameters
{
  "expr": "item * 2"
}
Input: in
1
2
3
Expected output: out
2
4
6

The same step as a node of a pipeline.yaml:

pipeline.yaml
nodes:
  map:
    pipe: std:map
    inputs:
      in: {from: inputs.in}
    parameters:
      expr: "item * 2"

Run it #

The pipe runs on its own from a shell. The input is the test input above. The quickstart shows how to get the openflange command.

Command
printf '%s\n' 1 2 3 | openflange run std:map --param 'expr=item * 2'
Standard output (out)
2
4
6

Executed with openflange 0.0.1 (go1.27.1 linux/amd64), built from commit 11cf8cc of the reference implementation; the output shown is what it printed, and it matches the test.

Notes from the manifest #

The pipe's manifest, OPENFLANGE.md, carries these notes.

Part of the OpenFlange standard library (std, version 0.1).

Evaluates the Starlark expression expr once per input item and emits its value on out. Exactly one item is emitted per input item (a None result is emitted as JSON null), so the pipe is one-to-one and, because Starlark expressions have no side effects, deterministic.

Inside the expression item is the current item: JSON objects are dicts (insertion-ordered), arrays are lists, integers have arbitrary precision and other numbers are 64-bit floats. json and math modules are available; load, files and the network are not.

yaml
nodes:
  upper:
    pipe: std:map
    inputs: {in: {from: inputs.names}}
    parameters:
      expr: "item.upper()"

An expression that fails for an item fails the run with E_RUNTIME; use std:filter or std:validate-schema first to route unwanted items.

Reference #

Maturity
Experimental
Processing scope
record
Manifest version
0.1.0