map-conform 0.1.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.
- map_conform/__init__.py +5 -0
- map_conform/__main__.py +7 -0
- map_conform/batch/__init__.py +1 -0
- map_conform/batch/arrow.py +80 -0
- map_conform/batch/columnar.py +125 -0
- map_conform/batch/engine.py +191 -0
- map_conform/batch/files.py +207 -0
- map_conform/cli.py +460 -0
- map_conform/doctor.py +178 -0
- map_conform/errors.py +107 -0
- map_conform/expr/__init__.py +6 -0
- map_conform/expr/compiler.py +562 -0
- map_conform/expr/functions.py +542 -0
- map_conform/expr/sandbox.py +333 -0
- map_conform/expr/sdk.py +116 -0
- map_conform/map-conform-spec.schema.json +1204 -0
- map_conform/mapper.py +355 -0
- map_conform/metadata.py +73 -0
- map_conform/metrics.py +62 -0
- map_conform/naming/__init__.py +1 -0
- map_conform/naming/ascii-table.json +980 -0
- map_conform/naming/conform.py +262 -0
- map_conform/naming/flatten.py +148 -0
- map_conform/naming/nested.py +117 -0
- map_conform/naming/reserved/ansi.txt +369 -0
- map_conform/naming/reserved/duckdb.txt +114 -0
- map_conform/naming/reserved/postgres.txt +105 -0
- map_conform/naming/reserved/snowflake.txt +90 -0
- map_conform/naming/reserved.py +34 -0
- map_conform/naming/shape.py +96 -0
- map_conform/naming/streams.py +76 -0
- map_conform/naming/translit.py +170 -0
- map_conform/plan/__init__.py +1 -0
- map_conform/plan/chain.py +667 -0
- map_conform/plan/compile.py +551 -0
- map_conform/plan/lower.py +281 -0
- map_conform/plan/ops.py +336 -0
- map_conform/plan/row.py +212 -0
- map_conform/plan/vector.py +71 -0
- map_conform/rejects.py +92 -0
- map_conform/settings.py +157 -0
- map_conform/spec/__init__.py +1 -0
- map_conform/spec/_struct.py +483 -0
- map_conform/spec/bridge.py +109 -0
- map_conform/spec/check.py +380 -0
- map_conform/spec/errors.py +22 -0
- map_conform/spec/importer.py +87 -0
- map_conform/spec/jsonschema.py +54 -0
- map_conform/spec/load.py +357 -0
- map_conform/spec/model.py +473 -0
- map_conform/spec/reference.py +179 -0
- map_conform/spec/steps.py +297 -0
- map_conform/spec/stream_maps.py +233 -0
- map_conform/spec/zamboni.py +99 -0
- map_conform/transforms/__init__.py +1 -0
- map_conform/transforms/builtins.py +63 -0
- map_conform/transforms/casts.py +310 -0
- map_conform/transforms/fake.py +150 -0
- map_conform/transforms/nested.py +111 -0
- map_conform/transforms/numeric.py +318 -0
- map_conform/transforms/polars_vector.py +151 -0
- map_conform/transforms/privacy.py +220 -0
- map_conform/transforms/registry.py +116 -0
- map_conform/transforms/temporal.py +410 -0
- map_conform/transforms/text.py +249 -0
- map_conform/transforms/vector.py +386 -0
- map_conform/types/__init__.py +1 -0
- map_conform/types/canonical.py +255 -0
- map_conform/types/from_jsonschema.py +177 -0
- map_conform/types/jsontext.py +63 -0
- map_conform/types/to_arrow.py +52 -0
- map_conform/types/to_jsonschema.py +65 -0
- map_conform/types/wire.py +53 -0
- map_conform/udfs.py +327 -0
- map_conform-0.1.0.dist-info/METADATA +157 -0
- map_conform-0.1.0.dist-info/RECORD +79 -0
- map_conform-0.1.0.dist-info/WHEEL +4 -0
- map_conform-0.1.0.dist-info/entry_points.txt +2 -0
- map_conform-0.1.0.dist-info/licenses/LICENSE +201 -0
map_conform/spec/load.py
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"""Load a conform spec and resolve the rules for each stream (detailed design §3.1).
|
|
2
|
+
|
|
3
|
+
Loading is: read YAML or JSON -> deep-merge the inline ``spec`` setting over it ->
|
|
4
|
+
substitute ``${var}`` / ``${env:NAME}`` -> strict parse. Resolving a tap stream merges, by
|
|
5
|
+
presence, ``defaults`` -> every matching glob from least to most specific -> the exact name;
|
|
6
|
+
objects merge key by key and lists replace whole.
|
|
7
|
+
|
|
8
|
+
YAML is read with YAML 1.2 core-schema scalars. PyYAML's YAML 1.1 defaults would turn
|
|
9
|
+
``yes``/``no``/``on``/``off`` (and the country code ``NO``) into booleans and ``1:30`` into 90,
|
|
10
|
+
which corrupts value lists such as ``true_values``. Duplicate keys are an error.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
import sys
|
|
19
|
+
from collections.abc import Mapping
|
|
20
|
+
from dataclasses import dataclass
|
|
21
|
+
from fnmatch import fnmatchcase
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import TYPE_CHECKING, Any
|
|
24
|
+
|
|
25
|
+
import yaml
|
|
26
|
+
|
|
27
|
+
from map_conform.spec._struct import (
|
|
28
|
+
Issue,
|
|
29
|
+
Issues,
|
|
30
|
+
child,
|
|
31
|
+
dump,
|
|
32
|
+
freeze_mapping,
|
|
33
|
+
parse_dataclass,
|
|
34
|
+
thaw,
|
|
35
|
+
)
|
|
36
|
+
from map_conform.spec.errors import SpecError
|
|
37
|
+
from map_conform.spec.model import (
|
|
38
|
+
DEFAULTS_KEYS,
|
|
39
|
+
STREAM_KEYS,
|
|
40
|
+
Defaults,
|
|
41
|
+
Spec,
|
|
42
|
+
StreamSpec,
|
|
43
|
+
parse_spec,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
if sys.version_info >= (3, 12):
|
|
47
|
+
from typing import override
|
|
48
|
+
else:
|
|
49
|
+
from typing_extensions import override
|
|
50
|
+
|
|
51
|
+
if TYPE_CHECKING:
|
|
52
|
+
from yaml.nodes import MappingNode
|
|
53
|
+
|
|
54
|
+
_VAR = re.compile(r"\$\$\{|\$\{(env:)?([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}")
|
|
55
|
+
_GLOB_CHARS = frozenset("*?[")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# --- Reading ----------------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class _Yaml12Loader(yaml.SafeLoader):
|
|
62
|
+
"""SafeLoader with YAML 1.2 core-schema scalars and no duplicate keys."""
|
|
63
|
+
|
|
64
|
+
yaml_implicit_resolvers: dict[str, list[tuple[str, re.Pattern[str]]]] = {} # noqa: RUF012 -- PyYAML's class-level registry
|
|
65
|
+
|
|
66
|
+
@override
|
|
67
|
+
def construct_mapping(self, node: MappingNode, deep: bool = False) -> dict[Any, Any]:
|
|
68
|
+
"""Build a mapping, rejecting duplicate keys."""
|
|
69
|
+
seen: set[object] = set()
|
|
70
|
+
for key_node, _ in node.value:
|
|
71
|
+
key = self.construct_object(key_node, deep=deep)
|
|
72
|
+
if key in seen:
|
|
73
|
+
mark = key_node.start_mark
|
|
74
|
+
msg = f"duplicate key {key!r}"
|
|
75
|
+
raise yaml.constructor.ConstructorError(None, None, msg, mark)
|
|
76
|
+
seen.add(key)
|
|
77
|
+
return super().construct_mapping(node, deep=deep)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
for _tag, _pattern, _first in [
|
|
81
|
+
("tag:yaml.org,2002:null", r"^(?:~|null|Null|NULL|)$", ["~", "n", "N", ""]),
|
|
82
|
+
("tag:yaml.org,2002:bool", r"^(?:true|True|TRUE|false|False|FALSE)$", list("tTfF")),
|
|
83
|
+
(
|
|
84
|
+
"tag:yaml.org,2002:int",
|
|
85
|
+
r"^(?:[-+]?[0-9]+|0o[0-7]+|0x[0-9a-fA-F]+)$",
|
|
86
|
+
list("-+0123456789"),
|
|
87
|
+
),
|
|
88
|
+
(
|
|
89
|
+
"tag:yaml.org,2002:float",
|
|
90
|
+
(
|
|
91
|
+
r"^(?:[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][-+]?[0-9]+)?"
|
|
92
|
+
r"|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$"
|
|
93
|
+
),
|
|
94
|
+
list("-+.0123456789"),
|
|
95
|
+
),
|
|
96
|
+
]:
|
|
97
|
+
_Yaml12Loader.add_implicit_resolver(_tag, re.compile(_pattern), _first)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _construct_int(loader: yaml.SafeLoader, node: yaml.ScalarNode) -> int:
|
|
101
|
+
text = loader.construct_scalar(node)
|
|
102
|
+
# Base 0 reads the 0o/0x prefixes; plain digits are decimal even with a leading zero.
|
|
103
|
+
return int(text, 0) if text.startswith(("0o", "0x")) else int(text, 10)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
_Yaml12Loader.add_constructor("tag:yaml.org,2002:int", _construct_int)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def read_document(path: str | Path) -> object:
|
|
110
|
+
"""Read a YAML (``.yaml``/``.yml``) or JSON (``.json``) spec file.
|
|
111
|
+
|
|
112
|
+
Raises:
|
|
113
|
+
SpecError: if the file cannot be read or parsed.
|
|
114
|
+
"""
|
|
115
|
+
path = Path(path)
|
|
116
|
+
source = str(path)
|
|
117
|
+
try:
|
|
118
|
+
text = path.read_text(encoding="utf-8")
|
|
119
|
+
except OSError as exc:
|
|
120
|
+
raise SpecError([Issue("", f"cannot read the spec: {exc.strerror}")], source) from exc
|
|
121
|
+
if path.suffix.lower() == ".json":
|
|
122
|
+
try:
|
|
123
|
+
return json.loads(text)
|
|
124
|
+
except json.JSONDecodeError as exc:
|
|
125
|
+
where = f"line {exc.lineno}, column {exc.colno}"
|
|
126
|
+
raise SpecError([Issue("", f"invalid JSON at {where}: {exc.msg}")], source) from exc
|
|
127
|
+
if path.suffix.lower() not in {".yaml", ".yml"}:
|
|
128
|
+
raise SpecError([Issue("", "the spec must be .yaml, .yml or .json")], source)
|
|
129
|
+
try:
|
|
130
|
+
return yaml.load(text, Loader=_Yaml12Loader) # noqa: S506 -- a SafeLoader subclass
|
|
131
|
+
except yaml.YAMLError as exc:
|
|
132
|
+
mark = getattr(exc, "problem_mark", None)
|
|
133
|
+
where = f" at line {mark.line + 1}, column {mark.column + 1}" if mark else ""
|
|
134
|
+
problem = getattr(exc, "problem", None) or str(exc)
|
|
135
|
+
raise SpecError([Issue("", f"invalid YAML{where}: {problem}")], source) from exc
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
# --- Merging and substitution -------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def deep_merge(base: object, override: object) -> object:
|
|
142
|
+
"""Merge by presence: mappings merge key by key; anything else (lists too) replaces."""
|
|
143
|
+
if isinstance(base, Mapping) and isinstance(override, Mapping):
|
|
144
|
+
merged = dict(base)
|
|
145
|
+
for key, value in override.items():
|
|
146
|
+
merged[key] = deep_merge(base[key], value) if key in base else value
|
|
147
|
+
return merged
|
|
148
|
+
return override
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def substitute(
|
|
152
|
+
data: object,
|
|
153
|
+
variables: Mapping[str, object],
|
|
154
|
+
env: Mapping[str, str],
|
|
155
|
+
issues: Issues,
|
|
156
|
+
) -> object:
|
|
157
|
+
"""Replace ``${name}``, ``${env:NAME}`` and ``${env:NAME:-default}`` in every string.
|
|
158
|
+
|
|
159
|
+
A string that is exactly one ``${name}`` takes the variable's value with its type; inside
|
|
160
|
+
other text the value is formatted. ``$${`` writes a literal ``${``. A macro's own
|
|
161
|
+
parameters are left for expansion. Unknown names are recorded in ``issues``.
|
|
162
|
+
"""
|
|
163
|
+
return _Substituter(variables, env, issues).walk(data, "", frozenset())
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@dataclass(frozen=True)
|
|
167
|
+
class _Substituter:
|
|
168
|
+
variables: Mapping[str, object]
|
|
169
|
+
env: Mapping[str, str]
|
|
170
|
+
issues: Issues
|
|
171
|
+
|
|
172
|
+
def walk(self, data: object, path: str, keep: frozenset[str]) -> object:
|
|
173
|
+
if isinstance(data, Mapping):
|
|
174
|
+
out: dict[str, object] = {}
|
|
175
|
+
for key, value in data.items():
|
|
176
|
+
inner = keep
|
|
177
|
+
if path == "macros" and isinstance(value, Mapping): # the macro's parameters
|
|
178
|
+
inner = keep | frozenset(value.get("params") or {})
|
|
179
|
+
out[key] = self.walk(value, child(path, key), inner)
|
|
180
|
+
return out
|
|
181
|
+
if isinstance(data, list):
|
|
182
|
+
return [self.walk(v, child(path, i), keep) for i, v in enumerate(data)]
|
|
183
|
+
if isinstance(data, str):
|
|
184
|
+
whole = _VAR.fullmatch(data)
|
|
185
|
+
if whole and whole.group(0) != "$${":
|
|
186
|
+
return self.value(whole, path, keep)
|
|
187
|
+
return _VAR.sub(lambda m: _format(self.value(m, path, keep)), data)
|
|
188
|
+
return data
|
|
189
|
+
|
|
190
|
+
def value(self, match: re.Match[str], path: str, keep: frozenset[str]) -> object:
|
|
191
|
+
if match.group(0) == "$${":
|
|
192
|
+
return "${"
|
|
193
|
+
is_env, name, default = match.group(1), match.group(2), match.group(3)
|
|
194
|
+
found: Mapping[str, object] = self.env if is_env else self.variables
|
|
195
|
+
if name in found:
|
|
196
|
+
return found[name]
|
|
197
|
+
if not is_env and name in keep:
|
|
198
|
+
return match.group(0)
|
|
199
|
+
if default is not None:
|
|
200
|
+
return default
|
|
201
|
+
if is_env:
|
|
202
|
+
self.issues.add(path, f"environment variable {name!r} is not set")
|
|
203
|
+
else:
|
|
204
|
+
self.issues.add(path, f"unknown variable ${{{name}}}; set it in spec_vars")
|
|
205
|
+
return match.group(0)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _format(value: object) -> str:
|
|
209
|
+
if isinstance(value, bool):
|
|
210
|
+
return "true" if value else "false"
|
|
211
|
+
if value is None:
|
|
212
|
+
return ""
|
|
213
|
+
return value if isinstance(value, str) else json.dumps(value)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def load_spec(
|
|
217
|
+
path: str | Path | None = None,
|
|
218
|
+
inline: Mapping[str, object] | None = None,
|
|
219
|
+
spec_vars: Mapping[str, object] | None = None,
|
|
220
|
+
env: Mapping[str, str] | None = None,
|
|
221
|
+
*,
|
|
222
|
+
base: Mapping[str, object] | None = None,
|
|
223
|
+
) -> Spec:
|
|
224
|
+
"""Load, merge, substitute and strictly parse a spec.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
path: The spec file (``spec_path``).
|
|
228
|
+
inline: An inline spec (the ``spec`` setting), deep-merged over the file.
|
|
229
|
+
spec_vars: Values for ``${name}``.
|
|
230
|
+
env: The environment for ``${env:NAME}``; defaults to ``os.environ``.
|
|
231
|
+
base: A spec merged *under* the others after substitution: the translated SDK
|
|
232
|
+
``stream_maps``, whose expressions must not be substituted.
|
|
233
|
+
|
|
234
|
+
Raises:
|
|
235
|
+
SpecError: listing every problem, each with its path.
|
|
236
|
+
"""
|
|
237
|
+
if path is None and inline is None and base is None:
|
|
238
|
+
raise SpecError([Issue("", "no spec: set spec_path or spec")])
|
|
239
|
+
document: object = read_document(path) if path is not None else {}
|
|
240
|
+
if inline is not None:
|
|
241
|
+
document = deep_merge(document, thaw(inline))
|
|
242
|
+
issues = Issues()
|
|
243
|
+
document = substitute(document, spec_vars or {}, os.environ if env is None else env, issues)
|
|
244
|
+
base_dir = Path(path).parent if path is not None else Path.cwd()
|
|
245
|
+
document = _read_shapes(document, base_dir, issues)
|
|
246
|
+
source = str(path) if path is not None else "the inline spec"
|
|
247
|
+
if base is not None:
|
|
248
|
+
document = deep_merge(thaw(base), document)
|
|
249
|
+
source = "the spec and stream_maps" if path or inline else "the stream_maps settings"
|
|
250
|
+
if issues:
|
|
251
|
+
raise SpecError(issues.items, source)
|
|
252
|
+
return parse_spec(document, source)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def _read_shapes(document: object, base_dir: Path, issues: Issues) -> object:
|
|
256
|
+
"""Replace each column ``shape`` given as a file path with the JSON Schema it holds."""
|
|
257
|
+
streams = document.get("streams") if isinstance(document, dict) else None
|
|
258
|
+
if not isinstance(streams, dict):
|
|
259
|
+
return document
|
|
260
|
+
for key, rules in streams.items():
|
|
261
|
+
columns = rules.get("columns") if isinstance(rules, dict) else None
|
|
262
|
+
for name, column in (columns or {}).items() if isinstance(columns, dict) else ():
|
|
263
|
+
shape = column.get("shape") if isinstance(column, dict) else None
|
|
264
|
+
if not isinstance(shape, str):
|
|
265
|
+
continue
|
|
266
|
+
where = child(child(child(child("streams", key), "columns"), name), "shape")
|
|
267
|
+
file = base_dir / shape
|
|
268
|
+
try:
|
|
269
|
+
column["shape"] = json.loads(file.read_text(encoding="utf-8"))
|
|
270
|
+
except OSError as exc:
|
|
271
|
+
issues.add(where, f"cannot read {str(file)!r}: {exc.strerror}")
|
|
272
|
+
except json.JSONDecodeError as exc:
|
|
273
|
+
issues.add(where, f"{str(file)!r} is not JSON: {exc.msg} at line {exc.lineno}")
|
|
274
|
+
return document
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
# --- Resolving streams --------------------------------------------------------------------------
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
@dataclass(frozen=True)
|
|
281
|
+
class ResolvedStream:
|
|
282
|
+
"""The effective rules for one output stream."""
|
|
283
|
+
|
|
284
|
+
tap_stream: str
|
|
285
|
+
"""The tap stream the records come from."""
|
|
286
|
+
key: str | None
|
|
287
|
+
"""The ``streams`` key of a ``source`` stream (its output name), else None."""
|
|
288
|
+
matched: tuple[str, ...]
|
|
289
|
+
"""The ``streams`` keys merged, least specific first."""
|
|
290
|
+
spec: StreamSpec
|
|
291
|
+
settings: Defaults
|
|
292
|
+
raw: Mapping[str, Any]
|
|
293
|
+
"""The merged mapping the two were parsed from, for explain output."""
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def specificity(pattern: str) -> tuple[int, int, int]:
|
|
297
|
+
"""Sort key: globs before exact names, then by literal characters, then by length."""
|
|
298
|
+
literal = sum(1 for c in pattern if c not in _GLOB_CHARS)
|
|
299
|
+
exact = 0 if _GLOB_CHARS & set(pattern) else 1
|
|
300
|
+
return (exact, literal, len(pattern))
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def matching_keys(spec: Spec, tap_stream: str) -> list[str]:
|
|
304
|
+
"""The non-``source`` keys that match a tap stream, least specific first."""
|
|
305
|
+
keys = [
|
|
306
|
+
key
|
|
307
|
+
for key, rules in spec.streams.items()
|
|
308
|
+
if rules.spec.source is None and fnmatchcase(tap_stream, key)
|
|
309
|
+
]
|
|
310
|
+
return sorted(keys, key=specificity) # stable: declaration order breaks ties
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def _resolve(
|
|
314
|
+
spec: Spec,
|
|
315
|
+
tap_stream: str,
|
|
316
|
+
key: str | None,
|
|
317
|
+
raws: list[Mapping[str, Any]],
|
|
318
|
+
matched: tuple[str, ...],
|
|
319
|
+
) -> ResolvedStream:
|
|
320
|
+
merged: dict[str, Any] = {}
|
|
321
|
+
for raw in raws:
|
|
322
|
+
for name, value in raw.items():
|
|
323
|
+
plain = thaw(value)
|
|
324
|
+
if name == "naming" and isinstance(plain, str):
|
|
325
|
+
plain = {"preset": plain} # naming: sdk merges like {preset: sdk}
|
|
326
|
+
merged[name] = deep_merge(merged[name], plain) if name in merged else plain
|
|
327
|
+
own = {k: v for k, v in merged.items() if k in STREAM_KEYS}
|
|
328
|
+
overrides = {k: v for k, v in merged.items() if k in DEFAULTS_KEYS}
|
|
329
|
+
issues = Issues()
|
|
330
|
+
where = child("streams", key or tap_stream)
|
|
331
|
+
stream_spec = parse_dataclass(StreamSpec, own, where, issues)
|
|
332
|
+
settings = parse_dataclass(Defaults, deep_merge(dump(spec.defaults), overrides), where, issues)
|
|
333
|
+
if issues or not isinstance(stream_spec, StreamSpec) or not isinstance(settings, Defaults):
|
|
334
|
+
raise SpecError(issues.items)
|
|
335
|
+
return ResolvedStream(tap_stream, key, matched, stream_spec, settings, freeze_mapping(merged))
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def resolve_stream(spec: Spec, tap_stream: str) -> ResolvedStream | None:
|
|
339
|
+
"""The rules for a tap stream itself, or None when ``else: drop`` drops it unmatched."""
|
|
340
|
+
keys = matching_keys(spec, tap_stream)
|
|
341
|
+
if not keys and spec.else_ == "drop":
|
|
342
|
+
return None
|
|
343
|
+
raws = [spec.streams[k].raw for k in keys]
|
|
344
|
+
return _resolve(spec, tap_stream, None, raws, tuple(keys))
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def output_streams(spec: Spec, tap_stream: str) -> list[ResolvedStream]:
|
|
348
|
+
"""Every output stream fed by a tap stream: itself (unless dropped) and its copies."""
|
|
349
|
+
out: list[ResolvedStream] = []
|
|
350
|
+
own = resolve_stream(spec, tap_stream)
|
|
351
|
+
if own is not None and not own.spec.drop:
|
|
352
|
+
out.append(own)
|
|
353
|
+
for key, rules in spec.streams.items():
|
|
354
|
+
source = rules.spec.source
|
|
355
|
+
if source is not None and fnmatchcase(tap_stream, source) and not rules.spec.drop:
|
|
356
|
+
out.append(_resolve(spec, tap_stream, key, [rules.raw], (key,)))
|
|
357
|
+
return out
|