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

Keeps the first item for every distinct key; bounded by maxKeys.

For example: remove duplicate webhook deliveries.

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

Ports #

std:distinct takes in and produces out.std:distinctinrecordsoutrecords
std:distinct takes in and produces out.std:distinctinrecordsoutrecords
Named ports from the latest published contract. Dashed lines are optional ports.
Ports of std:distinct
PortDirectionKindRequiredDescription
ininputrecordsyes
outoutputrecordsyes

Parameters #

Parameters of std:distinct
NameTypeDefaultRequiredDescription
fieldsarraynonenoMember names forming the key. Default is the whole item.
maxKeysinteger1000000no Minimum 1.

When to use it #

  • The same event was delivered twice: keep the first record for every id (fields: [id]).
  • Two exports overlap: merge them and keep each record once.
  • Without fields the whole record is the key; keys are compared as JSON values, so 1 and 1.0 are the same key and member order does not matter.

When to use something else

  • It remembers one key per distinct value and never forgets keys silently: with more distinct keys than maxKeys (default 1,000,000) the run fails with E_RESOURCE.

How it works #

std:distinct keeps the first of every repeated itemThe items a, b, a, c, b go in. The second a and the second b, drawn dashed, are consumed; a, b and c come out.inabacbstd:distinctoutabcstd:distinct keeps the first of every repeated itemThe items a, b, a, c, b go in. The second a and the second b, drawn dashed, are consumed; a, b and c come out.inabacbstd:distinctoutabc

The items a, b, a, c, b go in. The second a and the second b, drawn dashed, are consumed; a, b and c come out.

Drawn from a real run of the reference implementation.

A tested example #

Nothing here is invented: this is the test “first occurrence wins” from the pipe's own portable test file, which every conformant runner must pass.

Parameters

This test sets no parameters.

Input: in
"a"
"b"
"a"
"c"
"b"
Expected output: out
"a"
"b"
"c"

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

pipeline.yaml
nodes:
  distinct:
    pipe: std:distinct
    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' '"a"' '"b"' '"a"' '"c"' '"b"' | openflange run std:distinct
Standard output (out)
"a"
"b"
"c"

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

Passes an item only the first time its key is seen; later items with the same key are consumed (that is this pipe's purpose, not a silent drop). Passed items are not re-encoded.

The key is the whole item, or — with fields — the tuple of those top-level members (an absent member is distinct from a null member). Keys are compared as JSON values: objects are equal regardless of member order, numbers are equal when they are mathematically equal (1, 1.0 and 10e-1 are one key; the comparison is exact, not floating point), strings are compared by code point without Unicode normalisation.

Bounded state. The pipe remembers at most maxKeys keys (keys longer than 32 bytes are kept as SHA-256 digests). One key more fails the run with E_RESOURCE; keys are never evicted. With fields, a non-object item fails with E_RUNTIME.

Reference #

Maturity
Experimental
Processing scope
record
Manifest version
0.1.0