(distributed_query_engines)=
A distributed query engine takes the query you already wrote and runs it across several machines for you. You do not partition anything by hand and you do not change your queries — the engine installs itself on your session, rewrites the plan into stages, and executes those stages on its own workers.
This is the counterpart to {ref}distributed_expressions, where you decide the partitioning and ship one expression per slice of data. Choose an engine when you want a single query spread across a cluster; choose expressions when you already know how to split the work and only need parallelism.
An engine library ships an object you hand to {py:meth}~datafusion.SessionContext.with_extensions:
from datafusion import SessionContext import my_engine ctx = SessionContext().with_extensions(my_engine.Extension("scheduler:50050")) ctx.register_table("events", my_engine.TableProvider("s3://bucket/events")) ctx.sql("SELECT country, count(*) FROM events GROUP BY country").show()
The sql call is unchanged from a single-process program. What changed is underneath it: installing the engine gave the session a query planner of the engine's own, and that planner is what turns your plan into distributed stages.
Two consequences worth knowing:
with_extensions is a session-level setup step.distributed_udf_portability describes the constraints that apply to Python callables crossing a process boundary in general.If you install more than one library, pass them in one with_extensions call so they can see each other. See {ref}user_guide_extensions for the details of installing extension libraries, and {ref}ffi if you want to write an engine yourself.
(distributed_worker_parity)=
An engine ships your plan to a process that has never seen your session. That process has to be able to rebuild everything the plan refers to, and there is no way to snapshot a {py:class}~datafusion.SessionContext and restore it somewhere else: {py:class}~datafusion.SessionConfig is write-only from Python, and while information_schema.df_settings can be read back, it lists datafusion.runtime.* keys that have no configuration namespace to set them into again.
So parity is not automatic. It is something you build the same way twice, and these are the things that have to match. Most engines handle several of them for you — check which.
__datafusion_codec_id__ rather than letting them default to a class's import path, and compare {py:meth}~datafusion.SessionContext.physical_extension_codec_ids on both sides before shipping anything. See {ref}extension_codec_ids.sys.executable makes this true by construction; a hardcoded python does not.cloudpickle version, which is not stamped. Cross-version loading usually works and is not guaranteed. Pin it.target_partitions, if a worker re-plans anything. Left to default it follows the core count, so two differently-sized machines disagree.Two more that are about lifetime rather than configuration:
extension_sessions.to_bytes. {py:meth}~datafusion.ExecutionPlan.to_bytes takes an optional context, and without one it uses an empty codec chain that cannot encode any library's nodes. The argument being optional makes this easy to miss, because the failure only appears once an extension node is in the plan.And one that is about the engine rather than the session:
Query-level distribution is being built upstream. Neither project below is usable from datafusion-python yet; both sections will fill in as the integrations land. In the meantime the repository contains a worked example you can read and run: examples/distributed splits a query across worker processes using three separate extension libraries, and is written to make each of the requirements above visible — including the ways they fail.
🚧 Work in progress upstream — not yet usable from datafusion-python.
datafusion-distributed splits a single physical plan into stages and runs each stage on a different worker node. The driver writes a SQL or DataFrame query once; the runtime handles partitioning, shuffles, and reassembly.
A datafusion-python integration is in development. In the meantime, {ref}distributed_expressions covers most use cases that do not require automatic plan partitioning.
🚧 Work in progress upstream — not yet usable from datafusion-python.
Apache Ballista provides distributed query execution on top of DataFusion with a scheduler / executor model better suited to long-lived cluster deployments. A datafusion-python integration is on the roadmap.