Ports #
| Port | Direction | Kind | Required | Description |
|---|---|---|---|---|
in | input | records | yes | |
matched | output | records | yes | |
unmatched | output | records | yes |
Parameters #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
expr | string | none | yes | Starlark expression over item and params. |
When to use it #
- Two branches that are both processed: paid orders go to invoicing, the rest to a reminder step.
- Separate records that have a value from those that do not: truthiness decides, so an empty list or a missing member counts as “no”.
When to use something else
- When only one side matters,
std:filteris simpler: its second output is optional. For more than two branches usestd:partitionor chain splits.
How it works #
The items 1, 10, 5 and 20 go in. With the expression item >= 10, the items 10 and 20 leave on matched and the items 1 and 5 leave on unmatched, each in their original order.
Drawn from a real run of the reference implementation.
Every item goes somewhere #
expr is evaluated for every item. A truthy result sends the item, unchanged, to matched; anything else sends it to unmatched. Truthiness is Starlark's: False, None, 0, an empty string and an empty list or dict all count as “no”. The order of the items is kept on each output.
Both outputs are required. Each needs a consumer, or an explicit discard: true — a pipeline that forgets one side does not validate, so nothing is lost by accident. An expression that fails on an item (for example item['missing']) fails the run with E_RUNTIME.
Split, filter or partition #
- One side matters:
std:filterkeeps the matching items and drops the rest, or passes them to its optionalrejectedoutput. - Two sides matter:
std:split. - More than two:
std:partitionroutes by key to up to eight outputs, or chain several splits. A split whose expression names the output is not part of v0.1 — ports are static.
A tested example #
Nothing here is invented: this is the test “routes both ways” from the pipe's own portable test file, which every conformant runner must pass.
{
"expr": "item >= 10"
}1
10
5
2010
201
5The same step as a node of a pipeline.yaml:
nodes:
split:
pipe: std:split
inputs:
in: {from: inputs.in}
parameters:
expr: "item >= 10"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 10 5 20 \
| openflange run std:split \
--param 'expr=item >= 10' \
--output matched=- \
--output unmatched=unmatched.ndjson10
201
5Executed 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 expr for every item and routes the unchanged item to matched
(truthy) or unmatched (falsy). Each output preserves the input order of its
items. Both outputs are required: each needs a consumer or an explicit
discard: true (use std:filter when only one side is wanted).
v0.1 has exactly these two outputs. For more branches chain several splits or
use std:partition.
nodes:
route:
pipe: std:split
inputs: {in: {from: inputs.orders}}
parameters: {expr: "item['total'] >= 100"}
outputs:
large: {from: route.outputs.matched}
small: {from: route.outputs.unmatched}Reference #
- Maturity
- Experimental
- Processing scope
record- Manifest version
0.1.0
- Normative definition: std:split in the standard library specification
- Manifest and tests: std/0.1/split in the specification repository
- Expression parameters are Starlark: how expressions are evaluated