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.

What does a pipe in batch mode look like in Starlark?

Available — v0.0.1 (experimental)starlarkbatch

A Starlark pipe in batch mode

The mask-email pipe declared with batch: {maxItems: 256} and written as process_batch(items, params): the runner calls it with a list instead of once per address.

Available in v0.0.1: the files, README and tests are in examples/batch-starlark of the openflange-go repository. Commands run from the repository root.

Needs: only the openflange CLI.

A pipe is a data-processing step with declared inputs and outputs.

What goes in, what comes out

Input (stdin)
"alice@example.com"
"bob@example.org"
Command
printf '"alice@example.com"\n"bob@example.org"\n' | openflange run ./examples/batch-starlark
Output (stdout)
"a***e@example.com"
"b*b@example.org"

Files and further commands

examples/batch-starlark/OPENFLANGE.md — the batch declaration (excerpt)
batch:
  maxItems: 256
examples/batch-starlark/mask.star — process_batch (excerpt)
def process_batch(items, params):
    """Called once per batch with a list of 1..maxItems addresses."""
    character = params["character"]
    if len(list(character.codepoints())) != 1:
        fail("parameter character must be exactly one Unicode code point")
    first = params["preserveFirst"]
    last = params["preserveLast"]

    out = []
    for item in items:
        reason = _invalid(item)
        if reason != None:
            # Record-level errors are data. If `rejected` is not connected
            # this emit fails the run (E_RUNTIME).
            emit("rejected", {"value": item, "reason": reason})
        else:
            out.append(_mask(item, character, first, last))
    return out  # goes to the required output `email`, in order
Show the batch settings; run the tests
openflange inspect ./examples/batch-starlark     # shows the batch settings
openflange test ./examples/batch-starlark

What to notice

  • The runner calls the script when maxItems items are there, or at the end of the input. maxWaitMs is 0 here: it never waits. There is no minimum size.
  • The returned list goes to the required output email, element by element; emit works as usual for the optional rejected output.
  • Batch boundaries mean nothing: the tests pin maxItems to 1 and 3 and expect the same output.
  • Does it make this pipe faster? A little: Starlark already runs inside the runner, so only the call overhead goes away. Batch mode is really for pipes that live in another process — see the Python, R and DuckDB examples.
  • No permissions are needed: nothing leaves the runner. Re-run for this page with the v0.0.1 CLI: the output matched the README.