Ports #
| Port | Direction | Kind | Required | Description |
|---|---|---|---|---|
in | input | records | yes | variadic: fed by several producers. |
out | output | records | yes |
Parameters #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
mode | string | "interleave" | no | One of: interleave, concat. |
When to use it #
- Two sources produce records of the same shape and the next step should see them all:
std:mergeis the only way to feed one input from several producers. - A fixed order — last month's file, then this month's:
mode: concatforwards the producers one after another, in the order they are listed. - Bring the branches of a split or partition back together after each was processed its own way.
When to use something else
- With the default
mode: interleavethe order between producers is unspecified and may differ between runs. If the order matters, useconcat.
How it works #
Producer a sends a1, a2, a3 and producer b sends b1, b2. In interleave mode the items come out as they arrive — here a1, b1, a2, a3, b2, one possible order; each producer's own order is kept. In concat mode everything from a comes first, then everything from b.
Drawn from a real run of the reference implementation. Where the specification leaves the order open, one permitted order is drawn; the real run was checked to be a permitted order too.
Two producers, one input #
An input normally has exactly one producer. When two branches should continue as one stream, the pipeline says so with a std:merge node whose input lists the producers:
nodes:
both:
pipe: std:merge
inputs:
in: {from: [first.outputs.out, second.outputs.out]}
parameters: {mode: concat}Mapping several producers to an ordinary input is an invalid pipeline; in of std:merge is a variadic input, which is why the pipe needs a runner with the variadic capability. Items pass through unchanged.
Interleave or concat #
mode: interleave(default). Items are forwarded as they arrive, and every producer is read concurrently, so a slow producer never blocks the others. The order of the items of each producer is kept. How the producers mix is unspecified and may differ between runs — the drawing shows one possible outcome.mode: concat. Everything from the first listed producer, then everything from the second, and so on. The output is deterministic.
The price of concat #
With concat, a later producer is not read until the earlier ones have ended; it is held back by backpressure. That is harmless for independent sources. It can stall when one upstream node feeds both a later concat input and, through a path that blocks, an earlier input of the same merge: holding back the later branch eventually holds back the shared producer, and the earlier input never ends. The specification requires a runner to notice that every node is blocked and to fail the run with E_RESOURCE rather than hang.
Rule of thumb from the manifest: concat for independent sources, interleave for branches of a common upstream.
A tested example #
Nothing here is invented: this is the test “a single producer passes through” from the pipe's own portable test file, which every conformant runner must pass.
This test sets no parameters.
1
2
31
2
3The same step as a node of a pipeline.yaml:
nodes:
merge:
pipe: std:merge
inputs:
in: {from: [inputs.in]}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:merge1
2
3Executed 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).
The explicit way to feed one input from several producers. Items pass through unchanged and are never decoded; nothing is dropped and nothing is buffered beyond the runner's bounded edges.
mode: interleave(default) — items are forwarded as they arrive. The relative order of the items of each producer is preserved; how the producers interleave is unspecified and may differ between runs (the pipe is therefore not declared deterministic).mode: concat— deterministic: everything from the first listed producer, then everything from the second, and so on. A later producer is not read until the earlier ones have ended, so it is held back by backpressure.
Concat and shared upstreams. If one producer broadcasts both to a later
concat input and, through a blocking path, to an earlier input of the same
merge, holding back the later branch also holds back the shared producer once
the bounded buffers fill, and the earlier input never ends. The specification
requires a runner to detect that every node is blocked and fail with
E_RESOURCE. Prefer concat for independent sources and interleave for
branches of a common upstream.
in is a variadic input, so the pipe declares requires: [variadic]. A
producer that is a disconnected optional pipeline input contributes nothing.
nodes:
both:
pipe: std:merge
inputs:
in: {from: [first.outputs.out, second.outputs.out]}
parameters: {mode: concat}Reference #
- Maturity
- Experimental
- Needs the runner capability
variadic- Processing scope
record- Manifest version
0.1.0
- Normative definition: std:merge in the standard library specification
- Manifest and tests: std/0.1/merge in the specification repository