Different pipes. One standard.

Начните вводить запрос.

Поиск работает прямо в браузере по статическому индексу, собранному вместе с сайтом (Pagefind). Ваш запрос никуда не отправляется.

Стандартная библиотека

Описывает переносимые строительные блоки, которые любой раннер может предоставлять под префиксом std:, — filter, map, merge, window, преобразование CSV и JSON, источники и приёмники данных. У каждого блока фиксированные порты и параметры, поэтому пайплайн, который их использует, ведёт себя одинаково в любом раннере.

Коротко

Идентификатор
openflange.org/std/v0.1 — открывается по адресу https://openflange.org/std/v0.1/
Статус
Экспериментально
Версия
v0.1 (документ 0.1.0-draft), последняя · все версии
Обновлено
Схемы
Связанные
Пайплайн · Пайп
Форматы
HTML (эта страница) · Открыть в формате Markdown (на английском) · лицензия CC BY 4.0

Ищете готовый пайп? В каталоге стандартной библиотеки на openflange.dev перечислены все стандартные пайпы: порты, параметры и разобранный пример из тестов соответствия. Эта страница — нормативный текст.

Нормативным является английский текст

Ниже приведена спецификация «OpenFlange Standard Library» на языке оригинала — английском. Нормативную силу имеет только английский текст; краткое описание и подписи на этой странице носят справочный характер.

This specification defines the OpenFlange standard library: a versioned set of portable pipes, referenced as std:<name>, for mapping, filtering, routing, merging, batching, windowing, format conversion and basic input and output. For each standard pipe it gives the exact contract as a pipe manifest and the semantics every runner must implement.

This document is published at https://openflange.org/std/v0.1. Its identifier, openflange.org/std/v0.1, is that URL without the scheme, and is the value documents of this kind carry in spec:.

At a glance #

Minimal example #

A standalone pipeline that uses one standard pipe:

yaml
spec: openflange.org/pipeline/v0.1
nodes:
  adults:
    pipe: std:filter@0.1
    inputs:
      in: {from: inputs.people}
    parameters:
      expr: 'item["age"] >= 18'
outputs:
  adults: {from: adults.outputs.out}

Input {"name":"a","age":17} and {"name":"b","age":30} produces {"name":"b","age":30}.

1. Introduction #

The standard library is a small, versioned set of portable pipes addressed with the std: reference scheme. A pipeline that uses only std: pipes and portable local pipes behaves identically on every conformant runner. The library is deliberately boring: it contains the plumbing every pipeline needs (projection, filtering, routing, merging, batching, windowing, a few format conversions, and basic sources and sinks) and nothing domain specific.

This document defines, for every standard pipe, its contract (as a pipe manifest, see the Pipe specification) and its semantics. It is one of the OpenFlange v0.1 specifications; the Pipeline specification defines the stream and execution model that the semantics below rely on.

1.1 Conventions #

The key words MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD, SHOULD NOT, RECOMMENDED, MAY and OPTIONAL are to be interpreted as described in RFC 2119 and RFC 8174 when, and only when, they appear in capitals.

Every fenced block in this document whose info string contains openflange:<kind> is a normative example that is machine-checked against the schemas in schemas/.

1.2 Citing this document #

Normative statements are cited by section number, for example std/v0.1 §4.2, and numbered or bulleted rules within a section by their position, for example std/v0.1 §4.2(3). Section numbers are stable within v0.1: sections are appended, never renumbered. Every heading has a stable fragment identifier derived from its text (lower-cased; characters other than letters, digits, spaces, hyphens and underscores removed; spaces replaced by hyphens), so a section is addressable as https://openflange.org/std/v0.1#<fragment>. Cross-references to other OpenFlange specifications are absolute URLs of that form. This document does not rely on images; its diagrams are text.

1.3 Terminology #

The terms pipe, source, sink, pipeline, subpipeline, node, port, stream, run and dataset are used as defined in the Pipe specification, section 2. The term workflow is reserved and is not used by this specification.

Additional terms:

  • standard pipe — a pipe defined by this document and referenced as std:<name>.
  • item — one element of a records or values stream (one NDJSON line).
  • expression parameter — a parameter of type string holding a Starlark expression, evaluated per item by the runner (section 3).

1.4 Feature maturity #

Feature Maturity
std: reference scheme and versioning (section 2) experimental
Record pipes: map, select, rename, cast, filter, limit, skip, distinct experimental
Routing pipes: split, partition, merge experimental
batch, unbatch experimental
window (record-count windows; relies on window framing) proposed
window-processing-time proposed (draft; semantics may change entirely)
json-parse, json-format, csv-decode, csv-encode experimental
ndjson-to-arrow, arrow-to-ndjson (optional capability arrow) experimental
validate-schema experimental
Sources stdin, file-source, http-source; sinks stdout, file-sink, discard experimental
Capability advertisement (section 2.3) experimental

No feature of this specification is stable or deprecated in v0.1.

2. Referencing and versioning #

2.1 References #

A standard pipe is referenced as std:<name> or std:<name>@<range>, where <range> is a SemVer range over the standard library version (not over an individual pipe). std:filter@0.1 selects the filter pipe of any 0.1.x standard library. A reference without a range selects the newest standard library version the runner implements.

