<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Directed_acyclic_graph_(Spark)</id>
	<title>Directed acyclic graph (Spark) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Directed_acyclic_graph_(Spark)"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Directed_acyclic_graph_(Spark)&amp;action=history"/>
	<updated>2026-12-06T00:08:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Directed_acyclic_graph_(Spark)&amp;diff=140&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Directed_acyclic_graph_(Spark)&amp;diff=140&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:39Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Directed acyclic graph (Spark)&lt;br /&gt;
| also_known_as   = DAG, Spark DAG, RDD lineage graph&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = RDD lineage, narrow and shuffle dependencies, DAG scheduler, stages, task scheduler&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Job, stage and task]], [[Narrow and wide transformations]], [[RDD]], [[Lazy evaluation]], [[Shuffle]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (core DAGScheduler.scala, docs/rdd-programming-guide.md, docs/web-ui.md, python/pyspark/core/rdd.py, python/pyspark/sql/dataframe.py, WholeStageCodegenExec.scala), the SIGMOD 2015 Spark SQL paper, the Airflow 3.4.0 documentation and a PySpark 4.3.0 run}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], the &amp;#039;&amp;#039;&amp;#039;directed acyclic graph&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;DAG&amp;#039;&amp;#039;&amp;#039;) of a job is the graph of datasets and the operations that connect them; Spark&amp;#039;s DAG scheduler cuts this graph into stages at [[shuffle]] boundaries and runs the stages in dependency order.&amp;lt;ref name=&amp;quot;dag&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala |title=DAGScheduler.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; &amp;quot;Directed&amp;quot; means each edge points from an input dataset to the dataset computed from it, and &amp;quot;acyclic&amp;quot; means no dataset depends on itself. The same graph, read backwards from a result, is the &amp;#039;&amp;#039;&amp;#039;lineage&amp;#039;&amp;#039;&amp;#039; that Spark uses to recompute lost data.&lt;br /&gt;
&lt;br /&gt;
== What does the DAG scheduler do? ==&lt;br /&gt;
The DAGScheduler is the high-level scheduling layer in the [[Driver (Apache Spark)|driver]]. For each job, the Spark 4.3.0 source describes it as computing a DAG of stages, tracking which RDDs and stage outputs are already materialized, finding a minimal schedule, and submitting each stage as a TaskSet to the lower-level task scheduler.&amp;lt;ref name=&amp;quot;dag&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DAG scheduler has four further duties, all listed in its source:&amp;lt;ref name=&amp;quot;dag&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Stage boundaries.&amp;#039;&amp;#039;&amp;#039; It breaks the RDD graph at shuffle boundaries. Operations with narrow dependencies, like &amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt;, are pipelined into one set of tasks in a stage; a shuffle dependency needs a map stage that writes output files and a later stage that reads them after a barrier.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Reuse.&amp;#039;&amp;#039;&amp;#039; It remembers which RDDs are cached and which shuffle map stages have already produced output, so it does not recompute them.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Placement.&amp;#039;&amp;#039;&amp;#039; It computes preferred locations for each task from cached data, shuffle data or the input&amp;#039;s own locations, and passes them to the task scheduler.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Recovery.&amp;#039;&amp;#039;&amp;#039; When shuffle output files are lost, it resubmits the stages that produced them. Failures inside a stage that are not caused by lost shuffle files are retried by the task scheduler.&lt;br /&gt;
&lt;br /&gt;
The result of these steps is visible in the Spark web UI. A job&amp;#039;s detail page draws its DAG, with vertices for the RDDs or DataFrames and edges for the operations, and each stage detail page draws the stage&amp;#039;s part of the graph.&amp;lt;ref name=&amp;quot;webui&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/web-ui.html |title=Web UI (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Where are the stage boundaries? ==&lt;br /&gt;
A stage boundary is placed at every shuffle dependency, and nowhere else. Within one stage, every task applies the same chain of operations to a different partition. In the end, every stage has only shuffle dependencies on other stages.&amp;lt;ref name=&amp;quot;dag&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For DataFrame and SQL queries, the shuffle dependencies come from &amp;lt;code&amp;gt;Exchange&amp;lt;/code&amp;gt; operators in the physical plan. The plan below (from a PySpark 4.3.0 run with [[Adaptive Query Execution]] and broadcast joins turned off; plan IDs removed) has two &amp;lt;code&amp;gt;Exchange&amp;lt;/code&amp;gt; nodes feeding a sort-merge join, so the job has three stages: one for each input side and one for the join.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
*(5) Project [k#9L]&lt;br /&gt;
+- *(5) SortMergeJoin [k#9L], [k#11L], Inner&lt;br /&gt;
   :- *(2) Sort [k#9L ASC NULLS FIRST], false, 0&lt;br /&gt;
   :  +- Exchange hashpartitioning(k#9L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
   :     +- *(1) Project [id#8L AS k#9L]&lt;br /&gt;
   :        +- *(1) Range (0, 1000000, step=1, splits=2)&lt;br /&gt;
   +- *(4) Sort [k#11L ASC NULLS FIRST], false, 0&lt;br /&gt;
      +- Exchange hashpartitioning(k#11L, 200), ENSURE_REQUIREMENTS&lt;br /&gt;
         +- *(3) Project [id#10L AS k#11L]&lt;br /&gt;
            +- *(3) Range (0, 100, step=1, splits=2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which operators create a shuffle is covered in [[Narrow and wide transformations]].&lt;br /&gt;
&lt;br /&gt;
== What is lineage? ==&lt;br /&gt;
Lineage is the record of the transformations that produced a dataset. Spark&amp;#039;s cache is fault tolerant because of it: if a partition of a persisted RDD is lost, Spark recomputes it with the transformations that originally created it.&amp;lt;ref name=&amp;quot;rddguide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/rdd-programming-guide.html |title=RDD Programming Guide (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The 2015 Spark SQL paper describes RDDs the same way: the system recovers lost data using the lineage graph, by rerunning operations such as a filter to rebuild missing partitions.&amp;lt;ref name=&amp;quot;paper&amp;quot;&amp;gt;{{Cite web |url=https://people.csail.mit.edu/matei/papers/2015/sigmod_spark_sql.pdf |title=Spark SQL: Relational Data Processing in Spark (SIGMOD 2015) |publisher=Armbrust et al., Databricks, MIT CSAIL and AMPLab UC Berkeley |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Shuffle files support the same recovery. Spark keeps them until the RDDs that use them are no longer referenced, so that the map side does not have to run again if the lineage is recomputed.&amp;lt;ref name=&amp;quot;rddguide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lineage can be printed. &amp;lt;code&amp;gt;RDD.toDebugString()&amp;lt;/code&amp;gt; returns a description of an RDD and its recursive dependencies.&amp;lt;ref name=&amp;quot;rddpy&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/core/rdd.py |title=rdd.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; For DataFrames, &amp;lt;code&amp;gt;explain()&amp;lt;/code&amp;gt; plays the same role (see [[Logical plan and physical plan]]).&lt;br /&gt;
&lt;br /&gt;
A long lineage has a cost: the plan grows with each step, and recomputing it after a failure repeats every step. &amp;lt;code&amp;gt;DataFrame.checkpoint()&amp;lt;/code&amp;gt; truncates the logical plan by saving the data to the checkpoint directory; the PySpark reference recommends it for iterative algorithms, where the plan may grow exponentially. It works with Spark Connect since 4.0.0.&amp;lt;ref name=&amp;quot;pydf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/dataframe.py |title=dataframe.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What the Spark DAG is not ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Not an orchestration DAG.&amp;#039;&amp;#039;&amp;#039; In [[Apache Airflow]], a Dag models a whole workflow: its schedule, its tasks (for example submitting a Spark job) and the dependencies between them.&amp;lt;ref name=&amp;quot;airflow&amp;quot;&amp;gt;{{Cite web |url=https://airflow.apache.org/docs/apache-airflow/3.4.0/index.html |title=What is Airflow? (Airflow 3.4.0 documentation) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A Spark DAG lives inside one Spark job: the driver builds it for an action and schedules its stages.&amp;lt;ref name=&amp;quot;dag&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Not the query plan itself.&amp;#039;&amp;#039;&amp;#039; For DataFrame and SQL code, the [[Catalyst optimizer]] first produces logical and physical plans, which are trees of operators.&amp;lt;ref name=&amp;quot;paper&amp;quot; /&amp;gt; Each physical operator executes as an RDD of rows (in the Spark 4.3.0 source, &amp;lt;code&amp;gt;doExecute()&amp;lt;/code&amp;gt; returns an &amp;lt;code&amp;gt;RDD[InternalRow]&amp;lt;/code&amp;gt;), and the DAG scheduler works on that RDD graph.&amp;lt;ref name=&amp;quot;wscg&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/WholeStageCodegenExec.scala |title=WholeStageCodegenExec.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Job, stage and task]]&lt;br /&gt;
* [[Narrow and wide transformations]]&lt;br /&gt;
* [[Lazy evaluation]]&lt;br /&gt;
* [[RDD]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Logical plan and physical plan]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>