Ports #
| Port | Direction | Kind | Required | Description |
|---|---|---|---|---|
in | input | records | yes | |
out | output | records | yes | One JSON array per item. |
Parameters #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
size | integer | none | yes | Minimum 1. Maximum 1000000. |
When to use it #
- The next pipe takes an array per call — a bulk insert, a bulk API request:
size: 500emits arrays of exactly 500 records and a shorter last one. - Process records in fixed groups and flatten the results again with
std:unbatch.
When to use something else
- The arrays are data that every later pipe sees, and there is no time limit: a group is emitted when it is full or the input ends. If a pipe only wants to receive its input in slices, that is batch mode, declared in that pipe's manifest. For groups with a meaning (“the last 5 readings”) use
std:window.
How it works #
The items 1 to 5 go in. With size 2, three items come out, each an array: 1 and 2, 3 and 4, and a final shorter array holding 5.
Drawn from a real run of the reference implementation.
Arrays as data #
std:batch collects consecutive items into JSON arrays of exactly size items and emits each array as one item. When the input ends, the items still pending are emitted as a final, shorter array; an empty array is never emitted. There is no time limit: a group leaves when it is full or the input is over.
After this pipe the arrays are the records. Every later pipe sees them, a filter after it filters arrays, and std:unbatch turns them back into single items.
Four things called “batch” #
The specification keeps them apart, and so should a pipeline:
std:batcharrays — data. Visible to every later pipe, exactlysizelong, no meaning attached to where one ends.- Batch mode — a pipe declares in its manifest that its implementation receives its input in slices. The stream between nodes still carries single items; the slicing is a private matter between the runner and that one pipe. No standard pipe declares it.
- Transport batches — how a runner moves items between nodes internally. Invisible, and never a boundary.
- Windows — groups with a meaning (“the last 5 readings”). Those are frames on a
windowsport, made bystd:window.
The specification's advice: prefer batch mode when a pipe wants to make one call for many items; use std:batch when the arrays themselves are the data.
A tested example #
Nothing here is invented: this is the test “groups with a shorter tail” from the pipe's own portable test file, which every conformant runner must pass.
{
"size": 2
}1
2
3
4
5[1,2]
[3,4]
[5]The same step as a node of a pipeline.yaml:
nodes:
batch:
pipe: std:batch
inputs:
in: {from: inputs.in}
parameters:
size: 2Run 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 4 5 | openflange run std:batch --param size=2[1,2]
[3,4]
[5]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).
Collects consecutive items into JSON arrays of size items and emits each
array as one item. At end of stream a final shorter array is emitted if items
remain; an empty input produces no output. Elements are copied as raw bytes.
These arrays are ordinary data. They are unrelated to the runner's transport
batches and carry no window semantics — use std:window for logical windows
with framing metadata. std:unbatch is the inverse.
State is bounded by size (at most size − 1 pending items).
Reference #
- Maturity
- Experimental
- Processing scope
record- Manifest version
0.1.0
- Normative definition: std:batch in the standard library specification
- Manifest and tests: std/0.1/batch in the specification repository