To run:
pip install dagster, dagit
dagster dev -f 3d_multi_partitions.py
This example shows how to use asset factories to construct an asset graph that contains 3+ dimensional "partioned" assets. In this approach, eash asset group represents a dimension, with each asset inside the group representing a "partition". In this example, "shape" and "color" are both asset groups. In the "shape" group there are assets for each value of interest, "circle" and "square". We continue to use dagster's built-in partitions for dates. Downstream combinations of assets can be created with the appropriate upstream dependencies. In this example a downstream asset is created for each permutation of color and shape, eg, red_circle. Like regular assets, this dependency graph could be used to fuel auto-materialization policies. This result is comparable to PartitionMapping in the 2D case, but extensible to the 3+ dimensions.
In this approach the Dagster UI remains navigable:
- The asset group can be used for UI sub-selection:
- Asset search also works for UI sub-selection:
-
Backfills can be launched across the date dimension as normal. To launch a backfill of multiple dimensions, eg date and shape, simply select the relevant assets, eg "all circle assets" and then materialize all.
-
The code shows how to utilize the dimensions within the asset for appropriate computation. In this case a sample SQL query is constructed. This example uses
non_argument_deps
instead of any IO manager, so it is up to the asset code to either load and store the data or use the parameters to execute an appropriate client command:
The example could be extended to additional dimensions by further iterating on the "permutation loop", eg crossing the list of color_shape tuples with a list of sizes to create a nested tuple: ((color, shape), size)
.