PeaLang / Code Library / Blueprint
Production Blueprint · v3.1.36

Data pipeline quality gate

Domain: Data Engineering / Pipeline QualityPeaLangPython
Verified example. The code below was checked against the local PeaLang v3.1.36 parser, interpreter or async VM. It uses only syntax and built-ins present in that source tree.

Problem statement

An ETL job publishes a dataset to several consumers. Before publication it must reject an empty batch, count records by region and fail closed when any value is missing or negative — with a report that data engineers can read in CI logs.

Complete code

function quality(rows) {
  if len(rows) == 0 {
    return error("ValueError", "empty dataset", "E_EMPTY")
  }
  let groups = group_by(rows, "region")
  let totals = {r: len(v) for [r, v] in items(groups)}
  let bad = [r for r in rows if r["value"] == null or r["value"] < 0]
  return {"groups": totals, "invalid": len(bad), "ok": len(bad) == 0}
}

let rows = [
  {"region": "east", "value": 10},
  {"region": "west", "value": 5},
  {"region": "east", "value": null}
]
print std.json.stringify(quality(rows))
Save as data-pipeline-quality-gate.pea

Run & verify

pea fmt --check data-pipeline-quality-gate.pea
pea check data-pipeline-quality-gate.pea
pea run data-pipeline-quality-gate.pea
Always run the formatter and static checker before execution: pea fmt --check data-pipeline-quality-gate.pea && pea check data-pipeline-quality-gate.pea, then pea run data-pipeline-quality-gate.pea (or the host command shown above for async modules).

Why & How

  1. Fail closed on empty input. An empty batch is treated as a structured value error with code E_EMPTY, not as an empty success report. This prevents a silent no-op from being mistaken for a healthy pipeline run.
  2. Comprehensions do the aggregation. group_by(rows, "region") buckets records, and a dict comprehension with destructuring [r, v] turns those buckets into counts. No mutable accumulator loop is needed.
  3. Null safety. The invalid-row comprehension checks null and negative values explicitly. PeaLang's null is a real value, so treating it as a number would produce misleading aggregates.
  4. Portable output. std.json.stringify produces deterministic JSON for logs or a CI artifact. The ok flag is derived from the same invalid count, so there is no second source of truth.
  5. Python host boundary. In a production pipeline, call this function through interop.call_python in the reverse direction — the host supplies rows from its dataframe layer and receives plain maps back. PeaLang owns the policy, not the I/O.
  6. Verification. The sample returns two east rows, one west row, one invalid row and "ok": false, demonstrating every branch of the quality rule.