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.

TransformExperimental

std:batch #

Groups consecutive items into JSON arrays of size items.

For example: group 500 records into one array for a bulk API call.

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

Ports #

std:batch takes in and produces out.std:batchinrecordsoutrecords
std:batch takes in and produces out.std:batchinrecordsoutrecords
Named ports from the latest published contract. Dashed lines are optional ports.
Ports of std:batch
PortDirectionKindRequiredDescription
ininputrecordsyes
outoutputrecordsyesOne JSON array per item.

Parameters #

Parameters of std:batch
NameTypeDefaultRequiredDescription
sizeintegernoneyes Minimum 1. Maximum 1000000.

When to use it #

  • The next pipe takes an array per call — a bulk insert, a bulk API request: size: 500 emits 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 #

std:batch groups five items into arrays of twoThe 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.in12345std:batchsize: 2out12345std:batch groups five items into arrays of twoThe 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.in12345std:batchsize: 2out12345

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:batch arrays — data. Visible to every later pipe, exactly size long, 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 windows port, made by std: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.

Parameters
{
  "size": 2
}
Input: in
1
2
3
4
5
Expected output: out
[1,2]
[3,4]
[5]

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

pipeline.yaml
nodes:
  batch:
    pipe: std:batch
    inputs:
      in: {from: inputs.in}
    parameters:
      size: 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.

Command
printf '%s\n' 1 2 3 4 5 | openflange run std:batch --param size=2
Standard output (out)
[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