std: references are distinct from builtin:<runtime>/<name> references, which name runtime-specific pipes (for example builtin:datatug/query). builtin: pipes are outside the scope of this specification and are not portable. A runner MUST NOT expose a non-standard pipe under the std: scheme, and MUST NOT change the behaviour of a standard pipe under its standard name.

std and builtin are reserved node identifiers in pipelines so that references and node names can never be confused.

2.2 Manifests #

Every standard pipe has an OPENFLANGE.md manifest. The manifest frontmatter is given normatively in section 5 of this document; the canonical files are distributed in the specification repository under std/0.1/<name>/OPENFLANGE.md together with their portable tests. Each manifest's id is the pipe name, its version is the standard library version, and its implementation is {type: builtin, name: "std:<name>"}.

A runner implements standard pipes natively; it MUST honour the contract in the manifest (ports, kinds, parameters, defaults, bounds). Standard pipes execute in-process and need no permission grants, with the exception of the I/O pipes described in section 5.7.

In a lockfile, a std: reference is recorded like any other reference (see the Lockfile specification); its resolved value is std:<name>@<exact version> and its integrity is computed over the canonical manifest.

2.3 Capabilities #

Not every runner implements every standard pipe. A runner:

  • MUST be able to report, before execution, the standard library version(s) and the set of standard pipes it implements, and the optional capabilities it supports. The reference CLI exposes this as openflange version --capabilities.
  • MUST reject, at validation time, a pipeline that references a standard pipe it does not implement, with E_UNSUPPORTED. It MUST NOT substitute a different behaviour.
  • MUST reject a standard pipe whose manifest requires a feature the runner does not implement, with E_UNSUPPORTED.

The optional capabilities defined by v0.1 are the feature identifiers of the Pipe specification: windows, processing-time-windows, arrow, variadic and batch. The standard pipes that need one of the first four declare it in requires; no standard pipe can use batch (5.4). A runner reports batch together with the implementation types for which it supports batch mode.

A runner that claims conformance to openflange.org/std/v0.1 MUST implement every experimental pipe of section 5 except those that require the arrow capability, and SHOULD implement std:window.

3. Expression parameters #

Several standard pipes take a Starlark expression (expr, key, partitionBy). These expressions are evaluated with the Starlark binding of the Pipe specification, section 9, with exactly two predeclared names:

  • item — the current item, converted from JSON;
  • params — the node's resolved parameters as a dict.

Expressions MUST be free of side effects; a runner MUST NOT provide emit, I/O, or mutable shared state to them. An expression that raises an error, or that does not compile, fails the node: a compile error is reported at validation time as E_PARAM; an evaluation error fails the run with E_RUNTIME.

Where a boolean is expected (std:filter, std:split), the result is interpreted using Starlark truthiness (bool(result)).

4. Common behaviour #

Unless a pipe's section says otherwise:

  1. Ports. The pipe has one required input in and one required output out, both of kind records and untyped. records and values streams are both accepted (they are mutually compatible kinds).
  2. Scope. Processing scope is record: bounded memory independent of the stream length.
  3. Order. Output order follows input order.
  4. Pass-through fidelity. An item, or a member of an item, that the pipe does not modify MUST be emitted with every JSON number preserved exactly: the same literal, byte for byte (1.50 stays 1.50, 1E3 stays 1E3). Object member order MUST be preserved. A standard pipe MUST NOT round a number through a binary floating-point representation unless its semantics require arithmetic on that number.
  5. Empty input. An empty input stream is valid and produces an empty output stream (exception: csv-encode with explicit fields, 5.6).
  6. Errors. A failure described as "fails" below fails the node and, per the execution model, the run, with code E_RUNTIME unless another code is named. Nothing is dropped silently: an item leaves a standard pipe on an output, or the documented semantics say it is consumed (for example by limit), or the run fails.
  7. Optional outputs. Where a pipe has an optional output (for example rejected), the behaviour when it is not connected is stated explicitly.
  8. Parameters are validated at compile time; a value outside the declared type or bounds is E_PARAM.

5. The standard pipes #

5.1 Record transformations #

std:map #

Evaluates expr for each item and emits the result. Exactly one item is emitted per input item; a None result is emitted as JSON null. A result that cannot be represented as JSON (for example a non-finite float or a function) fails.

yaml
spec: openflange.org/pipe/v0.1
id: map
version: 0.1.0
title: Map
description: Emits the value of a Starlark expression for every item.
license: Apache-2.0
maturity: experimental
scope: record
cardinality: one-to-one
deterministic: true
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
parameters:
  expr: {type: string, required: true, description: Starlark expression over `item` and `params`.}
implementation: {type: builtin, name: "std:map"}

std:select #

Emits, for each object item, an object containing only the members named in fields, in the order given by fields. A named member that is absent from the item is omitted (it is not emitted as null). An item that is not a JSON object fails. fields MUST NOT contain duplicates (E_PARAM).

