Ports #
| Port | Direction | Kind | Required | Description |
|---|---|---|---|---|
in | input | records | yes | |
out | output | records | yes |
Parameters #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
expr | string | none | yes | Starlark 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
- To keep or drop whole records, use
std:filter. To only pick or rename members,std:selectandstd:renameneed no expression.
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.
{
"expr": "item * 2"
}1
2
32
4
6The same step as a node of a 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.
printf '%s\n' 1 2 3 | openflange run std:map --param 'expr=item * 2'2
4
6Executed 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.
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
- Normative definition: std:map in the standard library specification
- Manifest and tests: std/0.1/map in the specification repository
- Expression parameters are Starlark: how expressions are evaluated