Local execution
Local execution runs a planned DataFrame query in one process. The native runner turns the optimized plan into a local physical plan, feeds data into a stream of bounded batches, applies physical operators, and returns result partitions or write metadata. See Execution engines for the runner choice, Distributed execution for the multi-worker path, and UDFs and aggregations for user-defined functions and grouped work.
Execution model
The native path is coordinated by daft/…/native_runner.py. It freezes the execution context for the query, performs plan optimization, builds a LocalPhysicalPlan, and passes that plan with its source inputs to the native executor. Results are yielded as they become available, so callers can collect a full result or consume partitions as a stream.
The local executor uses one process with shared compute and I/O runtimes. It can still run several operator tasks at once. A shared memory manager limits work that declares a memory need, while cancellation and task completion are handled by the execution loop.
This diagram shows how a lazy query becomes local work and then becomes result partitions.
flowchart LR
A[Optimized logical plan] --> B[Local physical plan]
B --> C[Pipeline nodes]
I[Source inputs] --> C
C --> D[MicroPartition results]
C --> E[Write and commit metadata]
Query lifecycle
When a caller materializes a query, the local path follows a fixed high-level sequence:
- The runner creates query identity and starts query and heartbeat notices.
- The logical plan is optimized with the current execution settings.
- The plan translator binds each source to an input ID and creates physical operators.
- The pipeline builder creates source, transform, join, sink, and write nodes.
- The executor enqueues the source inputs and routes output morsels to the matching input ID.
- The runner yields results and closes the plan when all inputs finish.
An input ID identifies one submitted unit of source work. The same physical pipeline can serve more than one input ID, and each ID receives its own flush signal and runtime stats.
References: daft/…/native_runner.py• L85-178 daft/…/native_executor.py• L28-78 src/…/translate.rs• L21-33 src/…/run.rs• L328-405
Pipeline coordination
The pipeline passes a morsel, a bounded unit of table data, between nodes. A morsel carries its input ID and a MicroPartition. A flush message marks the end of that input, which lets downstream nodes finalize state without waiting for unrelated inputs.
Intermediate operators transform morsels and return new morsels. Streaming sinks can stop or emit output while they consume input. Blocking sinks collect enough state to perform work such as a sort, aggregate, join, repartition, or write, then emit output during finalization. This split lets the engine stream simple work while giving stateful work a clear end-of-input boundary.
References: src/…/pipeline.rs• L81-145 src/…/intermediate_op.rs• L41-69 src/…/blocking_sink.rs• L41-68 src/…/base.rs• L32-81
Physical operators
LocalPhysicalPlan is the executable tree for one local query. It keeps the schema and execution state for each node and represents both ordinary relational work and boundaries that produce or consume partitions. The plan translator walks the logical plan and binds expressions to the input schema before the pipeline is built.
Operator roles
The local engine groups physical operators by how they move data through the pipeline:
| Role | Purpose | Representative work |
|---|---|---|
| Source | Introduce data into the pipeline | In-memory data, scan tasks, and glob paths |
| Intermediate | Transform one morsel into another | Projection, filter, UDF, explode, and unpivot |
| Streaming sink | Process input while retaining limited state | Limit, sample, monotonic IDs, and some UDF paths |
| Blocking sink | Wait for input state before producing final output | Sort, top-N, aggregate, dedup, pivot, and windows |
| Join node | Coordinate two input pipelines | Hash, cross, sort-merge, and as-of joins |
| Write sink | Store data or publish write results | File writes, catalog writes, and data sinks |
The operator role matters to memory and output timing. For example, a sort emits only after it has enough input to complete, while a filter can emit each processed morsel.
References: src/…/plan.rs• L71-132 src/…/translate.rs• L102-188 src/…/pipeline.rs• L436-513 src/…/pipeline.rs• L916-1082
UDF execution
User-defined function (UDF) execution evaluates an expression projection against each input batch while preserving the pipeline's batch and error contracts. A local worker process receives batches through authenticated local IPC and shared-memory transport, runs with one compute thread, and returns both the transformed batch and evaluation metrics.
Ray actor UDFs use a pool of remote actors when the execution mode needs managed placement. The pool checks that each actor can fit on one live node, spreads actors across resources, waits for readiness, and allows bounded actor restarts and task retries. A pool can therefore start with fewer actors than requested when cluster capacity is limited, but it fails when no actor can be scheduled or none becomes ready within the configured timeout.
References: daft/…/udf_worker.py• L26-101 daft/…/ray_actor_pool_udf.py• L24-76 daft/…/ray_actor_pool_udf.py• L79-165
Batch sizing and parallel work
The pipeline propagates a morsel size requirement from downstream nodes to sources. Operators then use per-operator batching rules and a concurrency limit to decide how many morsels can run at once. Each worker has operator state, so stateful operators can process independent inputs without mixing their results.
The memory manager grants permits for declared memory requests. A task waits when the process budget is full and releases its permit when the task ends. This bounds concurrent work, but it does not make an operation that needs more than the total budget runnable.
References: src/…/pipeline.rs• L148-222 src/…/pipeline.rs• L397-433 src/…/intermediate_op.rs• L103-207 src/…/resource_manager.rs• L44-114
Scans and input flow
The local plan separates a source description from the data submitted to it. The translator puts source inputs in a map and gives the physical scan a source ID. At run time, the execution loop sends each input to the matching source node.
Source types
Local execution supports source inputs with different ownership and read paths:
| Source | Input supplied at run time | Main behavior |
|---|---|---|
| In-memory scan | Existing MicroPartition references | Forwards existing partitions into the pipeline |
| Physical scan | Scan tasks | Splits and reads file or external-source tasks in parallel |
| Glob scan | Glob path expressions | Resolves matching files and streams file metadata or data into morsels |
| Shuffle read | Shuffle partition references | Reads local cached data or fetches data from a shuffle server |
All source paths emit a flush event for each input. Empty input still produces an empty partition where needed, so downstream state and result collection can complete in the same way as non-empty input.
References: src/…/lib.rs• L28-50 src/…/translate.rs• L35-97 src/…/input_sender.rs• L8-35 src/…/in_memory.rs• L89-121 src/…/glob_scan.rs• L62-197
Scan task processing
A physical scan receives prepared scan tasks and sends them to format-specific readers. It can split work, limit the number of active scan tasks, apply scan pushdowns such as columns, filters, and limits, and preserve task order when the query asks for ordered output. The readers stream record batches, which the source casts to the materialized schema and wraps as MicroPartition values for the rest of the pipeline.
The source emits an empty partition and a completion signal when a task has no rows. This keeps downstream state and result collection consistent with non-empty input. The scan path also owns source-level I/O stats, applies Iceberg position deletes when present, and can report skipped corrupt files when the source configuration permits them. Parquet can answer an unfiltered full-row count from metadata; filters, limits, non-full count modes, or delete rows require row-level reading instead. A scan failure stops local execution rather than silently changing the result.
References: src/…/scan_task.rs• L37-68 src/…/scan_task.rs• L71-220 src/…/scan_task.rs• L482-642 src/…/scan_task_reader.rs• L20-214 src/…/scan_task_reader.rs• L216-371
Shuffle paths
A shuffle changes how rows are grouped into output partitions so a later stage can read the groups it needs. The local engine has two different meanings for this boundary: the ordinary native runner does not create distributed partitions, while a local executor used as part of a worker task can use a Flight-backed shuffle service.
Native runner partition behavior
The native runner is a single-process engine. Logical repartition and into_partitions requests are therefore treated as no-ops in its plan translation, and a logical random shuffle is represented as a local sort by a seeded random expression. Queries that require physical repartitioning must use the distributed runner.
This boundary is important for correctness and performance. A query can still use local sort, joins, and aggregation, but it cannot use the native runner to create separate partitions for later distributed work.
References: src/…/translate.rs• L392-408 src/…/translate.rs• L583-593 daft/…/dataframe.py• L3770-3838
Flight-backed local shuffles
When a local executor runs a distributed task, a Flight-backed shuffle can spill partition data to local files and expose partition references through a small in-process server. Repartition and gather sinks write the output partitions, register them with the server, and pass references to the next stage. A shuffle reader serves local references without gRPC and fetches remote references through the Flight client when the next stage needs data from another worker.
The write path can use separate files per partition or one combined IPC file with byte ranges. Both forms let the reader locate a partition without rebuilding the whole upstream result. Shuffle directories are local file paths, so their space and lifetime are part of the worker's operating environment.
This diagram shows the local and remote read choices at a shuffle boundary.
flowchart LR
A[Upstream morsels] --> B[Repartition or gather sink]
B --> C[Local shuffle files]
C --> D[In-process Flight server]
D --> E[Local shuffle reader]
D --> F[Remote Flight reader]
E --> G[Next pipeline stage]
F --> G
References: src/…/shuffle_backend.rs• L5-61 src/…/repartition.rs• L64-90 src/…/repartition.rs• L171-241 src/…/shuffle_read.rs• L60-116 src/…/flight_server.rs• L83-212 src/…/oneshot_writer.rs• L56-113
Result writing
Writing is a pipeline stage, not a separate post-processing step. The local plan creates a write sink for the selected output format and a commit stage for file output. The write sink sends data to a writer factory, while the commit stage gathers the paths and applies write-level actions.
File write lifecycle
For a file sink, the local path follows this sequence:
- The writer factory selects a native or PyArrow-backed writer when the format and schema allow it.
- The write sink sends input
MicroPartitionvalues to the writer and tracks rows and bytes written. - The writer closes its files and returns path records as the sink result.
- The commit stage applies overwrite rules, creates an optional success marker, and returns the written paths.
Partitioned output keeps a writer per partition value and omits plain partition columns from the file body when their values are represented in the path. The result of a write is therefore path and partition metadata rather than the original table rows.
References: src/…/translate.rs• L610-666 src/…/pipeline.rs• L1404-1464 src/…/write.rs• L171-256 src/…/commit_write.rs• L61-193 src/…/partition.rs• L14-56
Result collection
The native executor exposes each completed MicroPartition to Python through an async result receiver. The Python runner converts those results to local materialized results and either yields them or stores them in the local partition-set cache. At the end of an input, the executor returns execution stats and the physical pipeline description.
If a consumer stops early, the runner closes the result stream and marks the query as finished or canceled as appropriate. Errors from a UDF, operator, source, or writer are surfaced through the same query lifecycle instead of being hidden by result collection.
References: daft/…/native_executor.py• L32-78 src/…/run.rs• L679-769 daft/…/native_runner.py• L154-214
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
Inputvariant,InputSendervariant, source node, and plan translation aligned. A mismatch can reach an unreachable branch when a plan is run. - Keep flush behavior aligned across every source and every stateful sink. A missing flush can leave per-input state open and prevent final output or commit.
- When adding a physical operator, update the plan-to-pipeline mapping and its schema, stats, and morsel-size behavior together.
- When changing scan task splitting, order handling, empty-input behavior, or reader pushdowns, preserve the contract between scan completion and downstream flush.
- When changing shuffle partition IDs, file layout, or reference metadata, update both the writer registration path and local or remote read path.
- When changing write formats or partition columns, keep writer selection, file schema handling, commit metadata, and overwrite behavior consistent.
- When changing executor reuse or plan fingerprints, preserve the rule that one cached pipeline only accepts matching input sender types.
- When changing UDF worker transport or actor-pool startup, keep batch result framing, error reporting, resource checks, readiness timeouts, and retry behavior aligned with the caller's UDF contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A repartition query uses the native runner | Repartition is ignored and the input plan runs without the requested partition layout | Use the distributed runner for physical repartitioning |
| A source input reaches the wrong input sender type | Local execution fails at the input boundary | Keep Input, InputSender, and plan translation mappings synchronized |
| A stateful node does not receive a flush event | Its per-input state is not finalized and output or a write commit can remain incomplete | Every source must emit one flush per input, including empty input |
| A scan reader cannot satisfy a pushed-down count | The scan fails instead of returning a potentially wrong count | Use metadata count only for full counts without filters, limits, or delete rows |
| A scan task produces no record batch and no empty partition | Downstream state can wait for data or completion that never arrives | Preserve empty-partition emission for empty scan tasks |
| A corrupt file is not allowed by source settings | The scan fails and local execution stops | Enable the source's skip-corrupt-files behavior only when incomplete input is acceptable |
| A Flight shuffle plan runs without a local shuffle server | Shuffle sink or reader setup fails because partition references have no serving endpoint | Start the Flight server for Flight-backed local worker execution |
| A shuffle directory is not a local file path or lacks space | Shuffle spill or partition registration fails before the next stage can read data | Configure usable local shuffle directories and monitor their capacity |
| A physical operator requests more memory than the process budget | The task returns a compute error instead of waiting | Set the memory budget and operator requests within the same usable range |
| A file writer cannot support the selected format, schema, or single-file mode | Pipeline creation or finalization fails, and no committed result is returned | Check writer support and format constraints before enabling the write mode |
| No live node can satisfy one Ray UDF actor's resource request | The actor pool cannot schedule any actor | Set per-actor resource needs that one node can provide |
| Ray UDF actors do not become ready before the configured timeout | The UDF pool fails to start, or it proceeds with only the actors that became ready | Set a readiness timeout that matches cluster startup time and available capacity |
| A UDF worker loses its IPC connection or cannot serialize an error | The parent receives an incomplete UDF result or a reduced error report | Keep the worker transport alive and preserve the UDF error framing contract |
Key files
| File | Why to read it |
|---|---|
| daft/…/native_runner.py | Shows the Python entry point for optimization, local plan creation, result streaming, and query completion. |
| daft/…/native_executor.py | Shows the bridge from Python to the native async executor and result receiver. |
| daft/…/udf_worker.py | Shows the local UDF worker boundary for batch transport, evaluation metrics, and error reporting. |
| daft/…/ray_actor_pool_udf.py | Shows the Ray actor UDF boundary for resource placement, readiness, and actor retries. |
| src/…/translate.rs | Shows how logical sources and operations become local physical operators and inputs. |
| src/…/plan.rs | Defines the local physical plan and its operator families. |
| src/…/run.rs | Coordinates plan reuse, input enqueueing, output routing, cancellation, and execution stats. |
| src/…/pipeline.rs | Connects physical operators to source, transform, join, sink, and write pipeline nodes. |
| src/…/scan_task.rs | Explains scan-task scheduling, empty-input completion, ordering, delete handling, and input completion. |
| src/…/scan_task_reader.rs | Shows format dispatch, pushdown handoff, and the Parquet metadata count boundary. |
| src/…/repartition.rs | Explains partition creation and the Flight shuffle output path. |
| src/…/shuffle_read.rs | Explains local versus remote shuffle reads. |
| src/…/write.rs | Shows how pipeline data becomes files and write results. |
| src/…/commit_write.rs | Shows overwrite, success-marker, and final path handling. |
| src/…/flight_server.rs | Defines the local shuffle registry and partition serving boundary. |
| src/…/lib.rs | Defines the writer factory and async writer contracts used by local writes. |