yaml
spec: openflange.org/pipe/v0.1
id: select
version: 0.1.0
title: Select fields
description: Keeps only the listed members of each record.
license: Apache-2.0
maturity: experimental
scope: record
cardinality: one-to-one
deterministic: true
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
parameters:
  fields: {type: array, required: true, description: "Member names to keep, in output order."}
implementation: {type: builtin, name: "std:select"}

std:rename #

Renames members of each object item according to mapping ({old: new}). Renamed members keep their position; other members are untouched. A missing old member is not an error. If a rename would produce a name that already exists in the item (and is not itself being renamed away), the item fails — the pipe never overwrites data. An item that is not a JSON object fails.

yaml
spec: openflange.org/pipe/v0.1
id: rename
version: 0.1.0
title: Rename fields
description: Renames members of each record.
license: Apache-2.0
maturity: experimental
scope: record
cardinality: one-to-one
deterministic: true
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
parameters:
  mapping: {type: object, required: true, description: "Map of old member name to new member name."}
implementation: {type: builtin, name: "std:rename"}

std:cast #

Converts the listed members of each object item to the given JSON type. fields maps member names to one of string, integer, number, boolean. Members not listed are untouched; a listed member that is absent or null is left as is.

Conversion rules (anything not listed is un-castable):

target accepted source values result
string string; number; boolean the string; the number's literal; "true"/"false"
integer integer number; number with a zero fractional part (3.0); string matching [-+]?[0-9]+ the integer, exactly (arbitrary precision)
number number; string that is a JSON number literal (an optional leading + is not accepted) the number, exactly
boolean boolean; the strings "true" and "false" the boolean

Surrounding whitespace in strings is not trimmed. Conversions MUST be exact: "12345678901234567890123" cast to integer yields that integer, not a rounded value.

When an item has at least one un-castable member:

  • with onError: fail (the default) the run fails;
  • with onError: reject, the whole original item is emitted on the optional output rejected, wrapped as {"item": <original>, "errors": [{"field": <name>, "message": <text>}, ...]}, and nothing is emitted on out for it. If rejected is not connected, the run fails as with onError: fail.

The message texts are informative and not portable.

yaml
spec: openflange.org/pipe/v0.1
id: cast
version: 0.1.0
title: Cast fields
description: Converts members of each record to a JSON type, exactly or not at all.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
  rejected: {kind: records, required: false, description: "Items with un-castable members, wrapped as {item, errors}."}
parameters:
  fields: {type: object, required: true, description: "Map of member name to string|integer|number|boolean."}
  onError: {type: string, enum: [fail, reject], default: fail}
implementation: {type: builtin, name: "std:cast"}

5.2 Filtering and counting #

std:filter #

Evaluates expr for each item. Items for which it is truthy are emitted unchanged on out. Other items are emitted unchanged on the optional output rejected if it is connected, and are otherwise consumed (dropping non-matching items is the purpose of a filter, so this is not a silent drop).

yaml
spec: openflange.org/pipe/v0.1
id: filter
version: 0.1.0
title: Filter
description: Keeps the items for which a Starlark expression is truthy.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
  rejected: {kind: records, required: false, description: Items for which the expression is falsy.}
parameters:
  expr: {type: string, required: true, description: Starlark expression over `item` and `params`.}
implementation: {type: builtin, name: "std:filter"}

std:limit #

Emits the first count items and then completes its output. Remaining input is consumed and discarded; a runner MAY instead stop upstream producers that have no other consumer. In either case the node and the run complete normally (completed, not cancelled), and the observable output is the same. count: 0 yields an empty output.

yaml
spec: openflange.org/pipe/v0.1
id: limit
version: 0.1.0
title: Limit
description: Emits at most the first `count` items.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
parameters:
  count: {type: integer, required: true, minimum: 0}
implementation: {type: builtin, name: "std:limit"}

std:skip #

Discards the first count items and emits the rest unchanged.

yaml
spec: openflange.org/pipe/v0.1
id: skip
version: 0.1.0
title: Skip
description: Discards the first `count` items.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
parameters:
  count: {type: integer, required: true, minimum: 0}
implementation: {type: builtin, name: "std:skip"}

std:distinct #

Emits an item the first time its key is seen and consumes later items with the same key. Without fields the key is the whole item; with fields the key is the tuple of the named members (an absent member is distinct from a null member; an item that is not an object fails when fields is given).

Key equality is JSON value equality: objects are equal regardless of member order; numbers are equal when they are mathematically equal (1 and 1.0 are the same key); strings are compared by code point without normalisation.

The pipe holds one key per distinct value. When the number of distinct keys would exceed maxKeys, the run fails with E_RESOURCE; the pipe never evicts keys silently.

yaml
spec: openflange.org/pipe/v0.1
id: distinct
version: 0.1.0
title: Distinct
description: Keeps the first item for every distinct key; bounded by maxKeys.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: records}
parameters:
  fields: {type: array, description: Member names forming the key. Default is the whole item.}
  maxKeys: {type: integer, default: 1000000, minimum: 1}
implementation: {type: builtin, name: "std:distinct"}

5.3 Routing #

std:split #

