continuo-python-runtime 0.15.0__py3-none-any.whl → 0.16.0__py3-none-any.whl
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.
- continuo_python_runtime/validation/dependents_check.py +30 -39
- continuo_python_runtime/validation/drop_dependents.py +170 -0
- continuo_python_runtime/validation/runner.py +16 -10
- continuo_python_runtime/validation/warehouse_read.py +29 -7
- {continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/METADATA +70 -24
- {continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/RECORD +10 -9
- {continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/WHEEL +0 -0
- {continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/entry_points.txt +0 -0
- {continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/licenses/LICENSE +0 -0
- {continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -25,10 +25,13 @@ from continuo_python_runtime.validation.warehouse_read import (
|
|
|
25
25
|
Discover,
|
|
26
26
|
InputError,
|
|
27
27
|
close_quietly,
|
|
28
|
+
declared_drop_semantics,
|
|
28
29
|
discover_and_check_env,
|
|
29
30
|
emit,
|
|
30
31
|
first_line,
|
|
31
32
|
json_list,
|
|
33
|
+
seed_node_id,
|
|
34
|
+
seed_relation,
|
|
32
35
|
)
|
|
33
36
|
|
|
34
37
|
logger = logging.getLogger("validation_dependents_check")
|
|
@@ -64,7 +67,6 @@ class Verdict:
|
|
|
64
67
|
|
|
65
68
|
def decide(
|
|
66
69
|
mode: str,
|
|
67
|
-
family: str,
|
|
68
70
|
situation: Situation,
|
|
69
71
|
*,
|
|
70
72
|
detail: str = "",
|
|
@@ -73,16 +75,19 @@ def decide(
|
|
|
73
75
|
) -> Verdict:
|
|
74
76
|
"""The decision table of ``dependents_check``.
|
|
75
77
|
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
``
|
|
81
|
-
|
|
78
|
+
*detail* is the text that explains the situation, *completeness* the
|
|
79
|
+
adapter's own and *has_unowned* whether a listed object is outside the
|
|
80
|
+
allowed set. The table is the same on every engine family: a reload stops
|
|
81
|
+
on an object continuo does not own whether the engine's drop destroys it
|
|
82
|
+
(``schema_bound``) or leaves it reading a re-created table
|
|
83
|
+
(``late_binding``). A situation that a ``check`` stops on gives ``error``
|
|
84
|
+
and exit 1; ``report`` mode gives the same ``reason`` on a ``success`` block
|
|
85
|
+
and exit 0. A bad input is exit 2 in both modes. A ``reason`` prefixes the
|
|
86
|
+
message.
|
|
82
87
|
"""
|
|
83
88
|
if situation is Situation.BAD_INPUT:
|
|
84
89
|
return Verdict("error", "", 2, False, "none", detail)
|
|
85
|
-
reason, stops = _conclusion(
|
|
90
|
+
reason, stops = _conclusion(situation, has_unowned)
|
|
86
91
|
failed = stops and mode == "check"
|
|
87
92
|
return Verdict(
|
|
88
93
|
status="error" if failed else "success",
|
|
@@ -94,18 +99,17 @@ def decide(
|
|
|
94
99
|
)
|
|
95
100
|
|
|
96
101
|
|
|
97
|
-
def _conclusion(
|
|
102
|
+
def _conclusion(situation: Situation, has_unowned: bool) -> tuple[str, bool]:
|
|
98
103
|
"""The ``reason`` a situation carries and whether a ``check`` stops on it."""
|
|
99
|
-
schema_bound = family == "schema_bound"
|
|
100
104
|
if situation is Situation.ENGINE_MISMATCH:
|
|
101
105
|
return "engine_mismatch", True
|
|
102
106
|
if situation is Situation.UNREACHABLE:
|
|
103
107
|
return "warehouse_unreachable", True
|
|
104
108
|
if situation is Situation.NO_CAPABILITY:
|
|
105
|
-
return
|
|
109
|
+
return "unowned_dependents", True
|
|
106
110
|
if situation is Situation.LISTING_FAILED:
|
|
107
|
-
return "",
|
|
108
|
-
if
|
|
111
|
+
return "", True
|
|
112
|
+
if has_unowned:
|
|
109
113
|
return "unowned_dependents", True
|
|
110
114
|
return "", False
|
|
111
115
|
|
|
@@ -121,12 +125,6 @@ class _SeedInputs:
|
|
|
121
125
|
allowed: frozenset[str]
|
|
122
126
|
|
|
123
127
|
|
|
124
|
-
def _seed_node_id(env: Mapping[str, str]) -> str:
|
|
125
|
-
"""``NODE_ID``, else ``<PROD_SCHEMA>.<TABLE_NAME>`` when both are set, else ``""``."""
|
|
126
|
-
schema, table = env.get("PROD_SCHEMA", ""), env.get("TABLE_NAME", "")
|
|
127
|
-
return env.get("NODE_ID") or (f"{schema}.{table}" if schema and table else "")
|
|
128
|
-
|
|
129
|
-
|
|
130
128
|
def _seed_inputs(env: Mapping[str, str]) -> _SeedInputs:
|
|
131
129
|
mode = env.get("DEPENDENTS_CHECK_MODE", "")
|
|
132
130
|
if mode not in _MODES:
|
|
@@ -136,16 +134,14 @@ def _seed_inputs(env: Mapping[str, str]) -> _SeedInputs:
|
|
|
136
134
|
raise InputError(
|
|
137
135
|
f"DEPENDENTS_CHECK_ENGINE_FAMILY must be one of {', '.join(_FAMILIES)}, got {family!r}"
|
|
138
136
|
)
|
|
139
|
-
|
|
140
|
-
if not env.get(name):
|
|
141
|
-
raise InputError(f"missing required env var {name}")
|
|
137
|
+
schema, table = seed_relation(env)
|
|
142
138
|
allowed = json_list(env, "DEPENDENTS_CHECK_ALLOWED", required=False)
|
|
143
139
|
acknowledged = json_list(env, "DEPENDENTS_CHECK_ACKNOWLEDGED", required=False)
|
|
144
140
|
return _SeedInputs(
|
|
145
141
|
mode=mode,
|
|
146
142
|
family=family,
|
|
147
|
-
schema=
|
|
148
|
-
table=
|
|
143
|
+
schema=schema,
|
|
144
|
+
table=table,
|
|
149
145
|
allowed=frozenset(entry.strip().lower() for entry in [*allowed, *acknowledged]),
|
|
150
146
|
)
|
|
151
147
|
|
|
@@ -168,7 +164,7 @@ def _finish_seed(
|
|
|
168
164
|
env: Mapping[str, str], drop_semantics: str, verdict: Verdict,
|
|
169
165
|
dependents: list[dict[str, Any]] | None = None,
|
|
170
166
|
) -> int:
|
|
171
|
-
node_id =
|
|
167
|
+
node_id = seed_node_id(env)
|
|
172
168
|
if verdict.exit_code == 2:
|
|
173
169
|
logger.error("dependents_check %s: %s", node_id, verdict.message)
|
|
174
170
|
elif verdict.reason or verdict.exit_code:
|
|
@@ -192,7 +188,7 @@ def run_dependents_check(
|
|
|
192
188
|
try:
|
|
193
189
|
return _dependents_check(env, discover)
|
|
194
190
|
except Exception as exc:
|
|
195
|
-
logger.exception("dependents_check %s failed unexpectedly",
|
|
191
|
+
logger.exception("dependents_check %s failed unexpectedly", seed_node_id(env))
|
|
196
192
|
verdict = Verdict("error", "", 2, False, "none", f"unexpected error: {first_line(exc)}")
|
|
197
193
|
return _finish_seed(env, "", verdict)
|
|
198
194
|
|
|
@@ -202,10 +198,9 @@ def _dependents_check(env: Mapping[str, str], discover: Discover) -> int:
|
|
|
202
198
|
inputs = _seed_inputs(env)
|
|
203
199
|
engine, adapter_cls = discover_and_check_env(env, discover)
|
|
204
200
|
except InputError as exc:
|
|
205
|
-
return _finish_seed(env, "", decide("",
|
|
201
|
+
return _finish_seed(env, "", decide("", Situation.BAD_INPUT, detail=str(exc)))
|
|
206
202
|
|
|
207
|
-
|
|
208
|
-
drop_semantics = declared if isinstance(declared, str) else ""
|
|
203
|
+
drop_semantics = declared_drop_semantics(adapter_cls)
|
|
209
204
|
adapter_family = _FAMILY_OF_DROP_SEMANTICS.get(drop_semantics)
|
|
210
205
|
|
|
211
206
|
def finish(
|
|
@@ -213,7 +208,7 @@ def _dependents_check(env: Mapping[str, str], discover: Discover) -> int:
|
|
|
213
208
|
has_unowned: bool = False, dependents: list[dict[str, Any]] | None = None,
|
|
214
209
|
) -> int:
|
|
215
210
|
verdict = decide(
|
|
216
|
-
inputs.mode,
|
|
211
|
+
inputs.mode, situation,
|
|
217
212
|
detail=detail, completeness=completeness, has_unowned=has_unowned,
|
|
218
213
|
)
|
|
219
214
|
return _finish_seed(env, drop_semantics, verdict, dependents)
|
|
@@ -250,15 +245,11 @@ def _dependents_check(env: Mapping[str, str], discover: Discover) -> int:
|
|
|
250
245
|
finally:
|
|
251
246
|
close_quietly(adapter)
|
|
252
247
|
outside = [d for d in dependents if not d["allowed"]]
|
|
253
|
-
if inputs.family == "schema_bound"
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
detail = (
|
|
259
|
-
f"{len(outside)} external view(s) may go stale; recreate them after the reload: "
|
|
260
|
-
+ ", ".join(f"{d['schema']}.{d['name']}" for d in outside)
|
|
261
|
-
)
|
|
248
|
+
effect = "would drop" if inputs.family == "schema_bound" else "may break"
|
|
249
|
+
detail = f"the reload {effect} objects continuo does not own: " + ", ".join(
|
|
250
|
+
f"{d['schema']}.{d['name']} ({d['kind']}" + (f", owner {d['owner']})" if d["owner"] else ")")
|
|
251
|
+
for d in outside
|
|
252
|
+
)
|
|
262
253
|
return finish(
|
|
263
254
|
Situation.LISTED, detail if outside else "",
|
|
264
255
|
completeness=listing.completeness, has_unowned=bool(outside), dependents=dependents,
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""The ``drop_dependents`` validation op.
|
|
2
|
+
|
|
3
|
+
On a ``late_binding`` engine a drop of a seed's table destroys nothing else, so
|
|
4
|
+
after a reload the objects an operator acknowledged as reading the seed are
|
|
5
|
+
still there. ``drop_dependents`` drops each acknowledged object that still reads
|
|
6
|
+
the seed, through the adapter's ``DependentsRemoval``: deepest first, and an
|
|
7
|
+
object the listing no longer ties to the seed is skipped and never dropped. On a
|
|
8
|
+
``cascade`` engine the load's ``DROP ... CASCADE`` already removed them, so the
|
|
9
|
+
op drops nothing.
|
|
10
|
+
|
|
11
|
+
The block and the exit codes follow
|
|
12
|
+
:mod:`~continuo_python_runtime.validation.warehouse_read`: 0 when every object
|
|
13
|
+
was dropped or skipped, 1 when a drop failed or nothing could be tried (an
|
|
14
|
+
unreachable warehouse, a failed listing), 2 when the op could not run.
|
|
15
|
+
"""
|
|
16
|
+
import logging
|
|
17
|
+
from collections.abc import Mapping
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from typing import Any, cast
|
|
20
|
+
|
|
21
|
+
from continuo_engine_contract.port import ( # type: ignore[import-untyped]
|
|
22
|
+
DependentsRemoval,
|
|
23
|
+
DroppedDependents,
|
|
24
|
+
discover_adapter,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from continuo_python_runtime.validation.warehouse_read import (
|
|
28
|
+
Discover,
|
|
29
|
+
InputError,
|
|
30
|
+
close_quietly,
|
|
31
|
+
declared_drop_semantics,
|
|
32
|
+
discover_and_check_env,
|
|
33
|
+
emit,
|
|
34
|
+
first_line,
|
|
35
|
+
json_list,
|
|
36
|
+
seed_node_id,
|
|
37
|
+
seed_relation,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
logger = logging.getLogger("validation_drop_dependents")
|
|
41
|
+
|
|
42
|
+
# The env var naming the objects to drop.
|
|
43
|
+
_OBJECTS_VAR = "DROP_DEPENDENTS_OBJECTS"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class _DropInputs:
|
|
48
|
+
schema: str
|
|
49
|
+
table: str
|
|
50
|
+
objects: list[str]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _drop_inputs(env: Mapping[str, str]) -> _DropInputs:
|
|
54
|
+
schema, table = seed_relation(env)
|
|
55
|
+
objects = json_list(env, _OBJECTS_VAR, required=True)
|
|
56
|
+
for entry in objects:
|
|
57
|
+
entry_schema, dot, entry_name = entry.strip().partition(".")
|
|
58
|
+
if not dot or not entry_schema or not entry_name:
|
|
59
|
+
raise InputError(f"{_OBJECTS_VAR} entry {entry!r} is not <schema>.<name>")
|
|
60
|
+
return _DropInputs(schema, table, objects)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _fields(drop_semantics: str, outcome: DroppedDependents | None) -> dict[str, Any]:
|
|
64
|
+
dropped = outcome.dropped if outcome else ()
|
|
65
|
+
failed = outcome.failed if outcome else ()
|
|
66
|
+
return {
|
|
67
|
+
"op": "drop_dependents",
|
|
68
|
+
"drop_semantics": drop_semantics,
|
|
69
|
+
"dropped": [
|
|
70
|
+
{"schema": d.schema, "name": d.name, "kind": d.kind, "depth": d.depth} for d in dropped
|
|
71
|
+
],
|
|
72
|
+
"skipped": list(outcome.skipped) if outcome else [],
|
|
73
|
+
"failed": [
|
|
74
|
+
{
|
|
75
|
+
"schema": f.dependent.schema, "name": f.dependent.name, "kind": f.dependent.kind,
|
|
76
|
+
"depth": f.dependent.depth, "error": first_line(f.error),
|
|
77
|
+
}
|
|
78
|
+
for f in failed
|
|
79
|
+
],
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _finish(
|
|
84
|
+
env: Mapping[str, str], code: int, message: str, drop_semantics: str = "", *,
|
|
85
|
+
reason: str = "", outcome: DroppedDependents | None = None,
|
|
86
|
+
) -> int:
|
|
87
|
+
node_id = seed_node_id(env)
|
|
88
|
+
if code == 2:
|
|
89
|
+
logger.error("drop_dependents %s: %s", node_id, message)
|
|
90
|
+
elif code or message:
|
|
91
|
+
logger.warning("drop_dependents %s: %s", node_id, message)
|
|
92
|
+
emit("error" if code else "success", message, node_id, reason, _fields(drop_semantics, outcome))
|
|
93
|
+
return code
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def run_drop_dependents(env: Mapping[str, str], discover: Discover = discover_adapter) -> int:
|
|
97
|
+
"""Run ``drop_dependents`` against *env*; print its one block and return the exit code.
|
|
98
|
+
|
|
99
|
+
Reads ``PROD_SCHEMA``, ``TABLE_NAME``, ``DROP_DEPENDENTS_OBJECTS`` and the
|
|
100
|
+
adapter's ``required_env()`` from *env* (adapters connect from ``os.environ``,
|
|
101
|
+
so the runner passes that). An unexpected error still prints one ``error``
|
|
102
|
+
block and returns 2.
|
|
103
|
+
"""
|
|
104
|
+
try:
|
|
105
|
+
return _drop_dependents(env, discover)
|
|
106
|
+
except Exception as exc:
|
|
107
|
+
logger.exception("drop_dependents %s failed unexpectedly", seed_node_id(env))
|
|
108
|
+
return _finish(env, 2, f"unexpected error: {first_line(exc)}")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _drop_dependents(env: Mapping[str, str], discover: Discover) -> int:
|
|
112
|
+
try:
|
|
113
|
+
inputs = _drop_inputs(env)
|
|
114
|
+
engine, adapter_cls = discover_and_check_env(env, discover)
|
|
115
|
+
except InputError as exc:
|
|
116
|
+
return _finish(env, 2, str(exc))
|
|
117
|
+
seed = f"{inputs.schema}.{inputs.table}"
|
|
118
|
+
drop_semantics = declared_drop_semantics(adapter_cls)
|
|
119
|
+
if drop_semantics == "cascade":
|
|
120
|
+
logger.info("drop_dependents %s: engine %r drops with CASCADE; nothing to drop", seed, engine)
|
|
121
|
+
return _finish(
|
|
122
|
+
env, 0,
|
|
123
|
+
f"engine {engine!r} drops with CASCADE: the load's drop of {seed} already removed "
|
|
124
|
+
f"the objects that read it",
|
|
125
|
+
drop_semantics,
|
|
126
|
+
)
|
|
127
|
+
if drop_semantics != "late_binding":
|
|
128
|
+
return _finish(
|
|
129
|
+
env, 2, f"engine {engine!r} declares no known drop_semantics, got {drop_semantics!r}",
|
|
130
|
+
drop_semantics,
|
|
131
|
+
)
|
|
132
|
+
if not issubclass(adapter_cls, DependentsRemoval):
|
|
133
|
+
return _finish(
|
|
134
|
+
env, 2, f"engine {engine!r} cannot drop the objects that read a table", drop_semantics
|
|
135
|
+
)
|
|
136
|
+
if not inputs.objects:
|
|
137
|
+
return _finish(env, 0, "", drop_semantics)
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
adapter = adapter_cls.from_env()
|
|
141
|
+
except Exception as exc:
|
|
142
|
+
return _finish(
|
|
143
|
+
env, 1, f"warehouse_unreachable: {first_line(exc)}", drop_semantics,
|
|
144
|
+
reason="warehouse_unreachable",
|
|
145
|
+
)
|
|
146
|
+
try:
|
|
147
|
+
outcome = cast(DependentsRemoval, adapter).drop_dependents(
|
|
148
|
+
inputs.schema, inputs.table, inputs.objects
|
|
149
|
+
)
|
|
150
|
+
except Exception as exc:
|
|
151
|
+
return _finish(
|
|
152
|
+
env, 1, f"listing the objects that read {seed} failed: {first_line(exc)}",
|
|
153
|
+
drop_semantics,
|
|
154
|
+
)
|
|
155
|
+
finally:
|
|
156
|
+
close_quietly(adapter)
|
|
157
|
+
|
|
158
|
+
for dependent in outcome.dropped:
|
|
159
|
+
logger.info("drop_dependents %s: dropped %s.%s", seed, dependent.schema, dependent.name)
|
|
160
|
+
notes = []
|
|
161
|
+
if outcome.failed:
|
|
162
|
+
notes.append("drop_failed: could not drop " + ", ".join(
|
|
163
|
+
f"{f.dependent.schema}.{f.dependent.name} ({first_line(f.error)})" for f in outcome.failed
|
|
164
|
+
))
|
|
165
|
+
if outcome.skipped:
|
|
166
|
+
notes.append(f"not dropped, they do not read {seed}: " + ", ".join(outcome.skipped))
|
|
167
|
+
return _finish(
|
|
168
|
+
env, 1 if outcome.failed else 0, "; ".join(notes), drop_semantics,
|
|
169
|
+
reason="drop_failed" if outcome.failed else "", outcome=outcome,
|
|
170
|
+
)
|
|
@@ -28,6 +28,10 @@ Dispatches on ``VALIDATION_OP`` env var (default ``build_from_sql``):
|
|
|
28
28
|
allowed and acknowledged lists. Needs no ``DBT_TARGET_SCHEMA`` and creates nothing.
|
|
29
29
|
- ``probe_views``: try each view of ``PROBE_VIEWS`` with a zero-row read and report
|
|
30
30
|
which ones no longer bind. Needs no ``DBT_TARGET_SCHEMA`` and creates nothing.
|
|
31
|
+
- ``drop_dependents``: after a seed's production table is reloaded on a
|
|
32
|
+
``late_binding`` engine, drop each object of ``DROP_DEPENDENTS_OBJECTS`` that still
|
|
33
|
+
reads it (``PROD_SCHEMA``.``TABLE_NAME``), deepest first. Needs no
|
|
34
|
+
``DBT_TARGET_SCHEMA``; on a ``cascade`` engine it drops nothing.
|
|
31
35
|
The inputs and the result block of each op are in its own module.
|
|
32
36
|
|
|
33
37
|
The engine adapter is discovered from the single installed
|
|
@@ -49,7 +53,7 @@ from continuo_engine_contract.port import ( # type: ignore[import-untyped]
|
|
|
49
53
|
)
|
|
50
54
|
from continuo_python_runtime.csv_readers import reader_for
|
|
51
55
|
from continuo_python_runtime.csv_source import check_header, parse_csv_uri
|
|
52
|
-
from continuo_python_runtime.validation import dependents_check, probe_views, s3
|
|
56
|
+
from continuo_python_runtime.validation import dependents_check, drop_dependents, probe_views, s3
|
|
53
57
|
|
|
54
58
|
logger = logging.getLogger("validation_runner")
|
|
55
59
|
|
|
@@ -121,7 +125,12 @@ def load_candidate_spec() -> dict:
|
|
|
121
125
|
|
|
122
126
|
_NODE_OPS = ("build_from_sql", "build_from_prod", "build_from_columns", "check_binds")
|
|
123
127
|
_SCHEMA_OPS = ("ensure_schema", "drop_schema")
|
|
124
|
-
|
|
128
|
+
# The ops on a seed's dependents: each reads its own inputs and needs no candidate schema.
|
|
129
|
+
_DEPENDENTS_OPS = {
|
|
130
|
+
"dependents_check": dependents_check.run_dependents_check,
|
|
131
|
+
"probe_views": probe_views.run_probe_views,
|
|
132
|
+
"drop_dependents": drop_dependents.run_drop_dependents,
|
|
133
|
+
}
|
|
125
134
|
|
|
126
135
|
|
|
127
136
|
def main() -> None:
|
|
@@ -135,8 +144,8 @@ def main() -> None:
|
|
|
135
144
|
Schema ops (``ensure_schema``/``drop_schema``) act on the whole candidate
|
|
136
145
|
schema — the executor schedules them as one-shot engine-image Jobs to own
|
|
137
146
|
the candidate-schema lifecycle without connecting to the warehouse itself —
|
|
138
|
-
and take no table. The
|
|
139
|
-
|
|
147
|
+
and take no table. The ops on a seed's dependents (``dependents_check``,
|
|
148
|
+
``probe_views``, ``drop_dependents``) read their own inputs, need no
|
|
140
149
|
candidate schema and exit with the code their own module's function
|
|
141
150
|
returns. An unknown op is refused before any input is read.
|
|
142
151
|
"""
|
|
@@ -144,18 +153,15 @@ def main() -> None:
|
|
|
144
153
|
level=logging.INFO, stream=sys.stderr, format="%(levelname)s %(name)s: %(message)s"
|
|
145
154
|
)
|
|
146
155
|
op = os.environ.get("VALIDATION_OP", "build_from_sql")
|
|
147
|
-
if op not in (*_NODE_OPS, *_SCHEMA_OPS, *
|
|
156
|
+
if op not in (*_NODE_OPS, *_SCHEMA_OPS, *_DEPENDENTS_OPS):
|
|
148
157
|
target_schema = os.environ.get("DBT_TARGET_SCHEMA", "")
|
|
149
158
|
unique_id = _node_id() or (f"schema.{target_schema}" if target_schema else "")
|
|
150
159
|
logger.error("unknown VALIDATION_OP %r", op)
|
|
151
160
|
print(result.result_block("error", f"unknown VALIDATION_OP {op!r}",
|
|
152
161
|
unique_id=unique_id), flush=True)
|
|
153
162
|
sys.exit(2)
|
|
154
|
-
if op in
|
|
155
|
-
|
|
156
|
-
code = dependents_check.run_dependents_check(os.environ)
|
|
157
|
-
else:
|
|
158
|
-
code = probe_views.run_probe_views(os.environ)
|
|
163
|
+
if op in _DEPENDENTS_OPS:
|
|
164
|
+
code = _DEPENDENTS_OPS[op](os.environ)
|
|
159
165
|
if code:
|
|
160
166
|
sys.exit(code)
|
|
161
167
|
return
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
"""What the warehouse
|
|
1
|
+
"""What the warehouse ops on a seed's dependents share: their inputs, their one block and their adapter.
|
|
2
2
|
|
|
3
3
|
The ops ``dependents_check`` (:mod:`~continuo_python_runtime.validation.dependents_check`)
|
|
4
4
|
and ``probe_views`` (:mod:`~continuo_python_runtime.validation.probe_views`) read the
|
|
5
|
-
warehouse and change nothing
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
warehouse and change nothing; ``drop_dependents``
|
|
6
|
+
(:mod:`~continuo_python_runtime.validation.drop_dependents`) drops the objects an
|
|
7
|
+
operator acknowledged. Each prints exactly one structured result block as the
|
|
8
|
+
last line on stdout (``continuo_engine_contract.result``) and returns the process
|
|
9
|
+
exit code: 0 when the op ran to its conclusion, 1 when a ``check`` stops or a
|
|
10
|
+
drop fails, 2 when the op could not run (a bad input, no adapter, missing adapter
|
|
11
|
+
env, an unexpected error). The block's ``status`` is ``error`` for exit codes 1
|
|
12
|
+
and 2. Diagnostics go to stderr through ``logging``; stdout carries only the block.
|
|
11
13
|
"""
|
|
12
14
|
import json
|
|
13
15
|
import logging
|
|
@@ -32,6 +34,26 @@ class InputError(Exception):
|
|
|
32
34
|
"""An input of the op is missing or malformed."""
|
|
33
35
|
|
|
34
36
|
|
|
37
|
+
def seed_node_id(env: Mapping[str, str]) -> str:
|
|
38
|
+
"""``NODE_ID``, else ``<PROD_SCHEMA>.<TABLE_NAME>`` when both are set, else ``""``."""
|
|
39
|
+
schema, table = env.get("PROD_SCHEMA", ""), env.get("TABLE_NAME", "")
|
|
40
|
+
return env.get("NODE_ID") or (f"{schema}.{table}" if schema and table else "")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def seed_relation(env: Mapping[str, str]) -> tuple[str, str]:
|
|
44
|
+
"""The seed's production relation, ``(PROD_SCHEMA, TABLE_NAME)``; both are required."""
|
|
45
|
+
for name in ("PROD_SCHEMA", "TABLE_NAME"):
|
|
46
|
+
if not env.get(name):
|
|
47
|
+
raise InputError(f"missing required env var {name}")
|
|
48
|
+
return env["PROD_SCHEMA"], env["TABLE_NAME"]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def declared_drop_semantics(adapter_cls: type) -> str:
|
|
52
|
+
"""The adapter class's ``drop_semantics``, or ``""`` when it declares none (or not a string)."""
|
|
53
|
+
declared = getattr(adapter_cls, "drop_semantics", "")
|
|
54
|
+
return declared if isinstance(declared, str) else ""
|
|
55
|
+
|
|
56
|
+
|
|
35
57
|
def first_line(exc: BaseException) -> str:
|
|
36
58
|
"""The first line of an exception's text, at most ``MAX_TEXT`` characters, never empty."""
|
|
37
59
|
text = str(exc).strip()
|
{continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: continuo-python-runtime
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.16.0
|
|
4
4
|
Summary: Runtime harness, contract tooling, and CI lint for Continuo python nodes.
|
|
5
5
|
Author: Simone Carolini
|
|
6
6
|
Maintainer: Simone Carolini
|
|
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
13
13
|
Requires-Python: >=3.14
|
|
14
14
|
Requires-Dist: boto3==1.43.114
|
|
15
15
|
Requires-Dist: continuo-contracts==0.5.0
|
|
16
|
-
Requires-Dist: continuo-engine-contract==0.
|
|
16
|
+
Requires-Dist: continuo-engine-contract==0.12.0
|
|
17
17
|
Requires-Dist: pyarrow==26.0.0
|
|
18
18
|
Requires-Dist: pyyaml==6.0.3
|
|
19
19
|
Requires-Dist: sqlglot==30.23.0
|
|
@@ -115,8 +115,8 @@ last line of stdout, and Continuo's Go side parses it byte-for-byte
|
|
|
115
115
|
sentinel markers, the framing, and the field names inside the block — is
|
|
116
116
|
**frozen**. The additions are an optional `reason` key, written after
|
|
117
117
|
`unique_id` only when an outcome has a machine-readable code (for example
|
|
118
|
-
`image_contract_mismatch`), and the op's own keys that the `dependents_check
|
|
119
|
-
`probe_views` ops write after `reason`; a block without either keeps its bytes,
|
|
118
|
+
`image_contract_mismatch`), and the op's own keys that the `dependents_check`,
|
|
119
|
+
`probe_views` and `drop_dependents` ops write after `reason`; a block without either keeps its bytes,
|
|
120
120
|
and the sentinels, `schema_version` and the five standard keys do not change. Reuse
|
|
121
121
|
it; never change it from this side alone. A change here that
|
|
122
122
|
the Go parser has not been taught is a production outage, not a refactor.
|
|
@@ -554,11 +554,11 @@ A domain repo picks its warehouse engine by which base image it builds
|
|
|
554
554
|
`FROM`:
|
|
555
555
|
|
|
556
556
|
```dockerfile
|
|
557
|
-
FROM ghcr.io/carolsimone/continuo-python-runtime-postgres:v0.
|
|
557
|
+
FROM ghcr.io/carolsimone/continuo-python-runtime-postgres:v0.16.0
|
|
558
558
|
# or
|
|
559
|
-
FROM ghcr.io/carolsimone/continuo-python-runtime-trino:v0.
|
|
559
|
+
FROM ghcr.io/carolsimone/continuo-python-runtime-trino:v0.16.0
|
|
560
560
|
# or
|
|
561
|
-
FROM ghcr.io/carolsimone/continuo-python-runtime-duckdb:v0.
|
|
561
|
+
FROM ghcr.io/carolsimone/continuo-python-runtime-duckdb:v0.16.0
|
|
562
562
|
```
|
|
563
563
|
|
|
564
564
|
The engine is part of the image **name**; the tag is the bare version, so
|
|
@@ -599,20 +599,30 @@ Both shapes end up running the same runtime and the same adapter version;
|
|
|
599
599
|
which one you pick only changes who controls the base OS layer underneath
|
|
600
600
|
them.
|
|
601
601
|
|
|
602
|
-
## Dependents check and
|
|
602
|
+
## Dependents check, view probe and dependents drop
|
|
603
603
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
604
|
+
Three validation ops act on what reads a seed. `dependents_check` and
|
|
605
|
+
`probe_views` read the warehouse and change nothing; `drop_dependents` drops the
|
|
606
|
+
objects an operator acknowledged. They run through the same runner image as the
|
|
607
|
+
other validation ops (`VALIDATION_OP`), need no `DBT_TARGET_SCHEMA`, and print
|
|
608
|
+
one result block as the last line of stdout.
|
|
607
609
|
|
|
608
610
|
A seed reload drops and recreates the seed's production table. On an engine where
|
|
609
611
|
a drop destroys the objects that read the table (`drop_semantics` `cascade`,
|
|
610
612
|
postgres) that takes every view, function and constraint built on the seed with
|
|
611
613
|
it, including objects continuo does not own. On an engine where those objects
|
|
612
614
|
survive and fail on their next read (`late_binding`, trino and duckdb) they
|
|
613
|
-
may
|
|
614
|
-
with what the operator has allowed or
|
|
615
|
-
|
|
615
|
+
may break once the table's columns change. `dependents_check` lists what a
|
|
616
|
+
reload would touch and compares it with what the operator has allowed or
|
|
617
|
+
acknowledged; `drop_dependents` removes the acknowledged objects after a reload
|
|
618
|
+
on a `late_binding` engine, as `DROP ... CASCADE` already does on postgres;
|
|
619
|
+
`probe_views` tries named views after a reload and says which no longer bind.
|
|
620
|
+
|
|
621
|
+
Postgres lists every kind of object that reads the seed, exactly (a recursive
|
|
622
|
+
`pg_depend` walk). Trino and duckdb list every view that reads it directly or
|
|
623
|
+
through other views, at its depth, by parsing each view's SQL
|
|
624
|
+
(`best_effort`: a view built from dynamic SQL, or one in another catalog, is
|
|
625
|
+
missed); see the adapters' READMEs.
|
|
616
626
|
|
|
617
627
|
`dependents_check` runs in two places. `check` runs in the seed task's own pod just
|
|
618
628
|
before dbt and stops the reload with exit 1 when the check concludes it must.
|
|
@@ -649,17 +659,53 @@ After the standard keys (and `reason` when one applies): `op` (`dependents_check
|
|
|
649
659
|
|---|---|---|---|
|
|
650
660
|
| a missing or malformed input, no adapter, missing adapter env | none | exit 2 | exit 2 |
|
|
651
661
|
| the adapter's family differs from `DEPENDENTS_CHECK_ENGINE_FAMILY`, or it declares none | `engine_mismatch` | exit 1 | exit 0 |
|
|
652
|
-
| the adapter cannot list dependents
|
|
653
|
-
| the adapter cannot list dependents, `late_binding` | none | exit 0 | exit 0 |
|
|
662
|
+
| the adapter cannot list dependents | `unowned_dependents` | exit 1 | exit 0 |
|
|
654
663
|
| the connection fails | `warehouse_unreachable` | exit 1 | exit 0 |
|
|
655
|
-
| the listing fails
|
|
656
|
-
|
|
|
657
|
-
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
664
|
+
| the listing fails | none | exit 1 | exit 0 |
|
|
665
|
+
| listed, an object is not allowed | `unowned_dependents` | exit 1 | exit 0 |
|
|
666
|
+
| anything else listed | none | exit 0 | exit 0 |
|
|
667
|
+
|
|
668
|
+
The table is the same on both families: a reload stops on an object continuo
|
|
669
|
+
does not own whether the engine's drop destroys it (`schema_bound`) or leaves
|
|
670
|
+
it reading a re-created table (`late_binding`). A seed table that does not
|
|
671
|
+
exist yet has no dependents and passes. A stop's `message` starts with its
|
|
672
|
+
`reason` and names each object outside the set as `<schema>.<name> (<kind>,
|
|
673
|
+
owner <owner>)`, or `<schema>.<name> (<kind>)` when the engine records no
|
|
674
|
+
owner.
|
|
675
|
+
|
|
676
|
+
### `drop_dependents`
|
|
677
|
+
|
|
678
|
+
Runs after a seed's reload succeeds on a `late_binding` engine, with the
|
|
679
|
+
objects the operator acknowledged. Its inputs:
|
|
680
|
+
|
|
681
|
+
| Variable | Meaning |
|
|
682
|
+
|---|---|
|
|
683
|
+
| `PROD_SCHEMA`, `TABLE_NAME` | The seed's production relation. |
|
|
684
|
+
| `DROP_DEPENDENTS_OBJECTS` | Required JSON array of `"<schema>.<name>"`, split on the first dot. `[]` drops nothing and does not connect. |
|
|
685
|
+
| `NODE_ID` | Optional; the block's `unique_id`. Default `<PROD_SCHEMA>.<TABLE_NAME>`. |
|
|
686
|
+
|
|
687
|
+
The op lists the seed's dependents once and drops each requested object the
|
|
688
|
+
listing holds, deepest first, through the adapter's `DependentsRemoval`. An
|
|
689
|
+
entry matches a listed object when, trimmed and in lower case, it equals
|
|
690
|
+
`<schema>.<name>` in lower case. An entry the listing does not hold is skipped
|
|
691
|
+
and never dropped: the op drops nothing it cannot tie to the seed. A drop that
|
|
692
|
+
fails does not stop the others. On a `cascade` engine (postgres) it drops
|
|
693
|
+
nothing and does not connect: the load's `DROP ... CASCADE` already removed the
|
|
694
|
+
objects, and `message` says so.
|
|
695
|
+
|
|
696
|
+
The block has `op` (`drop_dependents`), `drop_semantics` (the adapter's),
|
|
697
|
+
`dropped` (`{schema, name, kind, depth}` in the order dropped), `skipped` (the
|
|
698
|
+
entries as given) and `failed` (`{schema, name, kind, depth, error}`, `error`
|
|
699
|
+
the first line of the failure, at most 500 characters). `message` names each
|
|
700
|
+
failed and skipped object.
|
|
701
|
+
|
|
702
|
+
| Situation | `reason` | exit |
|
|
703
|
+
|---|---|---|
|
|
704
|
+
| a missing or malformed input, no adapter, missing adapter env, a `late_binding` adapter that is not a `DependentsRemoval`, an adapter with no known `drop_semantics`, an unexpected error | none | 2 |
|
|
705
|
+
| the connection fails; nothing is dropped | `warehouse_unreachable` | 1 |
|
|
706
|
+
| the listing fails; nothing is dropped | none | 1 |
|
|
707
|
+
| a drop failed | `drop_failed` | 1 |
|
|
708
|
+
| every object dropped or skipped, a `cascade` engine, or no objects | none | 0 |
|
|
663
709
|
|
|
664
710
|
### `probe_views`
|
|
665
711
|
|
{continuo_python_runtime-0.15.0.dist-info → continuo_python_runtime-0.16.0.dist-info}/RECORD
RENAMED
|
@@ -26,14 +26,15 @@ continuo_python_runtime/csv_readers/__init__.py,sha256=9TKvjC37C77uRaJQZuO0--zVj
|
|
|
26
26
|
continuo_python_runtime/csv_readers/https.py,sha256=tMJ9k5F0b9SAydpon0ZlOznfjvjhF2BBLltyVmvRneE,4998
|
|
27
27
|
continuo_python_runtime/csv_readers/s3.py,sha256=zmvHs3TxlN2alPKrdaHzPyREmkve2nBiAsHRXXe1mE0,2246
|
|
28
28
|
continuo_python_runtime/validation/__init__.py,sha256=hz5oGXsoaUoygR0_pBby9PS6cEfrre518EE0HGB58eE,79
|
|
29
|
-
continuo_python_runtime/validation/dependents_check.py,sha256=
|
|
29
|
+
continuo_python_runtime/validation/dependents_check.py,sha256=jeJlopEu0s6eg-F0h6lEab3C5lSjNfNA3-RZ2QMiIn8,9432
|
|
30
|
+
continuo_python_runtime/validation/drop_dependents.py,sha256=Nk_RuWfQHsc2F80Gma7yex1AKrqtS0ZZPRc8EdkOsUg,6366
|
|
30
31
|
continuo_python_runtime/validation/probe_views.py,sha256=rFN6cImJ0hQ1mdjvR766NPIezQdf3FKNnt4rli7pdeQ,3897
|
|
31
|
-
continuo_python_runtime/validation/runner.py,sha256=
|
|
32
|
+
continuo_python_runtime/validation/runner.py,sha256=_XI2MC6BCMhINo8RDvJbKpkkwNxWcODn972WNjyTG5Q,15726
|
|
32
33
|
continuo_python_runtime/validation/s3.py,sha256=q8nRrT9R7L1-M4dSlDnkL7CUJMPmq86MHY_UKYFlEf8,1785
|
|
33
|
-
continuo_python_runtime/validation/warehouse_read.py,sha256=
|
|
34
|
-
continuo_python_runtime-0.
|
|
35
|
-
continuo_python_runtime-0.
|
|
36
|
-
continuo_python_runtime-0.
|
|
37
|
-
continuo_python_runtime-0.
|
|
38
|
-
continuo_python_runtime-0.
|
|
39
|
-
continuo_python_runtime-0.
|
|
34
|
+
continuo_python_runtime/validation/warehouse_read.py,sha256=rxL7UtBqXQSE7KSQgeNLxFoSDb_DA0gI6uzkPNI2WxM,4537
|
|
35
|
+
continuo_python_runtime-0.16.0.dist-info/METADATA,sha256=5cJNsKBQKvppu4Obby7tZBuDwIR777fG-0HPLyN-a_w,41854
|
|
36
|
+
continuo_python_runtime-0.16.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
37
|
+
continuo_python_runtime-0.16.0.dist-info/entry_points.txt,sha256=ZvIwSm9f9B9ZmZMf6CyF5Zt4QONn8rqaIk-u-B1CF2Y,70
|
|
38
|
+
continuo_python_runtime-0.16.0.dist-info/licenses/LICENSE,sha256=hfXfFCk-8gnps4YvHA6bjCNaSYqOrq2gAdqkXYycAQc,11345
|
|
39
|
+
continuo_python_runtime-0.16.0.dist-info/licenses/NOTICE,sha256=ykgYyQkAMx3uas90FZHzt0aTca9IgJQCLpZ4d74Pl3U,465
|
|
40
|
+
continuo_python_runtime-0.16.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|