pipeloom-dagster 1.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pipeloom_dagster-1.5.0/.gitignore +18 -0
- pipeloom_dagster-1.5.0/LICENSE +202 -0
- pipeloom_dagster-1.5.0/NOTICE +2 -0
- pipeloom_dagster-1.5.0/PKG-INFO +52 -0
- pipeloom_dagster-1.5.0/README.md +27 -0
- pipeloom_dagster-1.5.0/pyproject.toml +43 -0
- pipeloom_dagster-1.5.0/src/pipeloom_dagster/__init__.py +7 -0
- pipeloom_dagster-1.5.0/src/pipeloom_dagster/defs.py +252 -0
- pipeloom_dagster-1.5.0/src/pipeloom_dagster/py.typed +0 -0
- pipeloom_dagster-1.5.0/src/pipeloom_dagster/unit.py +76 -0
- pipeloom_dagster-1.5.0/tests/test_definitions.py +240 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
.venv/
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
*.egg-info/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.mypy_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.coverage
|
|
11
|
+
coverage.xml
|
|
12
|
+
htmlcov/
|
|
13
|
+
site/
|
|
14
|
+
target/
|
|
15
|
+
.pipeloom/
|
|
16
|
+
.env
|
|
17
|
+
examples/data/
|
|
18
|
+
examples/airflow/include/wheels/
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pipeloom-dagster
|
|
3
|
+
Version: 1.5.0
|
|
4
|
+
Summary: Dagster integration for pipeloom: a compiled plan as one multi_asset per unit.
|
|
5
|
+
Project-URL: Repository, https://github.com/emanuel-luis/pipeloom
|
|
6
|
+
Project-URL: Documentation, https://emanuel-luis.github.io/pipeloom/
|
|
7
|
+
Project-URL: Changelog, https://github.com/emanuel-luis/pipeloom/blob/main/CHANGELOG.md
|
|
8
|
+
Author-email: Emanuel Luis <emanuel.filho08@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: assets,dagster,data-engineering,orchestration,pipelines,pipeloom
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: dagster<2,>=1.10
|
|
23
|
+
Requires-Dist: pipeloom~=1.5.0
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# pipeloom-dagster
|
|
27
|
+
|
|
28
|
+
[Dagster](https://dagster.io) integration for [pipeloom](https://github.com/emanuel-luis/pipeloom): a compiled plan becomes one `multi_asset` per execution unit.
|
|
29
|
+
|
|
30
|
+
```console
|
|
31
|
+
$ pip install "pipeloom[dagster]"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
# definitions.py
|
|
36
|
+
from pipeloom_dagster import definitions
|
|
37
|
+
|
|
38
|
+
defs = definitions("path/to/project", target="dev")
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```console
|
|
42
|
+
$ dagster dev -f definitions.py
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Reads the plan; no model code is imported while Dagster loads it.
|
|
46
|
+
- Materializing an asset runs exactly that unit (`pipeloom run --select unit:<id>`).
|
|
47
|
+
- Data tests become asset checks. Interval models get time partitions, and one partition runs exactly that window (`--partition-key`).
|
|
48
|
+
- Supports `dagster>=1.10,<2`.
|
|
49
|
+
|
|
50
|
+
Documentation: https://emanuel-luis.github.io/pipeloom/latest/plugins/dagster/
|
|
51
|
+
|
|
52
|
+
License: Apache-2.0.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# pipeloom-dagster
|
|
2
|
+
|
|
3
|
+
[Dagster](https://dagster.io) integration for [pipeloom](https://github.com/emanuel-luis/pipeloom): a compiled plan becomes one `multi_asset` per execution unit.
|
|
4
|
+
|
|
5
|
+
```console
|
|
6
|
+
$ pip install "pipeloom[dagster]"
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
# definitions.py
|
|
11
|
+
from pipeloom_dagster import definitions
|
|
12
|
+
|
|
13
|
+
defs = definitions("path/to/project", target="dev")
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```console
|
|
17
|
+
$ dagster dev -f definitions.py
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- Reads the plan; no model code is imported while Dagster loads it.
|
|
21
|
+
- Materializing an asset runs exactly that unit (`pipeloom run --select unit:<id>`).
|
|
22
|
+
- Data tests become asset checks. Interval models get time partitions, and one partition runs exactly that window (`--partition-key`).
|
|
23
|
+
- Supports `dagster>=1.10,<2`.
|
|
24
|
+
|
|
25
|
+
Documentation: https://emanuel-luis.github.io/pipeloom/latest/plugins/dagster/
|
|
26
|
+
|
|
27
|
+
License: Apache-2.0.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pipeloom-dagster"
|
|
7
|
+
version = "1.5.0"
|
|
8
|
+
description = "Dagster integration for pipeloom: a compiled plan as one multi_asset per unit."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "Emanuel Luis", email = "emanuel.filho08@gmail.com" }]
|
|
14
|
+
keywords = ["pipeloom", "dagster", "assets", "orchestration", "data-engineering", "pipelines"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = ["pipeloom~=1.5.0", "dagster>=1.10,<2"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Repository = "https://github.com/emanuel-luis/pipeloom"
|
|
29
|
+
Documentation = "https://emanuel-luis.github.io/pipeloom/"
|
|
30
|
+
Changelog = "https://github.com/emanuel-luis/pipeloom/blob/main/CHANGELOG.md"
|
|
31
|
+
|
|
32
|
+
[tool.uv.sources]
|
|
33
|
+
pipeloom = { workspace = true }
|
|
34
|
+
|
|
35
|
+
[tool.pipeloom]
|
|
36
|
+
config-version = 1
|
|
37
|
+
plugin-api = "1.2"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/pipeloom_dagster"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.sdist]
|
|
43
|
+
only-include = ["src", "tests", "LICENSE", "NOTICE", "README.md"]
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"""Build the Dagster definitions of a compiled plan (ADR-0066).
|
|
2
|
+
|
|
3
|
+
No `from __future__ import annotations` here: Dagster compares the `context` annotation to its
|
|
4
|
+
class, so a string annotation is refused.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import hashlib
|
|
8
|
+
import os
|
|
9
|
+
import re
|
|
10
|
+
from collections.abc import Mapping
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Final
|
|
13
|
+
|
|
14
|
+
import dagster as dg
|
|
15
|
+
from dagster import AssetExecutionContext
|
|
16
|
+
|
|
17
|
+
from pipeloom.artifacts.unit_graph import build_unit_graph
|
|
18
|
+
from pipeloom.config.models import IntervalConfig
|
|
19
|
+
from pipeloom.diagnostics import Report
|
|
20
|
+
from pipeloom.plan.identity import asset_path
|
|
21
|
+
from pipeloom.plan.manifest import manifest_bytes, read_manifest
|
|
22
|
+
from pipeloom.plan.model import Plan, PlanNode, PlanSelection
|
|
23
|
+
from pipeloom.runtime import intervals
|
|
24
|
+
from pipeloom_dagster.unit import UnitCommand, UnitOutcome, run_unit
|
|
25
|
+
|
|
26
|
+
DATA_TEST_CODE: Final = "PLQ303"
|
|
27
|
+
_CRON: Final = {
|
|
28
|
+
"hour": "0 * * * *",
|
|
29
|
+
"day": "0 0 * * *",
|
|
30
|
+
"week": "0 0 * * 1", # Monday, as the pipeloom week
|
|
31
|
+
"month": "0 0 1 * *",
|
|
32
|
+
"year": "0 0 1 1 *",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def asset_key(plan: Plan, node: PlanNode) -> dg.AssetKey:
|
|
37
|
+
"""project, target, then catalog (when set), schema and name of the relation: the parts of
|
|
38
|
+
the canonical dataset identity (ADR-0055)."""
|
|
39
|
+
rel, meta = node.relation, plan.metadata
|
|
40
|
+
if rel is None:
|
|
41
|
+
return dg.AssetKey(list(asset_path(meta.project, meta.target, node.name)))
|
|
42
|
+
path = asset_path(meta.project, meta.target, rel.name, rel.schema, rel.catalog)
|
|
43
|
+
return dg.AssetKey(list(path))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def partitions(interval: IntervalConfig) -> dg.TimeWindowPartitionsDefinition:
|
|
47
|
+
"""One partition per window; the key is the pipeloom partition key (ADR-0071)."""
|
|
48
|
+
spec = interval.partition_spec()
|
|
49
|
+
start = intervals.truncate(interval.begin, spec.grain).replace(tzinfo=None)
|
|
50
|
+
return dg.TimeWindowPartitionsDefinition(
|
|
51
|
+
start=start, cron_schedule=_CRON[spec.grain], fmt=spec.format, timezone="UTC"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _op_name(unit_id: str, taken: set[str]) -> str:
|
|
56
|
+
name = re.sub(r"[^A-Za-z0-9_]", "_", unit_id)
|
|
57
|
+
if name in taken:
|
|
58
|
+
name = f"{name}_{hashlib.sha256(unit_id.encode()).hexdigest()[:8]}"
|
|
59
|
+
taken.add(name)
|
|
60
|
+
return name
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _checks(node: PlanNode, key: dg.AssetKey) -> tuple[list[dg.AssetCheckSpec], dict[str, bool]]:
|
|
64
|
+
specs: list[dg.AssetCheckSpec] = []
|
|
65
|
+
blocking: dict[str, bool] = {}
|
|
66
|
+
for test in node.data_tests or ():
|
|
67
|
+
block = test.on_violation == "fail" and test.blocking is not False
|
|
68
|
+
blocking[test.name] = block
|
|
69
|
+
specs.append(
|
|
70
|
+
dg.AssetCheckSpec(
|
|
71
|
+
name=test.name,
|
|
72
|
+
asset=key,
|
|
73
|
+
blocking=block,
|
|
74
|
+
description=f"pipeloom data test, on_violation: {test.on_violation}",
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
return specs, blocking
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _results(
|
|
81
|
+
outcome: UnitOutcome, key: dg.AssetKey, blocking: Mapping[str, bool]
|
|
82
|
+
) -> list[dg.AssetCheckResult]:
|
|
83
|
+
found = {
|
|
84
|
+
e["name"]: e
|
|
85
|
+
for e in (outcome.row or {}).get("expectations", ())
|
|
86
|
+
if e.get("scope") == "table"
|
|
87
|
+
}
|
|
88
|
+
out: list[dg.AssetCheckResult] = []
|
|
89
|
+
for name, block in blocking.items():
|
|
90
|
+
sev = dg.AssetCheckSeverity.ERROR if block else dg.AssetCheckSeverity.WARN
|
|
91
|
+
e = found.get(name)
|
|
92
|
+
if e is None: # no result, no claim: Dagster records the check as not evaluated
|
|
93
|
+
continue
|
|
94
|
+
failed = int(e.get("failed") or 0)
|
|
95
|
+
out.append(
|
|
96
|
+
dg.AssetCheckResult(
|
|
97
|
+
check_name=name,
|
|
98
|
+
asset_key=key,
|
|
99
|
+
passed=failed == 0,
|
|
100
|
+
severity=sev,
|
|
101
|
+
metadata={"evaluated": True, "failed": failed, "kind": str(e.get("kind"))},
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
# A failed blocking check ends the step as soon as it is yielded (floor releases stop at the
|
|
105
|
+
# first), so it goes last and every other result is recorded first.
|
|
106
|
+
out.sort(key=lambda r: not r.passed and r.severity == dg.AssetCheckSeverity.ERROR)
|
|
107
|
+
return out
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _asset(
|
|
111
|
+
plan: Plan,
|
|
112
|
+
unit_id: str,
|
|
113
|
+
node: PlanNode,
|
|
114
|
+
key: dg.AssetKey,
|
|
115
|
+
deps: list[dg.AssetKey],
|
|
116
|
+
cmd: UnitCommand,
|
|
117
|
+
name: str,
|
|
118
|
+
retry: dg.RetryPolicy | None,
|
|
119
|
+
retry_on: str,
|
|
120
|
+
env: Mapping[str, str] | None,
|
|
121
|
+
) -> dg.AssetsDefinition:
|
|
122
|
+
interval = node.config.incremental.interval if node.config.incremental else None
|
|
123
|
+
pdef = None if interval is None else partitions(interval)
|
|
124
|
+
checks, blocking = _checks(node, key)
|
|
125
|
+
spec = dg.AssetSpec(
|
|
126
|
+
key=key,
|
|
127
|
+
deps=deps,
|
|
128
|
+
partitions_def=pdef,
|
|
129
|
+
metadata={"pipeloom/unit_id": unit_id, "pipeloom/model": node.name},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
@dg.multi_asset(
|
|
133
|
+
name=name, specs=[spec], check_specs=checks, can_subset=False, retry_policy=retry
|
|
134
|
+
)
|
|
135
|
+
def run(context: AssetExecutionContext) -> Any:
|
|
136
|
+
pkey = context.partition_key if pdef is not None and context.has_partition_key else None
|
|
137
|
+
outcome = run_unit(cmd, f"dagster-{context.run.run_id}", pkey, env)
|
|
138
|
+
error = (outcome.row or {}).get("error") or {}
|
|
139
|
+
only_tests = outcome.exit_code == 1 and error.get("code") == DATA_TEST_CODE
|
|
140
|
+
if outcome.exit_code != 0 and not only_tests:
|
|
141
|
+
raise dg.Failure(
|
|
142
|
+
description=f"unit {unit_id} exited {outcome.exit_code}: "
|
|
143
|
+
f"{error.get('code', '')} {error.get('message', '')}".strip(),
|
|
144
|
+
metadata={"output": outcome.output},
|
|
145
|
+
allow_retries=not (
|
|
146
|
+
error.get("category") == "permanent" and retry_on == "transient"
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
row = outcome.row
|
|
150
|
+
if row is None or row.get("status") == "skipped":
|
|
151
|
+
why = "no attempt file" if row is None else f"skipped: {row.get('skip_reason')}"
|
|
152
|
+
held = (row or {}).get("held_back")
|
|
153
|
+
raise dg.Failure(
|
|
154
|
+
description=f"unit {unit_id} produced nothing ({why})",
|
|
155
|
+
metadata={"output": outcome.output, "held_back": held or []},
|
|
156
|
+
)
|
|
157
|
+
yield dg.MaterializeResult(
|
|
158
|
+
asset_key=key,
|
|
159
|
+
metadata={
|
|
160
|
+
k: row[k]
|
|
161
|
+
for k in ("rows_written", "attempt", "partition_keys", "outcome")
|
|
162
|
+
if row.get(k) is not None
|
|
163
|
+
},
|
|
164
|
+
)
|
|
165
|
+
yield from _results(outcome, key, blocking)
|
|
166
|
+
|
|
167
|
+
return run
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _artifacts_root(project_dir: Path, target: str, vars_: Mapping[str, Any], env: Any) -> Path:
|
|
171
|
+
from pipeloom.api import Project, ProjectOptions
|
|
172
|
+
from pipeloom.runtime.run import artifacts_root
|
|
173
|
+
|
|
174
|
+
bound = Project(
|
|
175
|
+
ProjectOptions(project_dir=project_dir, target=target, vars=dict(vars_), env=env)
|
|
176
|
+
).bind()
|
|
177
|
+
return artifacts_root(bound.value, project_dir) if bound.value else project_dir / "target"
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _plan(
|
|
181
|
+
project_dir: Path, target: str, vars_: Mapping[str, Any], env: Any, manifest: Path | None
|
|
182
|
+
) -> tuple[Plan, Path]:
|
|
183
|
+
if manifest is not None:
|
|
184
|
+
report = Report()
|
|
185
|
+
plan = read_manifest(manifest, report)
|
|
186
|
+
if plan is None:
|
|
187
|
+
raise ValueError("; ".join(f"{d.code}: {d.message}" for d in report.sorted()))
|
|
188
|
+
return plan, manifest
|
|
189
|
+
from pipeloom.api import Project, ProjectOptions
|
|
190
|
+
|
|
191
|
+
out = Project(
|
|
192
|
+
ProjectOptions(project_dir=project_dir, target=target, vars=dict(vars_), env=env)
|
|
193
|
+
).compile()
|
|
194
|
+
if out.value is None:
|
|
195
|
+
raise ValueError("; ".join(f"{d.code}: {d.message}" for d in out.diagnostics))
|
|
196
|
+
root = _artifacts_root(project_dir, target, vars_, env)
|
|
197
|
+
path = root / "dagster" / f"{out.value.metadata.plan_hash[:16]}.manifest.json"
|
|
198
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
199
|
+
path.write_bytes(manifest_bytes(out.value, stable=True))
|
|
200
|
+
return out.value, path
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def definitions(
|
|
204
|
+
project_dir: str | os.PathLike[str],
|
|
205
|
+
target: str = "dev",
|
|
206
|
+
*,
|
|
207
|
+
manifest: str | os.PathLike[str] | None = None,
|
|
208
|
+
vars: Mapping[str, Any] | None = None,
|
|
209
|
+
) -> dg.Definitions:
|
|
210
|
+
"""One multi_asset per execution unit of the project, for `target`.
|
|
211
|
+
|
|
212
|
+
`manifest` is a file from `pipeloom compile --stable --out`; without it the project is
|
|
213
|
+
compiled here (no model code is imported) and the manifest is written under
|
|
214
|
+
`<artifacts root>/dagster/`. Each materialization runs `pipeloom run --select unit:<id>`
|
|
215
|
+
in a child process.
|
|
216
|
+
"""
|
|
217
|
+
proj = Path(project_dir).resolve()
|
|
218
|
+
env = dict(os.environ)
|
|
219
|
+
vars_ = dict(vars or {})
|
|
220
|
+
plan, mpath = _plan(proj, target, vars_, env, None if manifest is None else Path(manifest))
|
|
221
|
+
if plan.metadata.target != target:
|
|
222
|
+
raise ValueError(f"manifest was compiled for target '{plan.metadata.target}'")
|
|
223
|
+
root = _artifacts_root(proj, target, vars_, env)
|
|
224
|
+
# every model is rendered: a manifest read back carries no selection
|
|
225
|
+
whole = PlanSelection(select=(), exclude=(), selected=tuple(plan.nodes))
|
|
226
|
+
graph = build_unit_graph(plan.model_copy(update={"selection": whole}))
|
|
227
|
+
keys = {u.unit_id: asset_key(plan, plan.nodes[u.unique_id]) for u in graph.units}
|
|
228
|
+
taken: set[str] = set()
|
|
229
|
+
assets: list[dg.AssetsDefinition] = []
|
|
230
|
+
for u in graph.units:
|
|
231
|
+
node = plan.nodes[u.unique_id]
|
|
232
|
+
argv = tuple(
|
|
233
|
+
a.replace("{project_dir}", proj.as_posix()).replace("{manifest}", mpath.as_posix())
|
|
234
|
+
for a in u.argv
|
|
235
|
+
)
|
|
236
|
+
cmd = UnitCommand(u.unit_id, argv, root, bool(node.data_tests))
|
|
237
|
+
assets.append(
|
|
238
|
+
_asset(
|
|
239
|
+
plan,
|
|
240
|
+
u.unit_id,
|
|
241
|
+
node,
|
|
242
|
+
keys[u.unit_id],
|
|
243
|
+
[keys[p] for p in u.parents],
|
|
244
|
+
cmd,
|
|
245
|
+
_op_name(u.unit_id, taken),
|
|
246
|
+
dg.RetryPolicy(max_retries=u.retries, delay=u.retry_delay_s) if u.retries else None,
|
|
247
|
+
u.retry_on,
|
|
248
|
+
env,
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
# ponytail: vars are baked into the manifest, so units are not given --vars
|
|
252
|
+
return dg.Definitions(assets=assets)
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Run one unit in a child process and read what it left behind (ADR-0049 protocol)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from collections.abc import Mapping, Sequence
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from pipeloom.artifacts.layout import RunPaths
|
|
14
|
+
|
|
15
|
+
TAIL = 4000
|
|
16
|
+
"""Characters of the child's output kept in a failure message."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class UnitCommand:
|
|
21
|
+
"""Everything a materialization needs to run its unit."""
|
|
22
|
+
|
|
23
|
+
unit_id: str
|
|
24
|
+
argv: tuple[str, ...]
|
|
25
|
+
"""The unit graph argv with `{project_dir}` and `{manifest}` filled; `{run_id}` is not."""
|
|
26
|
+
artifacts_root: Path
|
|
27
|
+
data_tests: bool
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class UnitOutcome:
|
|
32
|
+
exit_code: int
|
|
33
|
+
row: Mapping[str, Any] | None
|
|
34
|
+
"""The newest attempt row of the unit in this run, if the child wrote one."""
|
|
35
|
+
output: str
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def command(cmd: UnitCommand, run_id: str, partition_key: str | None) -> list[str]:
|
|
39
|
+
argv = [a.replace("{run_id}", run_id) for a in cmd.argv]
|
|
40
|
+
assert argv[:2] == ["pipeloom", "run"]
|
|
41
|
+
extra = ["--orchestrator-id", f"dagster_run_id={run_id.removeprefix('dagster-')}"]
|
|
42
|
+
if cmd.data_tests:
|
|
43
|
+
extra += ["--data-tests", "true"]
|
|
44
|
+
if partition_key is not None:
|
|
45
|
+
extra += ["--partition-key", partition_key]
|
|
46
|
+
return [sys.executable, "-m", "pipeloom", "run", *argv[2:], *extra]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def latest_attempt(root: Path, run_id: str, unit_id: str) -> Mapping[str, Any] | None:
|
|
50
|
+
paths = RunPaths(root, run_id)
|
|
51
|
+
numbers = paths.attempt_numbers(unit_id)
|
|
52
|
+
if not numbers:
|
|
53
|
+
return None
|
|
54
|
+
doc = json.loads(paths.attempt(unit_id, numbers[-1]).read_text(encoding="utf-8"))
|
|
55
|
+
return doc if isinstance(doc, dict) else None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def run_unit(
|
|
59
|
+
cmd: UnitCommand,
|
|
60
|
+
run_id: str,
|
|
61
|
+
partition_key: str | None,
|
|
62
|
+
env: Mapping[str, str] | None = None,
|
|
63
|
+
extra_args: Sequence[str] = (),
|
|
64
|
+
) -> UnitOutcome:
|
|
65
|
+
# ponytail: subprocess.run kills the child on KeyboardInterrupt only; no SIGTERM grace.
|
|
66
|
+
done = subprocess.run(
|
|
67
|
+
[*command(cmd, run_id, partition_key), *extra_args],
|
|
68
|
+
capture_output=True,
|
|
69
|
+
text=True,
|
|
70
|
+
encoding="utf-8",
|
|
71
|
+
errors="replace",
|
|
72
|
+
env=None if env is None else dict(env),
|
|
73
|
+
check=False,
|
|
74
|
+
)
|
|
75
|
+
row = latest_attempt(cmd.artifacts_root, run_id, cmd.unit_id)
|
|
76
|
+
return UnitOutcome(done.returncode, row, (done.stdout + done.stderr)[-TAIL:])
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"""The Dagster definitions of a project, and materializing them in process (ADR-0066)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from datetime import UTC, datetime, timedelta
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import dagster as dg
|
|
10
|
+
import polars as pl
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
from pipeloom_dagster import definitions
|
|
14
|
+
|
|
15
|
+
EXAMPLES = Path(__file__).resolve().parents[3] / "examples"
|
|
16
|
+
T0 = datetime(2026, 1, 1, tzinfo=UTC)
|
|
17
|
+
PROJECT = """\
|
|
18
|
+
config_version: 1
|
|
19
|
+
name: shop
|
|
20
|
+
python_paths: [models]
|
|
21
|
+
sources:
|
|
22
|
+
- name: raw
|
|
23
|
+
tables:
|
|
24
|
+
- {name: events, format: parquet, location: raw}
|
|
25
|
+
targets:
|
|
26
|
+
dev:
|
|
27
|
+
engine: {kind: polars}
|
|
28
|
+
catalog: {kind: filesystem, root: wh}
|
|
29
|
+
state: {kind: json, path: .pipeloom/state}
|
|
30
|
+
naming: {kind: none}
|
|
31
|
+
"""
|
|
32
|
+
MODELS = """\
|
|
33
|
+
from pipeloom import model, ref, source
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@model(
|
|
37
|
+
inputs={"raw": source("raw", "events")},
|
|
38
|
+
materialized="incremental",
|
|
39
|
+
incremental={
|
|
40
|
+
"input": "raw",
|
|
41
|
+
"interval": {"event_time": "ts", "grain": "day", "begin": "2026-01-01"},
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
def daily(ctx, raw):
|
|
45
|
+
return raw
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@model(inputs={"raw": source("raw", "events")}, materialized="table", retries=2, retry_delay=3)
|
|
49
|
+
def plain(ctx, raw):
|
|
50
|
+
return raw
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@model(retries=1, retry_delay=0)
|
|
54
|
+
def broken(ctx):
|
|
55
|
+
raise ValueError("bad data")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@model(retries=1, retry_delay=0, retry_on="any")
|
|
59
|
+
def broken_any(ctx):
|
|
60
|
+
raise ValueError("bad data")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@model(
|
|
64
|
+
inputs={"p": ref("plain")},
|
|
65
|
+
materialized="table",
|
|
66
|
+
data_tests=[
|
|
67
|
+
{"name": "id_unique", "check": {"unique": ["id"]}},
|
|
68
|
+
{"name": "id_unique_open", "check": {"unique": ["id"]}, "blocking": False},
|
|
69
|
+
{"name": "id_not_null", "check": {"not_null": ["id"]}},
|
|
70
|
+
],
|
|
71
|
+
)
|
|
72
|
+
def checked(ctx, p):
|
|
73
|
+
return p
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.fixture
|
|
78
|
+
def project(tmp_path: Path) -> Path:
|
|
79
|
+
(tmp_path / "models").mkdir()
|
|
80
|
+
(tmp_path / "pipeloom.yml").write_text(PROJECT, encoding="utf-8")
|
|
81
|
+
(tmp_path / "models" / "m.py").write_text(MODELS, encoding="utf-8")
|
|
82
|
+
ts = [T0 + timedelta(days=d, hours=h) for d in range(3) for h in (1, 3)]
|
|
83
|
+
(tmp_path / "raw").mkdir()
|
|
84
|
+
frame = pl.DataFrame({"ts": ts, "id": [1, 1, 2, 3, 4, 5]})
|
|
85
|
+
frame.write_parquet(tmp_path / "raw" / "events.parquet")
|
|
86
|
+
return tmp_path
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def key(name: str) -> dg.AssetKey:
|
|
90
|
+
return dg.AssetKey(["shop", "dev", "main", name])
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def assets_of(defs: dg.Definitions) -> list[dg.AssetsDefinition]:
|
|
94
|
+
return [a for a in defs.assets or () if isinstance(a, dg.AssetsDefinition)]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def ran(project: Path, run_id: str) -> set[str]:
|
|
98
|
+
units = project / "target" / "runs" / f"dagster-{run_id}" / "units"
|
|
99
|
+
return {p.name for p in units.iterdir()} if units.is_dir() else set()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_one_asset_per_unit_with_lineage(project: Path) -> None:
|
|
103
|
+
defs = definitions(project, "dev")
|
|
104
|
+
specs = {s.key: s for a in assets_of(defs) for s in a.specs}
|
|
105
|
+
assert set(specs) == {
|
|
106
|
+
key("daily"),
|
|
107
|
+
key("plain"),
|
|
108
|
+
key("checked"),
|
|
109
|
+
key("broken"),
|
|
110
|
+
key("broken_any"),
|
|
111
|
+
}
|
|
112
|
+
assert {d.asset_key for d in specs[key("checked")].deps} == {key("plain")}
|
|
113
|
+
assert specs[key("daily")].partitions_def is not None
|
|
114
|
+
assert specs[key("plain")].partitions_def is None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_partition_keys_follow_the_spec(project: Path) -> None:
|
|
118
|
+
defs = definitions(project, "dev")
|
|
119
|
+
spec = next(s for a in assets_of(defs) for s in a.specs if s.key == key("daily"))
|
|
120
|
+
pdef = spec.partitions_def
|
|
121
|
+
assert isinstance(pdef, dg.TimeWindowPartitionsDefinition)
|
|
122
|
+
assert pdef.get_partition_keys()[:3] == ["2026-01-01", "2026-01-02", "2026-01-03"]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def test_manifest_argument_is_used(project: Path) -> None:
|
|
126
|
+
first = definitions(project, "dev")
|
|
127
|
+
manifest = next((project / "target" / "dagster").glob("*.manifest.json"))
|
|
128
|
+
again = definitions(project, "dev", manifest=manifest)
|
|
129
|
+
assert json.loads(manifest.read_text(encoding="utf-8"))["metadata"]["target"] == "dev"
|
|
130
|
+
assert len(assets_of(again)) == len(assets_of(first))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_materializing_one_asset_runs_exactly_that_unit(project: Path) -> None:
|
|
134
|
+
defs = definitions(project, "dev")
|
|
135
|
+
result = dg.materialize(assets_of(defs), selection=[key("plain")])
|
|
136
|
+
assert result.success
|
|
137
|
+
assert ran(project, result.run_id) == {"plain"}
|
|
138
|
+
assert (project / "wh").exists()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_a_failing_data_test_is_a_failed_check(project: Path) -> None:
|
|
142
|
+
defs = definitions(project, "dev")
|
|
143
|
+
assets = assets_of(defs)
|
|
144
|
+
dg.materialize(assets, selection=[key("plain")])
|
|
145
|
+
result = dg.materialize(assets, selection=[key("checked")], raise_on_error=False)
|
|
146
|
+
checks = {c.check_name: c for c in result.get_asset_check_evaluations()}
|
|
147
|
+
assert set(checks) == {"id_unique", "id_unique_open", "id_not_null"}
|
|
148
|
+
assert not checks["id_unique"].passed
|
|
149
|
+
assert checks["id_unique"].severity == dg.AssetCheckSeverity.ERROR
|
|
150
|
+
assert not checks["id_unique_open"].passed
|
|
151
|
+
assert checks["id_unique_open"].severity == dg.AssetCheckSeverity.WARN
|
|
152
|
+
assert checks["id_not_null"].passed
|
|
153
|
+
assert ran(project, result.run_id) == {"checked"}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_one_partition_runs_exactly_that_window(project: Path) -> None:
|
|
157
|
+
defs = definitions(project, "dev")
|
|
158
|
+
result = dg.materialize(assets_of(defs), selection=[key("daily")], partition_key="2026-01-02")
|
|
159
|
+
assert result.success
|
|
160
|
+
assert ran(project, result.run_id) == {"daily"}
|
|
161
|
+
attempt = next(
|
|
162
|
+
(project / "target" / "runs" / f"dagster-{result.run_id}" / "units" / "daily").glob(
|
|
163
|
+
"*.json"
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
assert json.loads(attempt.read_text(encoding="utf-8"))["partition_keys"] == ["2026-01-02"]
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def test_the_tpch_polars_example_loads_with_one_asset_per_model() -> None:
|
|
170
|
+
if not (EXAMPLES / "tpch_polars").is_dir():
|
|
171
|
+
pytest.skip("examples/ is not in this source tree")
|
|
172
|
+
defs = definitions(EXAMPLES / "tpch_polars", "dev")
|
|
173
|
+
n = sum(len(list(a.specs)) for a in assets_of(defs))
|
|
174
|
+
assert n == len(assets_of(defs)) == 9 # the nine models of the example
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def test_asset_keys_come_from_the_identity_helper() -> None:
|
|
178
|
+
from pipeloom.plan.identity import asset_path
|
|
179
|
+
|
|
180
|
+
assert asset_path("p", "t", "n") == ("p", "t", "n")
|
|
181
|
+
assert asset_path("p", "t", "n", "s") == ("p", "t", "s", "n")
|
|
182
|
+
assert asset_path("p", "t", "n", "s", "c") == ("p", "t", "c", "s", "n")
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def test_model_retries_become_a_retry_policy(project: Path) -> None:
|
|
186
|
+
defs = definitions(project, "dev")
|
|
187
|
+
policy = {a.op.name: a.op.retry_policy for a in assets_of(defs)}
|
|
188
|
+
plain = policy["plain"]
|
|
189
|
+
assert plain is not None and plain.max_retries == 2 and plain.delay == 3
|
|
190
|
+
assert policy["daily"] is None
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_a_partition_held_back_by_its_upstream_is_a_failure(project: Path) -> None:
|
|
194
|
+
# reviewer repro: a downstream window alone, before its upstream ran, is skipped by the gate
|
|
195
|
+
(project / "models" / "down.py").write_text(
|
|
196
|
+
"from pipeloom import model, ref\n\n\n@model(\n inputs={'d': ref('daily')},\n"
|
|
197
|
+
" materialized='incremental',\n incremental={'input': 'd', 'interval': "
|
|
198
|
+
"{'event_time': 'ts', 'grain': 'day', 'begin': '2026-01-01'}},\n data_tests=[{'name': "
|
|
199
|
+
"'t', 'check': {'not_null': ['id']}}],\n)\ndef down(ctx, d):\n return d\n",
|
|
200
|
+
encoding="utf-8",
|
|
201
|
+
)
|
|
202
|
+
defs = definitions(project, "dev")
|
|
203
|
+
result = dg.materialize(
|
|
204
|
+
assets_of(defs),
|
|
205
|
+
selection=[key("down")],
|
|
206
|
+
partition_key="2026-01-02",
|
|
207
|
+
raise_on_error=False,
|
|
208
|
+
)
|
|
209
|
+
assert not result.success
|
|
210
|
+
failure = next(e for e in result.all_events if e.is_step_failure)
|
|
211
|
+
assert "skipped: upstream_incomplete" in str(failure.event_specific_data.error) # type: ignore[union-attr]
|
|
212
|
+
assert not result.get_asset_materialization_events()
|
|
213
|
+
assert not result.get_asset_check_evaluations()
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_a_partition_already_in_the_ledger_does_no_work(project: Path) -> None:
|
|
217
|
+
defs = definitions(project, "dev")
|
|
218
|
+
for _ in range(2):
|
|
219
|
+
result = dg.materialize(
|
|
220
|
+
assets_of(defs), selection=[key("daily")], partition_key="2026-01-02"
|
|
221
|
+
)
|
|
222
|
+
assert result.success
|
|
223
|
+
assert len(result.get_asset_materialization_events()) == 1
|
|
224
|
+
attempt = next(
|
|
225
|
+
(project / "target" / "runs" / f"dagster-{result.run_id}" / "units" / "daily").glob(
|
|
226
|
+
"*.json"
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
assert json.loads(attempt.read_text(encoding="utf-8"))["outcome"] == "up_to_date"
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
@pytest.mark.parametrize(("name", "retried"), [("broken", False), ("broken_any", True)])
|
|
233
|
+
def test_retry_on_decides_whether_a_permanent_failure_is_retried(
|
|
234
|
+
project: Path, name: str, retried: bool
|
|
235
|
+
) -> None:
|
|
236
|
+
defs = definitions(project, "dev")
|
|
237
|
+
result = dg.materialize(assets_of(defs), selection=[key(name)], raise_on_error=False)
|
|
238
|
+
assert not result.success
|
|
239
|
+
kinds = {e.event_type_value for e in result.all_events}
|
|
240
|
+
assert ("STEP_UP_FOR_RETRY" in kinds) is retried
|