Skip to content

02 · Execution engine

Status: Core implemented (T7) · connectors (T8), preview (T11) · runner and orchestration (T13) · Owner: Platform · Code: engine/crates/flux-exec/src/

flux-exec turns a validated pipeline (01) into Apache DataFusion operations. It runs them with streaming, multi-threaded execution and writes dataset targets through the two-phase lake protocol (06). The same planner backs full runs, sharded runs and canvas previews.

sequenceDiagram
  participant O as Orchestrator (flux-api)
  participant R as flux-runner (shard i)
  participant L as Lake (DuckLake + S3)
  O->>R: start(run_id, pipeline version, shard i of K)
  R->>R: validate spec (fail → invalid)
  R->>R: build untapped plan, run runtime checks
  R->>R: build tapped plan
  loop each target
    R->>L: stream sorted batches → Parquet files (staged)
    R->>L: write staging manifest
  end
  R-->>O: StageReport (rows per node:port, targets)
  O->>L: commit(run_id) once every shard succeeded
  L-->>O: snapshot id per dataset (idempotent)
  1. Validate. flux_core::validate. Any error stops the run before any data is read.
  2. Checks. Runtime conditions are planned as queries and run before any target is written: lookup keys must be unique, lookups must match (missing: fail), no invalid rows (on_invalid: fail), invalid-row ratio limits. A failing check fails the run and names the node.
  3. Stage. Each target’s frame is sorted by the dataset key, executed as a stream, and written as Parquet into the table directory. Nothing is visible until commit.
  4. Commit. The orchestrator commits each dataset once, after every shard reports success (flux_exec::run::commit). A failed run calls abort, which deletes staged files.

Builder::build(order) walks nodes in validated topological order and keeps a map (node, port) → DataFrame. Frames are lazy; building a plan reads no data.

