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:unbatch #

Flattens array items into their elements.

For example: turn arrays back into single records.

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

Ports #

std:unbatch takes in and produces out.std:unbatchinrecordsoutrecords
std:unbatch takes in and produces out.std:unbatchinrecordsoutrecords
Named ports from the latest published contract. Dashed lines are optional ports.
Ports of std:unbatch
PortDirectionKindRequiredDescription
ininputrecordsyesOne JSON array per item.
outoutputrecordsyes

Parameters #

This pipe has no parameters.

When to use it #

  • A pipe answers with one array per call: flatten it so that later pipes see one record per line again.
  • Undo std:batch after the step that needed arrays.

When to use something else

  • It flattens one level only, and an item that is not an array fails the run. An empty array simply emits nothing.

How it works #

std:unbatch flattens arrays by one levelThree array items go in: an array of 1 and 2, an empty array, and an array holding the array [3] and the number 4. Four items come out: 1, 2, the array [3], and 4. The empty array emits nothing.in12[3]4std:unbatchout12[3]4std:unbatch flattens arrays by one levelThree array items go in: an array of 1 and 2, an empty array, and an array holding the array [3] and the number 4. Four items come out: 1, 2, the array [3], and 4. The empty array emits nothing.in12[3]4std:unbatchout12[3]4

Three array items go in: an array of 1 and 2, an empty array, and an array holding the array [3] and the number 4. Four items come out: 1, 2, the array [3], and 4. The empty array emits nothing.

Drawn from a real run of the reference implementation.

One level, in order #

Every element of every array item becomes an item of its own, in order. Only one level is flattened: in the drawing the inner array [3] comes out as it is. An empty array emits nothing, and an item that is not a JSON array fails the run.

std:unbatch is the inverse of std:batch, and it is just as useful after any pipe that answers with one array per call. It works on plain arrays only: the frames of a windows stream are objects, not arrays, and a windows output does not connect to this pipe's records input.

A tested example #

Nothing here is invented: this is the test “flattens one level” 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],4]
Expected output: out
1
2
[3]
4

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

pipeline.yaml
nodes:
  unbatch:
    pipe: std:unbatch
    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],4]' | openflange run std:unbatch
Standard output (out)
1
2
[3]
4

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

Emits every element of every input array as its own item, in order. Elements are copied as raw bytes (nested values and number literals are preserved). An empty array contributes nothing. An item that is not an array fails the run with E_RUNTIME. Only one level is flattened. Inverse of std:batch.

Reference #

Maturity
Experimental
Processing scope
record
Manifest version
0.1.0