Coverage for python/lsst/daf/relation/_materialization.py: 49%

29 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-25 02:29 -0800

1# This file is part of daf_relation. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ("Materialization",) 

25 

26import dataclasses 

27from typing import TYPE_CHECKING, Literal, final 

28 

29from ._leaf_relation import LeafRelation 

30from ._marker_relation import MarkerRelation 

31 

32if TYPE_CHECKING: 32 ↛ 33line 32 didn't jump to line 33, because the condition on line 32 was never true

33 from ._relation import Relation 

34 

35 

36@final 

37@dataclasses.dataclass(frozen=True, kw_only=True) 

38class Materialization(MarkerRelation): 

39 """A marker operation that indicates that the upstream tree should be 

40 evaluated only once, with the results saved and reused for subsequent 

41 processing. 

42 

43 Materialization is the only provided operation for which 

44 `UnaryOperationRelation.is_locked` defaults to `True`. 

45 

46 Also unlike most operations, the `~Relation.payload` value for a 

47 `Materialization` if frequently not `None`, as this is where 

48 engine-specific state is cached for future reuse. 

49 """ 

50 

51 name: str 

52 """Name to use for the cached payload within the engine (`str`).""" 

53 

54 def __str__(self) -> str: 

55 return f"materialize[{self.name!r}]({self.target})" 

56 

57 @property 

58 def is_locked(self) -> Literal[True]: 

59 # Docstring inherited. 

60 return True 

61 

62 @classmethod 

63 def simplify(cls, target: Relation) -> bool: 

64 match target: 

65 case Materialization(): 

66 return True 

67 case LeafRelation(): 

68 return True 

69 case MarkerRelation(target=new_target): 

70 if target.engine == new_target.engine: 

71 return cls.simplify(new_target) 

72 return False