Evaluates the boolean expression expr for each item and emits the item unchanged on matched when it is truthy and on unmatched otherwise. Both outputs are required: each needs a consumer or an explicit discard: true. Relative order is preserved on each output.

A general N-way split driven by an expression returning an output name is not part of v0.1 (ports are static in v0.1); use std:partition or chained splits.

yaml
spec: openflange.org/pipe/v0.1
id: split
version: 0.1.0
title: Split
description: Routes each item to `matched` or `unmatched` by a boolean expression.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  matched: {kind: records}
  unmatched: {kind: records}
parameters:
  expr: {type: string, required: true, description: Starlark expression over `item` and `params`.}
implementation: {type: builtin, name: "std:split"}

std:partition #

Routes each item to one of partitions outputs (p0 … p{n-1}) chosen from the value of the key expression. All items with equal keys (JSON value equality as for std:distinct) go to the same output within a run, and relative order is preserved on each output.

The assignment function is implementation-defined in v0.1, with one exception: when the key is a non-negative integer k, the item MUST be routed to p{k mod n}. Portable pipelines that need a deterministic layout SHOULD therefore compute an integer key.

The outputs p0…p7 are optional ports. Every output p{i} with i < partitions MUST be connected or explicitly discarded (E_UNCONNECTED otherwise, because items routed there would be lost); an output with i ≥ partitions MUST NOT be connected (E_PARAM).

yaml
spec: openflange.org/pipe/v0.1
id: partition
version: 0.1.0
title: Partition
description: Routes items to one of up to eight outputs by key.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  p0: {kind: records, required: false}
  p1: {kind: records, required: false}
  p2: {kind: records, required: false}
  p3: {kind: records, required: false}
  p4: {kind: records, required: false}
  p5: {kind: records, required: false}
  p6: {kind: records, required: false}
  p7: {kind: records, required: false}
parameters:
  key: {type: string, required: true, description: Starlark expression over `item` and `params`.}
  partitions: {type: integer, required: true, minimum: 1, maximum: 8}
implementation: {type: builtin, name: "std:partition"}

std:merge #

Merges several streams into one. in is a variadic input: the consumer lists its producers, {from: [a.outputs.out, b.outputs.out]}. std:merge is the only way to feed one logical input from several producers; a pipeline that maps several producers to a non-variadic input is invalid.

  • mode: interleave (default): items are forwarded as they arrive. The relative order of the items of each individual input is preserved; the interleaving between inputs is unspecified and MAY differ between runs. Every input is read concurrently, so a slow input never blocks the others.
  • mode: concat: the inputs are forwarded completely, one after another, in the order in which they are listed in from. The output is deterministic. Inputs later in the list are not read until the earlier ones have completed, so their producers are back-pressured; this is bounded by the ordinary stream buffers and cannot deadlock a DAG on its own, but a pipeline in which one producer broadcasts to both a concat merge input and, through a blocking path, to an earlier input of the same merge can stall. A runner MUST detect that every node is blocked and fail the run with E_RESOURCE rather than hang.

A producer that is a disconnected optional pipeline input contributes no items.

yaml
spec: openflange.org/pipe/v0.1
id: merge
version: 0.1.0
title: Merge
description: Merges several streams into one, interleaved or concatenated.
license: Apache-2.0
maturity: experimental
scope: record
requires: [variadic]
inputs:
  in: {kind: records, variadic: true}
outputs:
  out: {kind: records}
parameters:
  mode: {type: string, enum: [interleave, concat], default: interleave}
implementation: {type: builtin, name: "std:merge"}

5.4 Batching #

Batching here is a data transformation: it turns items into JSON arrays and back. It is unrelated to the transport batches a runner uses internally between nodes (which are invisible), to Arrow record batches, and to windows (5.5): a batch carries no semantic boundary.

It is also unrelated to batch mode (Pipe specification, section 5.7), in which a pipe declares that its implementation receives its input in slices. With batch mode the stream between nodes still carries single items and the slicing is a private matter between the runner and one pipe; with std:batch the arrays are the items, visible to every downstream pipe, exactly size long and with no time limit. No standard pipe declares batch mode — standard pipes are builtin implementations, which cannot declare it: they are native to their runner and gain nothing from it — and std:batch and std:unbatch behave as before. Prefer batch mode when a pipe wants to make one call for many items; use std:batch when the arrays themselves are the data.

std:batch #

Collects consecutive items into JSON arrays of exactly size items and emits each array as one item. At end of input a final shorter array is emitted if at least one item is pending; an empty array is never emitted.

yaml
spec: openflange.org/pipe/v0.1
id: batch
version: 0.1.0
title: Batch
description: Groups consecutive items into JSON arrays of `size` items.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: records, description: One JSON array per item.}
parameters:
  size: {type: integer, required: true, minimum: 1, maximum: 1000000}
implementation: {type: builtin, name: "std:batch"}

std:unbatch #

Emits each element of each array item as a separate item, in order. An empty array emits nothing. An item that is not a JSON array fails.

yaml
spec: openflange.org/pipe/v0.1
id: unbatch
version: 0.1.0
title: Unbatch
description: Flattens array items into their elements.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records, description: One JSON array per item.}
outputs:
  out: {kind: records}
