Partitions
A partition is one time slice of a
model, such as a single day. Rocky’s time_interval materialization
strategy says a model is partitioned by a time column at a fixed
granularity: hour, day, month, or year.
dagster-rocky converts those strategies into Dagster’s
PartitionsDefinition
variants. The translation happens twice, once when Dagster loads your
definitions and once on every run:
LOAD TIME rocky compile ──► ModelDetail ──► partitions_def_for_model_detail() │ ▼ PartitionsDefinition │ passed as partitions_def= ▼ your Dagster asset
RUN TIME context.partition_key ──► dagster_to_rocky_partition_key() "2026-04-08-13:00" │ ▼ "2026-04-08T13" ──► rocky run --partition <key>RockyComponent does both steps when you set surface_derived_models or dag_mode (both default to False). It groups assets by partitioning shape and threads each Dagster partition key into rocky run --partition <key>. dag_mode reads partition shape from rocky dag output, not from rocky compile.
Use the standalone helpers below when you build partitioned assets by hand.
Strategy mapping
Section titled “Strategy mapping”| Rocky grain | Dagster PartitionsDefinition |
|---|---|
hour |
HourlyPartitionsDefinition |
day |
DailyPartitionsDefinition |
month |
MonthlyPartitionsDefinition |
year |
TimeWindowPartitionsDefinition (yearly cron, no first-class class) |
partitions_def_for_time_interval(granularity, first_partition, ...)
Section titled “partitions_def_for_time_interval(granularity, first_partition, ...)”A pure builder. It takes a granularity and a start date, then returns the
matching PartitionsDefinition.
from dagster_rocky import partitions_def_for_time_interval
pdef = partitions_def_for_time_interval( granularity="day", first_partition="2026-01-01", timezone="UTC",)# pdef is a DailyPartitionsDefinition starting 2026-01-01 UTCpartitions_def_for_model_detail(model)
Section titled “partitions_def_for_model_detail(model)”The higher-level builder. It takes a ModelDetail from
CompileResult.models_detail. When the strategy discriminator says
time_interval, it calls the pure builder above.
It returns None for every other strategy, for example full_refresh,
incremental, merge, delete_insert, and view. It also returns None
for microbatch, even though that strategy is time-based.
from dagster_rocky import partitions_def_for_model_detail, RockyResource
rocky = RockyResource(config_path="rocky.toml", models_dir="models")compile_result = rocky.compile()
for model in compile_result.models_detail: pdef = partitions_def_for_model_detail(model) if pdef is not None: # Build a partitioned asset for this model ...Format conversion
Section titled “Format conversion”Rocky and Dagster use different canonical key formats for hourly and monthly grains:
| Grain | Rocky canonical | Dagster canonical |
|---|---|---|
hour |
2026-04-08T13 |
2026-04-08-13:00 |
day |
2026-04-08 |
2026-04-08 |
month |
2026-04 |
2026-04-01 |
year |
2026 |
2026 |
Day and year are wire-compatible. Hour and month need translation. Two helpers handle the conversion in both directions:
from dagster_rocky import ( rocky_to_dagster_partition_key, dagster_to_rocky_partition_key,)
# Rocky → Dagster (e.g. building a Dagster cursor from a Rocky run output)dagster_key = rocky_to_dagster_partition_key("hour", "2026-04-08T13")# "2026-04-08-13:00"
# Dagster → Rocky (e.g. threading a Dagster partition key into rocky run)rocky_key = dagster_to_rocky_partition_key("hour", "2026-04-08-13:00")# "2026-04-08T13"Round-tripping a key through both helpers is idempotent for all grains.
CLI argument builders
Section titled “CLI argument builders”Two convenience helpers build the rocky run argument list for partition
execution:
from dagster_rocky import partition_key_arg, partition_range_args
# Single-partition executionargs = partition_key_arg("2026-04-08")# ["--partition", "2026-04-08"]
# Backfill range execution (BackfillPolicy.single_run())args = partition_range_args("2026-04-01", "2026-04-08")# ["--from", "2026-04-01", "--to", "2026-04-08"]Both return [] when their inputs are None, so you can splat them into the argument list.