Node DataFusion translation
extract Sources::open (connector, fixture, or Flux dataset) → optional column projection → shard filter flux_shard(key, K) = i unless broadcast
map one select with a lowered, optionally cast expression per field (+ unmapped columns)
calculate successive with_column, so later fields see earlier ones
filter filter(condition) (null counts as false)
aggregate aggregate calls are pulled out of each measure (__flux_agg_N), grouped, then the measure expressions are projected: ROUND(SUM(a)/COUNT(), 1) works
join both sides aliased, joined on key pairs, projected back to plain names. Clashing right columns get right_prefix; same-named keys are dropped for inner/left joins
lookup lookup side reduced to keys + requested fields (+ first_value dedupe when duplicates: first), left-joined with a hit marker for missing: drop/fail
union union_by_name (name) or union (position), optional distinct
route one filtered frame per port; first_match excludes earlier matches, default port gets rows matching none
dedupe row_number() over keys ordered by order_by (reversed for keep: last) = 1, or distinct for whole rows
sort / limit sort, limit
window window calls pulled out like aggregates, then projected; ROWS frames from frame
repartition / partition `repartition(Hash
validate one boolean per rule; invalid gets _flux_errors (comma-separated rule names); warn keeps all rows in valid
target recorded with its frame; written by stage

Every output frame gets a tap (filter(flux_tap('node:port'))), a volatile UDF that counts rows as they pass. The optimizer can’t remove it or push it past other operators. The counts become the per-node row numbers in run stats and the live canvas overlay. Checks run on an untapped plan, so they don’t inflate those counts.

The engine-neutral formula AST lowers to DataFusion expressions against the input schema, which gives a type-aware translation:

  • Integer ÷ integer is real division (7 / 2 = 3.5), matching spreadsheet expectations.
  • & casts both sides to text; DATE_TRUNC on a date returns a date.
  • TODAY() and NOW() are fixed at run start, so replays of a run give the same result.
  • DATE_DIFF counts whole units between instants; months are calendar months.
  • Decimal literals keep full precision (Decimal128); CAST(x AS DECIMAL) is DECIMAL(38,9).
  • JSON_GET is a Flux UDF (udf.rs); flux_shard and flux_tap are internal UDFs.
  • Unknown columns produce errors with suggestions: c.fields.0.expr: column 'amout' doesn't exist here; did you mean 'amount'?

ExecError variants: Invalid (spec diagnostics), Node {node, field, message}, Target {node, dataset, message}, System. DataFusion errors are stripped of backtraces and prefixes. The run’s final event carries the node id, and the canvas highlights it. Nothing retries implicitly.

Engine::new(cpus) creates a DataFusion session with target_partitions = cpus, 8k-row batches, and Parquet filter pushdown enabled. Operators run on every partition in parallel; see 03 for node-level partitioning and sharding.

  • Sources::open(ctx, node, extract, shard) returns a lazy frame. ConnectorSources (design 04) reads through connector processes: Spool for runs, Sample(n) for previews, Schema for canvas schemas. Tests use in-memory fixtures.
  • connection: "flux" + object: "<dataset>" reads a Flux dataset from the lake at the current snapshot, so pipelines can build on each other’s output.
  • Sinks::write handles connection targets (T8).

The canvas shows the schema and sample rows at every node. The control plane resolves the active versions of the connections a draft pipeline uses (decrypting credentials) and the active connector catalog pins, then calls flux-preview (ClusterIP, bearer token):

Endpoint Does
POST /v1/preview Rows and schema at one node’s output port
POST /v1/schemas Schema of every output port, without reading data
POST /v1/connection/{test,discover,schema,sample} Connection form checks

The app reaches these as POST /api/pipelines/preview, /api/pipelines/schemas, /api/connections/{key}/{op} and /api/connections/draft/{op} (unsaved forms; omitted secrets come from the stored version). All need the editor role, because they read real data through connections.

Samples. Only the node’s ancestors are built (only). Each extract reads at most source_limit rows (default 1000, max 50 000) from one connector process, then the draft runs on that sample; the output is cut at limit rows (default 100, max 1000). The response says whether the output was truncated and whether any source hit its limit (sampled), in which case joins and aggregates are approximate. Datasets (connection: "flux") are read from the lake; limits push down where DataFusion can.

Schemas. Extracts ask connectors for their schema (schema op) and feed empty frames through the plan, so every node’s output schema is known without reading data. Nodes are built one at a time, so a broken node reports its error while the others still return schemas.

Cache. Samples and schemas are cached for 5 minutes (256 MiB, oldest first), keyed by sha256 of connector, connection values and request, so no credential is kept in a key. Clicking through nodes of the same draft reads each source once.

Isolation and limits. Each request gets its own engine with a memory limit (FLUX_PREVIEW_MEMORY_MB divided by FLUX_PREVIEW_CONCURRENCY); over it, the query fails instead of growing. At most FLUX_PREVIEW_CONCURRENCY requests run at once (others get 429), each bounded by FLUX_PREVIEW_TIMEOUT_S (504). Connectors run out of process as in runs; in production they come from Forge, installed against the request’s pins and re-installed (with a revocation check) every minute, and re-verified on every launch. FLUX_CONNECTOR_DIR is refused in production.

Errors name the node and field (422 {"error": {"kind": "node", "node", "field", "message"}}), like run failures.

Tested: sampling at any node, truncation and sampled flags, cache reuse, node errors, missing connections, auth before body parsing, schemas with a broken node, connection operations, unsafe connector names (flux-preview/tests); and through the API with the real PostgreSQL connector, including role checks and draft tests (test_preview.py).

  • Shared intermediate work isn’t cached. Extracts are read once per run (spooled, design 04), but each target and check re-executes the nodes between the spool and itself. Planned fix: materialize shared prefixes into temporary Parquet when a node fans out to more than one target or check.
  • Upsert rewrites the table (existing minus new keys, union new rows, then replace). It’s correct and conflict-checked, but it costs a full rewrite; see design 07 for the incremental write path.
  • Spill-to-disk limits per compute profile (DataFusion memory pool + disk manager sizes).
  • Cancellation latency: dropping the stream stops work within one batch; the pod is then deleted.