implementation: {type: builtin, name: "std:unbatch"}

5.5 Windows #

Windowing in OpenFlange is done by ordinary pipes with a window-aware contract, not by hidden per-node behaviour. A window pipe consumes a plain stream and emits a windows stream in which every line is one complete window frame (see the Pipeline specification, section 9); window-scope pipes (for example an R summary) consume that stream.

Windows are logical groups with semantic boundaries. They are distinct from transport batches, from std:batch arrays and from SQL analytical window functions, which are a feature of SQL engines and out of scope here.

std:window (proposed) #

Record-count windows: tumbling, sliding and partitioned.

Parameters. size is the number of items per window. step is the distance between the starts of consecutive windows; it defaults to size (tumbling windows) and MUST satisfy 1 ≤ step ≤ size (E_PARAM otherwise; step < size gives overlapping, sliding windows). partitionBy is an optional expression parameter; when present, windows are formed independently for each distinct value of the expression.

Partitions and ordinals. Without partitionBy there is one partition whose value is null. With it, the partition of an item is the JSON value of the expression (equality as for std:distinct). Within a partition, items are numbered with ordinals 0, 1, 2, … in arrival order.

Window membership. Window k (k = 0, 1, 2, …) of a partition covers the ordinals k·step to k·step + size − 1 of that partition. With step < size an item belongs to several windows — that is the documented overlap.

Emission. A window is emitted as one frame as soon as its last item has arrived, with partial: false and final: false. Frames of different partitions therefore appear in the order in which their windows fill. In the frame, index is k, partition is the partition value, start and end are the partition ordinals of the first and last item contained in the frame, and items holds the items in order.

End of stream. When the input completes, every window that has started (it contains at least one item) but has not filled is handled according to emitPartial:

  • emitPartial: true (default): each such window is emitted with the items it has, partial: true and final: true. Partitions are flushed in order of first appearance, and within a partition windows are flushed in increasing index.
  • emitPartial: false: such windows are discarded. This is a documented consumption, not a silent drop.

Empty windows are never emitted. The end of the window stream is the stream EOF; there is no end marker frame.

Bounded state. The pipe buffers at most size items per partition and holds state for at most maxPartitions partitions. A new partition beyond that bound fails the run with E_RESOURCE; partitions are never evicted silently.

Example — size: 3, step: 1, input "a" "b" "c" "d":

ndjson
{"window":{"index":0,"partition":null,"start":0,"end":2,"final":false,"partial":false},"items":["a","b","c"]}
{"window":{"index":1,"partition":null,"start":1,"end":3,"final":false,"partial":false},"items":["b","c","d"]}
{"window":{"index":2,"partition":null,"start":2,"end":3,"final":true,"partial":true},"items":["c","d"]}
{"window":{"index":3,"partition":null,"start":3,"end":3,"final":true,"partial":true},"items":["d"]}

Example — size: 2 (tumbling), partitionBy: 'item["k"]', input {"k":"x","v":1} {"k":"y","v":2} {"k":"x","v":3} {"k":"y","v":4} {"k":"x","v":5}:

ndjson
{"window":{"index":0,"partition":"x","start":0,"end":1,"final":false,"partial":false},"items":[{"k":"x","v":1},{"k":"x","v":3}]}
{"window":{"index":0,"partition":"y","start":0,"end":1,"final":false,"partial":false},"items":[{"k":"y","v":2},{"k":"y","v":4}]}
{"window":{"index":1,"partition":"x","start":2,"end":2,"final":true,"partial":true},"items":[{"k":"x","v":5}]}
yaml
spec: openflange.org/pipe/v0.1
id: window
version: 0.1.0
title: Window
description: Record-count tumbling, sliding and partitioned windows.
license: Apache-2.0
maturity: proposed
scope: record
requires: [windows]
inputs:
  in: {kind: records}
outputs:
  out: {kind: windows}
parameters:
  size: {type: integer, required: true, minimum: 1, maximum: 1000000}
  step: {type: integer, minimum: 1, maximum: 1000000, description: "Default: size (tumbling). Must not exceed size."}
  partitionBy: {type: string, description: Starlark expression over `item` and `params`.}
  emitPartial: {type: boolean, default: true}
  maxPartitions: {type: integer, default: 10000, minimum: 1}
implementation: {type: builtin, name: "std:window"}

std:window-processing-time (proposed, draft) #

Groups items by the wall-clock time at which the runner receives them: a window closes durationMs milliseconds after its first item arrived, or at end of stream. This pipe is a draft. It is inherently non-deterministic, its results are not reproducible, and its contract may change or be removed without a deprecation period. It exists so that the framing can be exercised with time-driven boundaries.

Draft semantics: there is a single partition (null); index counts emitted windows from 0; start and end are stream ordinals of the first and last contained item; a window closed by the timer has partial: false and final: false; the window flushed at end of stream has partial: true and final: true. No frame is emitted for an interval in which no item arrived. The buffered items of an open window are bounded by maxItems; reaching the bound closes the window early (partial: false).

Event-time windows, watermarks, allowed lateness and session windows are deferred (section 8).

