Skip to content

Commit a052bb1

Browse files
committed
[pac] add AssetCheckStatusCacheValue
1 parent f645bf8 commit a052bb1

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

python_modules/dagster/dagster/_core/asset_graph_view/asset_graph_view.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import functools
32
from collections.abc import Awaitable, Iterable
43
from datetime import datetime, timedelta
@@ -22,6 +21,7 @@
2221
from dagster._core.definitions.freshness import FreshnessState
2322
from dagster._core.definitions.partitions.context import (
2423
PartitionLoadingContext,
24+
partition_loading_context,
2525
use_partition_loading_context,
2626
)
2727
from dagster._core.definitions.partitions.definition import (
@@ -564,9 +564,12 @@ async def compute_subset_with_status(
564564
"""Returns the subset of an asset check that matches a given status."""
565565
from dagster._core.storage.event_log.base import AssetCheckSummaryRecord
566566

567-
# Handle partitioned asset checks with partition-level granularity
567+
# Handle partitioned asset checks
568568
if self._get_partitions_def(key):
569-
return await self._get_partitioned_check_subset_with_status(key, status, from_subset)
569+
with partition_loading_context(new_ctx=self._partition_loading_context):
570+
return await self._get_partitioned_check_subset_with_status(
571+
key, status, from_subset
572+
)
570573

571574
# Handle non-partitioned asset checks with existing logic
572575
summary = await AssetCheckSummaryRecord.gen(self, key)
@@ -628,35 +631,39 @@ async def _compute_missing_check_subset(
628631
) -> EntitySubset[AssetCheckKey]:
629632
return await self.compute_subset_with_status(key, None, from_subset)
630633

631-
async def _get_asset_check_partition_status(
632-
self, key: AssetCheckKey, partition: str
633-
) -> Optional["AssetCheckExecutionResolvedStatus"]:
634-
# NOTE: we should add a LoadingContext-native version of this
635-
record = self.instance.event_log_storage.get_latest_asset_check_execution_by_key(
636-
[key], partition
637-
).get(key)
638-
if record:
639-
targets_latest = await record.targets_latest_materialization(self)
640-
return await record.resolve_status(self) if targets_latest else None
641-
else:
642-
return None
643-
634+
@use_partition_loading_context
644635
async def _get_partitioned_check_subset_with_status(
645636
self,
646637
key: AssetCheckKey,
647638
status: Optional["AssetCheckExecutionResolvedStatus"],
648639
from_subset: EntitySubset,
649640
) -> EntitySubset[AssetCheckKey]:
641+
from dagster._core.storage.asset_check_status_cache import (
642+
get_updated_asset_check_status_cache_value,
643+
)
644+
650645
check_node = self.asset_graph.get(key)
651646
if not check_node or not check_node.partitions_def:
652647
check.failed(f"Asset check {key} not found or not partitioned.")
653648

654-
partitions = list(from_subset.expensively_compute_partition_keys())
655-
statuses = await asyncio.gather(
656-
*(self._get_asset_check_partition_status(key, p) for p in partitions)
649+
cache_value = get_updated_asset_check_status_cache_value(
650+
key, check_node.partitions_def, self
657651
)
658-
matching_partitions = {p for p, s in zip(partitions, statuses) if s == status}
659-
return from_subset.compute_intersection_with_partition_keys(matching_partitions)
652+
653+
if status is None:
654+
known_statuses = self.get_empty_subset(key=key)
655+
for serializable_subset in cache_value.subsets.values():
656+
subset = self.get_subset_from_serializable_subset(serializable_subset)
657+
if subset:
658+
known_statuses = known_statuses.compute_union(subset)
659+
return from_subset.compute_difference(known_statuses) or self.get_empty_subset(key=key)
660+
else:
661+
serializable_subset = cache_value.subsets.get(status)
662+
if serializable_subset is None:
663+
return self.get_empty_subset(key=key)
664+
return self.get_subset_from_serializable_subset(
665+
serializable_subset
666+
) or self.get_empty_subset(key=key)
660667

661668
async def _compute_run_in_progress_asset_subset(self, key: AssetKey) -> EntitySubset[AssetKey]:
662669
from dagster._core.storage.partition_status_cache import AssetStatusCacheValue

0 commit comments

Comments
 (0)