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.

TransformExperimentalneeds: variadic

std:merge #

Merges several streams into one, interleaved or concatenated.

For example: combine orders from two shops into one stream.

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

Ports #

std:merge takes in and produces out.std:mergeinrecordsoutrecords
std:merge takes in and produces out.std:mergeinrecordsoutrecords
Named ports from the latest published contract. Dashed lines are optional ports.
Ports of std:merge
PortDirectionKindRequiredDescription
ininputrecordsyes variadic: fed by several producers.
outoutputrecordsyes

Parameters #

Parameters of std:merge
NameTypeDefaultRequiredDescription
modestring"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:merge is the only way to feed one input from several producers.
  • A fixed order — last month's file, then this month's: mode: concat forwards 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: interleave the order between producers is unspecified and may differ between runs. If the order matters, use concat.

How it works #

Two producers merged by std:merge in both modesProducer 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.Interleave — one possible orderaa1a2a3bb1b2std:mergemode: interleaveouta1b1a2a3b2Concat — always this orderaa1a2a3bb1b2std:mergemode: concatouta1a2a3b1b2Two producers merged by std:merge in both modesProducer 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.Interleave — one possible orderaa1a2a3bb1b2std:mergemode: interleaveouta1b1a2a3b2Concat — always this orderaa1a2a3bb1b2std:mergemode: concatouta1a2a3b1b2

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:

yaml
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.

Parameters

This test sets no parameters.

Input: in
1
2
3
Expected output: out
1
2
3

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

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.

Command
printf '%s\n' 1 2 3 | openflange run std:merge
Standard output (out)
1
2
3

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).

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.

yaml
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