Ports #
| Port | Direction | Kind | Required | Description |
|---|---|---|---|---|
in | input | records | yes | |
out | output | records | yes |
Parameters #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
fields | array | none | no | Member names forming the key. Default is the whole item. |
maxKeys | integer | 1000000 | no | 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
fieldsthe whole record is the key; keys are compared as JSON values, so1and1.0are 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 withE_RESOURCE.
How it works #
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.
This test sets no parameters.
"a"
"b"
"a"
"c"
"b""a"
"b"
"c"The same step as a node of a 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.
printf '%s\n' '"a"' '"b"' '"a"' '"c"' '"b"' | openflange run std:distinct"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
- Normative definition: std:distinct in the standard library specification
- Manifest and tests: std/0.1/distinct in the specification repository