yaml
spec: openflange.org/pipe/v0.1
id: window-processing-time
version: 0.1.0
title: Processing-time window (draft)
description: Draft. Groups items by arrival time. Non-deterministic.
license: Apache-2.0
maturity: proposed
scope: record
requires: [windows, processing-time-windows]
inputs:
  in: {kind: records}
outputs:
  out: {kind: windows}
parameters:
  durationMs: {type: integer, required: true, minimum: 1}
  maxItems: {type: integer, default: 100000, minimum: 1}
implementation: {type: builtin, name: "std:window-processing-time"}

5.6 Format conversion #

Conversions that can lose information are never inserted automatically by a planner; they are explicit nodes, and these are the pipes for them.

std:json-parse #

Input in is a text stream containing NDJSON. Output out carries one item per line. The framing rules of NDJSON apply (UTF-8, no byte order mark, no blank lines, a missing final newline is tolerated); a violation or a line that is not valid JSON fails the run with E_FORMAT. Number literals are preserved.

yaml
spec: openflange.org/pipe/v0.1
id: json-parse
version: 0.1.0
title: JSON parse
description: Parses NDJSON text into items.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: text}
outputs:
  out: {kind: records}
implementation: {type: builtin, name: "std:json-parse"}

std:json-format #

The inverse of json-parse: emits each item as one compact JSON line terminated by \n on the text output.

yaml
spec: openflange.org/pipe/v0.1
id: json-format
version: 0.1.0
title: JSON format
description: Serialises items as NDJSON text.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: text}
implementation: {type: builtin, name: "std:json-format"}

std:csv-decode #

Parses CSV text (RFC 4180 quoting; delimiter is a single character, default ,; rows end with LF or CRLF; a leading UTF-8 byte order mark is accepted and discarded) into records.

  • header: true (default): the first row names the members; each further row becomes an object with those members in header order. Duplicate or empty header names fail with E_FORMAT.
  • header: false with fields: fields names the members.
  • header: false without fields: each row becomes a JSON array of strings.

Every value is emitted as a JSON string, exactly as it appears after unquoting; the decoder performs no type inference (use std:cast). An unquoted empty field is the empty string. A row whose number of fields differs from the header (or from fields) fails with E_FORMAT. A final row without a line terminator is accepted. Empty input, or input consisting only of a header row, produces no records.

yaml
spec: openflange.org/pipe/v0.1
id: csv-decode
version: 0.1.0
title: CSV decode
description: Parses CSV text into records of strings.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: text, mediaTypes: [text/csv, "text/plain; charset=utf-8"]}
outputs:
  out: {kind: records}
parameters:
  header: {type: boolean, default: true}
  delimiter: {type: string, default: ","}
  fields: {type: array, description: Member names when header is false.}
implementation: {type: builtin, name: "std:csv-decode"}

std:csv-encode #

Serialises object items as CSV text. The columns are fields if given, otherwise the member names of the first item in their order. With header: true (default) a header row is written first.

  • Rows are terminated by LF (\n), including the last one.
  • A string is written as is, and quoted with " (embedded quotes doubled) only if it contains the delimiter, a quote, CR or LF.
  • A number is written as its literal; true/false as those words; null and absent members as an empty field.
  • A member whose value is an array or an object fails the run (CSV cannot represent it losslessly; convert it first).
  • When the columns were taken from the first item, a later item with a member that is not a column fails the run. When fields is given, other members are ignored (an explicit projection).
  • An item that is not an object fails.
  • With an empty input: if fields is given and header is true, only the header row is written; otherwise the output is empty.

CSV encoding is lossy with respect to types (everything becomes text, null and "" coincide), which is why it is always explicit.

