Skip to content

Commit a839904

Browse files
committed
Partition Docs
Test Plan: unit Reviewers: prha Reviewed By: prha Differential Revision: https://dagster.phacility.com/D2010
1 parent 6c6612c commit a839904

31 files changed

Lines changed: 536 additions & 5 deletions

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. title:: Home
22

33
.. toctree::
4-
:maxdepth: 3
4+
:maxdepth: 5
55
:includehidden:
66
:name: Documentation
77

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. currentmodule:: dagster
2+
3+
Partitions
4+
==========
5+
6+
.. autoclass:: Partition
7+
.. autoclass:: PartitionSetDefinition
8+
9+
.. autodecorator:: repository_partitions
10+
11+
.. currentmodule:: dagster.utils.partitions
12+
13+
.. autofunction:: date_partition_range

docs/sections/api/apidocs/schedules.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Schedules
44
=========
55

66
.. autodecorator:: schedules
7+
.. autodecorator:: monthly_schedule
78
.. autodecorator:: hourly_schedule
89
.. autodecorator:: daily_schedule
910

docs/sections/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ API Docs
1414
apidocs/errors
1515
apidocs/utilities
1616
apidocs/schedules
17+
apidocs/partitions
1718
apidocs/cli
1819
apidocs/dagstermill
1920

docs/sections/learn/guides/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ Guides
22
=======================
33

44
.. toctree::
5-
:maxdepth: 1
5+
:maxdepth: 2
6+
67

78
dagster_types
89
solid/solid
10+
partitioning/index
911
testing/testing
1012
testing/expectations
1113
logging/logging
318 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Peforming a backfill
2+
^^^^^^^^^^^^^^^^^^^^
3+
4+
Now that we have a partition set defined for a pipeline, we can perform a backfill over all the partitions.
5+
6+
To do backfills, make sure you've set up a Run Launcher. In a separate terminal window, run ``dagit`` for our current repository. Now let's run ``dagster pipeline backfill`` and follow the prompts
7+
8+
.. code-block:: console
9+
10+
$ dagster pipeline backfill compute_total_stock_volume
11+
Pipeline: compute_total_stock_volume
12+
Partition set: stock_ticker_partition_sets
13+
Partitions:
14+
AAPL GOOG MSFT TSLA
15+
16+
Do you want to proceed with the backfill (4 partitions)? [y/N]: t
17+
Launching runs...
18+
Launched backfill job `uufbdyqg`
19+
20+
The backfill script just launched 4 runs configured individually for each partition. If we load dagit and filter for the tag ``dagster/backfill=uufbdyqg`` we'll be able to see our four runs:
21+
22+
.. thumbnail:: backfill.png
224 KB
Loading
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Creating a Date Partition Set
2+
===============================
3+
4+
The most common partitioning scheme is date based partitions. We'll now create a :py:class:`PartitionSetDefinition <dagster.PartitionSetDefinition>` for a set of dates.
5+
6+
First, let's modify our solid to take a date range as config:
7+
8+
9+
.. literalinclude:: ../../../../../examples/dagster_examples/stocks/repository.py
10+
:linenos:
11+
:lines: 4-19
12+
:language: python
13+
:caption: repository.py
14+
15+
16+
Just as before, we write a function that returns a list of partitions, but this time we return a list of ``datetime`` objects.
17+
18+
.. literalinclude:: ../../../../../examples/dagster_examples/stocks/date_partitions.py
19+
:linenos:
20+
:lines: 9-15
21+
:language: python
22+
:caption: repository.py
23+
24+
25+
Next, we define a function that takes a date :py:class:`Partition <dagster.Partition>` and returns config. Here, we calculate the first and last days of the previous month for each date partition to pass to the solid config.
26+
27+
.. literalinclude:: ../../../../../examples/dagster_examples/stocks/date_partitions.py
28+
:linenos:
29+
:lines: 18-34
30+
:language: python
31+
:caption: repository.py
32+
33+
Since it's not practical to hardcode all the possible date partitions, and we usually want date partitions between two date ranges, Dagster provides a utility to generate a list of partitions given a date range and time interval: :py:func:`date_partition_range <dagster.utils.partitions.date_partition_range>`. We'll use this function instead of the one we wrote above.
34+
35+
.. literalinclude:: ../../../../../examples/dagster_examples/stocks/date_partitions.py
36+
:linenos:
37+
:lines: 37-46
38+
:language: python
39+
:caption: repository.py
40+
41+
42+
Now, let's load dagit again and head to the Playground tab. This time, we'll see our date partitions in the partition selector.
43+
44+
.. thumbnail:: playground_date_partitions.png
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Partitioning and Scheduling Guide
2+
=================================
3+
4+
Tutorial
5+
^^^^^^^^
6+
7+
.. toctree::
8+
:maxdepth: 2
9+
10+
partition_pipeline
11+
partition_set
12+
backfill
13+
date_partition_set
14+
schedule_partitions
15+
16+
You can find all of the code for this guide checked into the dagster repository at ``dagster/examples/dagster_examples/stocks``
17+
18+
In this guide, we'll learn about why we partition data and how to write Dagster pipelines that can easily work with partitioned data. We'll also explore how to schedule partitioned work using Dagster's built-in scheduler functionalities.
19+
20+
Partitioning and Scheduling in Dagster
21+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
Many data engineering pipelines need to be written so they operate on partitioned segments of data. These pipelines are also often schedules so that they execute partitions of data at some interval.
24+
25+
For example, lets say we have a metrics pipeline that partitions data based on 24 hour time intervals. We will probably want to schedule this pipeline to run every day at midnight on the previous 24 hours' metrics data. With this setup, we'll have data continuously processed for every 24 hour segment.
26+
27+
Traditional workflow systems tightly couple partitioning and scheduling and provide solutions to date partitioned schedules like this metrics pipeline. However, as we've seen, there are many other ways to partition data, and these two concepts do not need to be completely intertwined. Being able to partition data on axis other than time is especially useful when conducting backfills.
28+
29+
Dagster aims to provides a flexible and generalized solution to partitioning, backfills, and scheduling that can extend beyond datetime partitioning, while also providing a set of easy to use tools for the common datetime partitioning use case.
30+
31+
In the next part of the tutorial, we'll build a partitioned schedule.
32+
33+
What is scheduling?
34+
^^^^^^^^^^^^^^^^^^^
35+
36+
The term "scheduling" is often overloaded in the context of workflow engines like Dagster. In this case, scheduling pipeline runs specifically refers to triggering pipeline runs to happen at some interval. For example, I might want to schedule an email marketing pipeline once a day at 9AM.
37+
38+
What is data partitioning?
39+
^^^^^^^^^^^^^^^^^^^^^^^^^^
40+
41+
When working with small datasets, we can easily make queries or run calculations over the entire dataset at once. Even after updating the base dataset, it's not expensive to redo queries and calculations to get new answers.
42+
43+
When datasets get extremely large it becomes difficult to work with the entire dataset in once piece. Queries become slower and inefficient and even fast data processing tools can take a long time to process extremely large quantities of data.
44+
45+
When we partition data, we break it up into discrete chunks using some partitioning scheme. For example, if we're working with a large metrics dataset, we might want to partition the data by country or other customer segments. It's often easier to reason about data when segmented into such partitions. Also, with smaller units of the data, we can process the partitions with less effort and, if there is no dependence between partitions, we can process the partitions in parallel.

0 commit comments

Comments
 (0)