yaml
spec: openflange.org/pipe/v0.1
id: csv-encode
version: 0.1.0
title: CSV encode
description: Serialises records as CSV text.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  out: {kind: text, mediaTypes: [text/csv, "text/plain; charset=utf-8"]}
parameters:
  header: {type: boolean, default: true}
  delimiter: {type: string, default: ","}
  fields: {type: array, description: Column names. Default is the first record's member names.}
implementation: {type: builtin, name: "std:csv-encode"}

std:ndjson-to-arrow and std:arrow-to-ndjson (capability arrow) #

Explicit conversions between item streams and Arrow IPC streams (application/vnd.apache.arrow.stream). They are available only on runners that advertise the arrow capability.

ndjson-to-arrow requires the target schema in the Arrow JSON form of the Pipe specification ({fields: [{name, type, nullable}]}); it never infers a schema. Both pipes MUST refuse, with E_FORMAT, any value they cannot preserve exactly: an integer outside the range of its column type, a decimal that does not fit the declared precision and scale, a null in a non-nullable column, a member not described by the schema, a timestamp that is not an RFC 3339 string with the column's unit and zone, binary data that is not valid base64 (binary columns are represented in JSON as base64 strings). arrow-to-ndjson writes decimal128 and 64-bit integers as JSON number literals with full precision, timestamps as RFC 3339 strings, date32 as YYYY-MM-DD strings and binary as base64 strings.

yaml
spec: openflange.org/pipe/v0.1
id: ndjson-to-arrow
version: 0.1.0
title: NDJSON to Arrow
description: Converts records to Arrow record batches, refusing lossy values.
license: Apache-2.0
maturity: experimental
scope: record
requires: [arrow]
inputs:
  in: {kind: records}
outputs:
  out: {kind: batches}
parameters:
  schema: {type: object, required: true, description: "Arrow schema: {fields: [{name, type, nullable}]}."}
  batchSize: {type: integer, default: 1024, minimum: 1, maximum: 1000000}
implementation: {type: builtin, name: "std:ndjson-to-arrow"}
yaml
spec: openflange.org/pipe/v0.1
id: arrow-to-ndjson
version: 0.1.0
title: Arrow to NDJSON
description: Converts Arrow record batches to records, refusing lossy values.
license: Apache-2.0
maturity: experimental
scope: record
requires: [arrow]
inputs:
  in: {kind: batches}
outputs:
  out: {kind: records}
implementation: {type: builtin, name: "std:arrow-to-ndjson"}

std:validate-schema #

Validates each item against the JSON Schema (dialect 2020-12) given in schema. Valid items are emitted unchanged on valid. An invalid item is emitted on the optional output rejected, wrapped as {"item": <original>, "errors": [{"path": <JSON Pointer>, "message": <text>}, ...]}. If rejected is not connected, the first invalid item fails the run — invalid data is never dropped silently. A schema that is not a valid JSON Schema is E_PARAM. format keywords are annotations and MUST NOT cause rejection in v0.1.

yaml
spec: openflange.org/pipe/v0.1
id: validate-schema
version: 0.1.0
title: Validate schema
description: Routes items by validity against a JSON Schema.
license: Apache-2.0
maturity: experimental
scope: record
inputs:
  in: {kind: records}
outputs:
  valid: {kind: records}
  rejected: {kind: records, required: false, description: "Invalid items wrapped as {item, errors}."}
parameters:
  schema: {type: object, required: true, description: JSON Schema 2020-12 for one item.}
implementation: {type: builtin, name: "std:validate-schema"}

5.7 Sources and sinks #

The I/O pipes touch the outside world and therefore need grants. Their required permissions depend on their parameters, which a static manifest cannot express; the following dynamic permission requirements are normative, and a runner MUST enforce them exactly as if they were declared in the manifest (refusing with E_PERMISSION when not granted):

pipe required permission
std:file-source filesystem.read covering path
std:file-sink filesystem.write covering path
std:http-source network for the host:port of url
std:stdin, std:stdout, std:discard none

A granted filesystem path covers the path itself and, if it is a directory, everything beneath it, after both are made absolute and symbolic links are resolved. Relative path parameters resolve against the directory of the pipeline file that contains the node. The parameters that determine these permissions MUST be literals or $param bindings resolved before execution; the requirement is computed from the resolved value.

All sources emit records on out (NDJSON framing); all sinks consume records on in. To read other formats, read the file as a pipeline input of kind text and convert explicitly.

std:stdin, std:stdout #

std:stdin emits the runner process's standard input, parsed as NDJSON. std:stdout writes its input to the runner's standard output as NDJSON. A pipeline MUST NOT contain more than one std:stdin node or more than one std:stdout node (E_DUPLICATE), and a runner MUST refuse (E_UNSUPPORTED) to run them where the standard streams are already bound (for example when openflange run binds a pipeline input to stdin, or when serving over HTTP).

yaml
spec: openflange.org/pipe/v0.1
id: stdin
version: 0.1.0
title: Standard input
description: "Source: the runner's standard input as NDJSON."
license: Apache-2.0
maturity: experimental
outputs:
  out: {kind: records}
implementation: {type: builtin, name: "std:stdin"}
yaml
spec: openflange.org/pipe/v0.1
id: stdout
version: 0.1.0
title: Standard output
description: "Sink: the runner's standard output as NDJSON."
license: Apache-2.0
maturity: experimental
inputs:
  in: {kind: records}
implementation: {type: builtin, name: "std:stdout"}

std:file-source, std:file-sink #

std:file-source reads the NDJSON file at path. std:file-sink writes its input to path as NDJSON, creating the file or replacing its previous content; with append: true it appends instead. A sink does not create parent directories. Because output is not transactional, a failed run can leave a partially written file; the run report says so (partialOutput).

yaml
spec: openflange.org/pipe/v0.1
id: file-source
version: 0.1.0
title: File source
description: "Source: an NDJSON file. Needs a filesystem.read grant covering `path`."
license: Apache-2.0
maturity: experimental
outputs:
  out: {kind: records}
parameters:
  path: {type: string, required: true}
implementation: {type: builtin, name: "std:file-source"}
yaml
spec: openflange.org/pipe/v0.1
id: file-sink
version: 0.1.0
title: File sink
description: "Sink: an NDJSON file. Needs a filesystem.write grant covering `path`."
license: Apache-2.0
maturity: experimental
inputs:
  in: {kind: records}
parameters:
  path: {type: string, required: true}
  append: {type: boolean, default: false}
implementation: {type: builtin, name: "std:file-sink"}

std:http-source #

Performs one HTTP GET on url and emits the NDJSON response body. The request is subject to the fetch rules of the Pipeline specification, section 12: HTTPS only (plain HTTP is allowed for loopback addresses), bounded time, redirects are not followed to a different host unless that host is also granted, and never to private, loopback or link-local address ranges unless the original URL was itself such an address. A response status other than 200 fails the run. No credentials are sent; authenticated sources are out of scope for the standard library in v0.1.

yaml
spec: openflange.org/pipe/v0.1
id: http-source
version: 0.1.0
title: HTTP source
description: "Source: NDJSON fetched with one HTTP GET. Needs a network grant for the URL's host:port."
license: Apache-2.0
maturity: experimental
outputs:
  out: {kind: records}
parameters:
  url: {type: string, required: true}
  timeoutMs: {type: integer, default: 30000, minimum: 1}
implementation: {type: builtin, name: "std:http-source"}

std:discard #

A sink that consumes and discards its input. It is equivalent to the consumer-side control discard: true on a required output and exists for cases where an explicit node is clearer.

yaml
spec: openflange.org/pipe/v0.1
id: discard
version: 0.1.0
title: Discard
description: "Sink: consumes and discards its input."
license: Apache-2.0
maturity: experimental
inputs:
  in: {kind: records}
implementation: {type: builtin, name: "std:discard"}

6. Examples #

A pipeline that keeps active customers, projects two members and counts in windows of 100:

yaml
spec: openflange.org/pipeline/v0.1
nodes:
  active:
    pipe: std:filter@0.1
    inputs:
      in: {from: inputs.customers}
    parameters:
      expr: 'item["status"] == "active"'
  project:
    pipe: std:select@0.1
    inputs:
      in: {from: active.outputs.out}
    parameters:
      fields: [id, email]
  windows:
    pipe: std:window@0.1
    inputs:
      in: {from: project.outputs.out}
    parameters:
      size: 100
outputs:
  windows:
    from: windows.outputs.out

A deterministic merge of two sources, followed by de-duplication:

yaml
spec: openflange.org/pipeline/v0.1
nodes:
  all:
    pipe: std:merge
    inputs:
      in: {from: [inputs.first, inputs.second]}
    parameters:
      mode: concat
  unique:
    pipe: std:distinct
    inputs:
      in: {from: all.outputs.out}
    parameters:
      fields: [id]
outputs:
  out:
    from: unique.outputs.out

A portable test for a standard pipe (see the Test specification):

yaml
spec: openflange.org/test/v0.1
pipe: std:filter
tests:
  - name: keeps even numbers and routes the rest
    parameters:
      expr: item % 2 == 0
    inputs:
      in: {values: [1, 2, 3, 4]}
    expect:
      outputs:
        out: {values: [2, 4]}
        rejected: {values: [1, 3]}

7. Security considerations #

  • Expressions are code. Expression parameters are Starlark and run in-process. Runners MUST evaluate them with the restrictions of the Starlark binding (no I/O, no load, no access to the environment), and SHOULD bound their execution steps so that a hostile expression cannot hang a run; exceeding the bound fails the run with E_RESOURCE.
  • Bounded state. distinct, window and batch hold state. The bounds (maxKeys, maxPartitions, size) are part of the contract and MUST be enforced with E_RESOURCE; a runner MUST NOT allow unbounded growth.
  • I/O pipes. file-source, file-sink and http-source are the only standard pipes that can reach outside the run. They are subject to enforce-or-refuse permission checks (5.7), path-safety rules and the SSRF and redirect rules of the Pipeline specification. file-sink can overwrite files: a consumer granting filesystem.write SHOULD grant the narrowest directory possible.
  • CSV. csv-encode output opened in spreadsheet software can trigger formula evaluation ("CSV injection") for values beginning with =, +, - or @. The encoder MUST NOT alter data to prevent this (that would be a silent change); consumers that hand CSV to spreadsheet users are responsible for sanitising.
  • No ambient authority. Standard pipes never read environment variables or secrets, and http-source never sends credentials.

8. Compatibility and versioning #

The standard library is versioned as a whole with SemVer; this document describes library version 0.1.0. While the specification is experimental (0.x), a minor version MAY change behaviour incompatibly; such changes are listed in the repository CHANGELOG.md and the affected manifests' versions change. Pipes and parameters will be marked deprecated for at least one minor version before removal, except for proposed features, which can change or disappear at any time. See COMPATIBILITY.md in the specification repository.

The following are explicitly deferred and not part of v0.1:

  • event-time windows, watermarks and allowed lateness;
  • session windows;
  • checkpointing, state recovery and persistent window state;
  • distributed scheduling and parallel partition execution;
  • WebAssembly implementations of standard pipes;
  • stream reconnect or resume for sources;
  • dynamic ports (for example an N-way split with caller-named outputs);
  • aggregation, join and sort pipes (use window-scope or dataset-scope pipes, for example R or SQL, until they are specified);
  • Parquet sources and sinks (Parquet is a snapshot format; planned).

Источник: specs/std/v0.1.md в репозитории спецификаций. Ключевые слова, такие как MUST и SHOULD, используются в значении, определённом в RFC 2119.