-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.py
More file actions
365 lines (300 loc) · 14.8 KB
/
parser.py
File metadata and controls
365 lines (300 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Union
from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import CatalogV1
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v1 import ManifestV1
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v2 import ManifestV2
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v3 import ManifestV3
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v4 import ManifestV4
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v5 import ManifestV5
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v6 import ManifestV6
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v7 import ManifestV7
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v8 import ManifestV8
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v9 import ManifestV9
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v10 import ManifestV10
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v11 import ManifestV11
from vendor.dbt_artifacts_parser.parsers.manifest.manifest_v12 import ManifestV12
from vendor.dbt_artifacts_parser.parsers.run_results.run_results_v1 import RunResultsV1
from vendor.dbt_artifacts_parser.parsers.run_results.run_results_v2 import RunResultsV2
from vendor.dbt_artifacts_parser.parsers.run_results.run_results_v3 import RunResultsV3
from vendor.dbt_artifacts_parser.parsers.run_results.run_results_v4 import RunResultsV4
from vendor.dbt_artifacts_parser.parsers.run_results.run_results_v5 import RunResultsV5
from vendor.dbt_artifacts_parser.parsers.run_results.run_results_v6 import RunResultsV6
from vendor.dbt_artifacts_parser.parsers.semantic_manifest.semantic_manifest_v1 import SemanticManifestV1
from vendor.dbt_artifacts_parser.parsers.sources.sources_v1 import SourcesV1
from vendor.dbt_artifacts_parser.parsers.sources.sources_v2 import SourcesV2
from vendor.dbt_artifacts_parser.parsers.sources.sources_v3 import SourcesV3
from vendor.dbt_artifacts_parser.parsers.utils import get_dbt_schema_version
from vendor.dbt_artifacts_parser.parsers.version_map import ArtifactTypes
#
# catalog
#
def parse_catalog(catalog: dict) -> Union[CatalogV1]:
"""Parse catalog.json
Args:
catalog: dict of catalog.json
Returns:
Union[CatalogV1]
"""
dbt_schema_version = get_dbt_schema_version(artifact_json=catalog)
if dbt_schema_version == ArtifactTypes.CATALOG_V1.value.dbt_schema_version:
return CatalogV1(**catalog)
raise ValueError("Not a catalog.json")
def parse_catalog_v1(catalog: dict) -> CatalogV1:
"""Parse catalog.json v1"""
dbt_schema_version = get_dbt_schema_version(artifact_json=catalog)
if dbt_schema_version == ArtifactTypes.CATALOG_V1.value.dbt_schema_version:
return CatalogV1(**catalog)
raise ValueError("Not a catalog.json v1")
#
# manifest
#
def parse_manifest(
manifest: dict,
) -> Union[
ManifestV1,
ManifestV2,
ManifestV3,
ManifestV4,
ManifestV5,
ManifestV6,
ManifestV7,
ManifestV8,
ManifestV9,
ManifestV10,
ManifestV11,
ManifestV12,
]:
"""Parse manifest.json
Args:
manifest: A dict of manifest.json
Returns:
Union[
ManifestV1, ManifestV2, ManifestV3, ManifestV4, ManifestV5,
ManifestV6, ManifestV7, ManifestV8, ManifestV9, ManifestV10,
ManifestV11, ManifestV12,
]
"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V1.value.dbt_schema_version:
return ManifestV1(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V2.value.dbt_schema_version:
return ManifestV2(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V3.value.dbt_schema_version:
return ManifestV3(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V4.value.dbt_schema_version:
return ManifestV4(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V5.value.dbt_schema_version:
return ManifestV5(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V6.value.dbt_schema_version:
return ManifestV6(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V7.value.dbt_schema_version:
return ManifestV7(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V8.value.dbt_schema_version:
return ManifestV8(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V9.value.dbt_schema_version:
return ManifestV9(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V10.value.dbt_schema_version:
return ManifestV10(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V11.value.dbt_schema_version:
return ManifestV11(**manifest)
elif dbt_schema_version == ArtifactTypes.MANIFEST_V12.value.dbt_schema_version:
return ManifestV12(**manifest)
raise ValueError("Not a manifest.json")
def parse_manifest_v1(manifest: dict) -> ManifestV1:
"""Parse manifest.json ver.1"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V1.value.dbt_schema_version:
return ManifestV1(**manifest)
raise ValueError("Not a manifest.json v1")
def parse_manifest_v2(manifest: dict) -> ManifestV2:
"""Parse manifest.json ver.2"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V2.value.dbt_schema_version:
return ManifestV2(**manifest)
raise ValueError("Not a manifest.json v2")
def parse_manifest_v3(manifest: dict) -> ManifestV3:
"""Parse manifest.json ver.3"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V3.value.dbt_schema_version:
return ManifestV3(**manifest)
raise ValueError("Not a manifest.json v3")
def parse_manifest_v4(manifest: dict) -> ManifestV4:
"""Parse manifest.json ver.4"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V4.value.dbt_schema_version:
return ManifestV4(**manifest)
raise ValueError("Not a manifest.json v4")
def parse_manifest_v5(manifest: dict) -> ManifestV5:
"""Parse manifest.json ver.5"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V5.value.dbt_schema_version:
return ManifestV5(**manifest)
raise ValueError("Not a manifest.json v5")
def parse_manifest_v6(manifest: dict) -> ManifestV6:
"""Parse manifest.json ver.6"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V6.value.dbt_schema_version:
return ManifestV6(**manifest)
raise ValueError("Not a manifest.json v6")
def parse_manifest_v7(manifest: dict) -> ManifestV7:
"""Parse manifest.json ver.7"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V7.value.dbt_schema_version:
return ManifestV7(**manifest)
raise ValueError("Not a manifest.json v7")
def parse_manifest_v8(manifest: dict) -> ManifestV8:
"""Parse manifest.json ver.8"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V8.value.dbt_schema_version:
return ManifestV8(**manifest)
raise ValueError("Not a manifest.json v8")
def parse_manifest_v9(manifest: dict) -> ManifestV9:
"""Parse manifest.json ver.9"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V9.value.dbt_schema_version:
return ManifestV9(**manifest)
raise ValueError("Not a manifest.json v9")
def parse_manifest_v10(manifest: dict) -> ManifestV10:
"""Parse manifest.json ver.10"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V10.value.dbt_schema_version:
return ManifestV10(**manifest)
raise ValueError("Not a manifest.json v10")
def parse_manifest_v11(manifest: dict) -> ManifestV11:
"""Parse manifest.json ver.11"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V11.value.dbt_schema_version:
return ManifestV11(**manifest)
raise ValueError("Not a manifest.json v11")
def parse_manifest_v12(manifest: dict) -> ManifestV12:
"""Parse manifest.json ver.12"""
dbt_schema_version = get_dbt_schema_version(artifact_json=manifest)
if dbt_schema_version == ArtifactTypes.MANIFEST_V12.value.dbt_schema_version:
return ManifestV12(**manifest)
raise ValueError("Not a manifest.json v12")
#
# run-results
#
def parse_run_results(
run_results: dict,
) -> Union[RunResultsV1, RunResultsV2, RunResultsV3, RunResultsV4, RunResultsV5, RunResultsV6]:
"""Parse run-results.json
Args:
run_results: A dict of run-results.json
Returns:
Union[RunResultsV1, RunResultsV2, RunResultsV3, RunResultsV4]:
"""
dbt_schema_version = get_dbt_schema_version(artifact_json=run_results)
if dbt_schema_version == ArtifactTypes.RUN_RESULTS_V1.value.dbt_schema_version:
return RunResultsV1(**run_results)
elif dbt_schema_version == ArtifactTypes.RUN_RESULTS_V2.value.dbt_schema_version:
return RunResultsV2(**run_results)
elif dbt_schema_version == ArtifactTypes.RUN_RESULTS_V3.value.dbt_schema_version:
return RunResultsV3(**run_results)
elif dbt_schema_version == ArtifactTypes.RUN_RESULTS_V4.value.dbt_schema_version:
return RunResultsV4(**run_results)
elif dbt_schema_version == ArtifactTypes.RUN_RESULTS_V5.value.dbt_schema_version:
return RunResultsV5(**run_results)
elif dbt_schema_version == ArtifactTypes.RUN_RESULTS_V6.value.dbt_schema_version:
return RunResultsV6(**run_results)
raise ValueError("Not a manifest.json")
def parse_run_results_v1(run_results: dict) -> RunResultsV1:
"""Parse run-results.json v1"""
dbt_schema_version = get_dbt_schema_version(artifact_json=run_results)
if dbt_schema_version == ArtifactTypes.RUN_RESULTS_V1.value.dbt_schema_version:
return RunResultsV1(**run_results)
raise ValueError("Not a run-results.json v1")
def parse_run_results_v2(run_results: dict) -> RunResultsV2:
"""Parse run-results.json v2"""
dbt_schema_version = get_dbt_schema_version(artifact_json=run_results)
if dbt_schema_version == ArtifactTypes.RUN_RESULTS_V2.value.dbt_schema_version:
return RunResultsV2(**run_results)
raise ValueError("Not a run-results.json v2")
def parse_run_results_v3(run_results: dict) -> RunResultsV3:
"""Parse run-results.json v3"""
dbt_schema_version = get_dbt_schema_version(artifact_json=run_results)
if dbt_schema_version == ArtifactTypes.RUN_RESULTS_V3.value.dbt_schema_version:
return RunResultsV3(**run_results)
raise ValueError("Not a run-results.json v3")
def parse_run_results_v4(run_results: dict) -> RunResultsV4:
"""Parse run-results.json v4"""
dbt_schema_version = get_dbt_schema_version(artifact_json=run_results)
if dbt_schema_version == ArtifactTypes.RUN_RESULTS_V4.value.dbt_schema_version:
return RunResultsV4(**run_results)
raise ValueError("Not a run-results.json v4")
def parse_run_results_v5(run_results: dict) -> RunResultsV5:
"""Parse run-results.json v5"""
dbt_schema_version = get_dbt_schema_version(artifact_json=run_results)
if dbt_schema_version == ArtifactTypes.RUN_RESULTS_V5.value.dbt_schema_version:
return RunResultsV5(**run_results)
raise ValueError("Not a run-results.json v5")
def parse_run_results_v6(run_results: dict) -> RunResultsV6:
"""Parse run-results.json v6"""
dbt_schema_version = get_dbt_schema_version(artifact_json=run_results)
if dbt_schema_version == ArtifactTypes.RUN_RESULTS_V6.value.dbt_schema_version:
return RunResultsV6(**run_results)
raise ValueError("Not a run-results.json v6")
#
# sources
#
def parse_sources(sources: dict) -> Union[SourcesV1, SourcesV2, SourcesV3]:
"""Parse sources.json
Args:
sources: A dict of sources.json
Returns:
Union[SourcesV1, SourcesV2, SourcesV3]
"""
dbt_schema_version = get_dbt_schema_version(artifact_json=sources)
if dbt_schema_version == ArtifactTypes.SOURCES_V1.value.dbt_schema_version:
return SourcesV1(**sources)
elif dbt_schema_version == ArtifactTypes.SOURCES_V2.value.dbt_schema_version:
return SourcesV2(**sources)
elif dbt_schema_version == ArtifactTypes.SOURCES_V3.value.dbt_schema_version:
return SourcesV3(**sources)
raise ValueError("Not a manifest.json")
def parse_sources_v1(sources: dict) -> SourcesV1:
"""Parse sources.json v1"""
dbt_schema_version = get_dbt_schema_version(artifact_json=sources)
if dbt_schema_version == ArtifactTypes.SOURCES_V1.value.dbt_schema_version:
return SourcesV1(**sources)
raise ValueError("Not a sources.json v1")
def parse_sources_v2(sources: dict) -> SourcesV2:
"""Parse sources.json v2"""
dbt_schema_version = get_dbt_schema_version(artifact_json=sources)
if dbt_schema_version == ArtifactTypes.SOURCES_V2.value.dbt_schema_version:
return SourcesV2(**sources)
raise ValueError("Not a sources.json v2")
def parse_sources_v3(sources: dict) -> SourcesV3:
"""Parse sources.json v3"""
dbt_schema_version = get_dbt_schema_version(artifact_json=sources)
if dbt_schema_version == ArtifactTypes.SOURCES_V3.value.dbt_schema_version:
return SourcesV3(**sources)
raise ValueError("Not a sources.json v3")
#
# semantic-manifest
#
def parse_semantic_manifest(semantic_manifest: dict) -> SemanticManifestV1:
"""Parse semantic_manifest.json
Args:
semantic_manifest: A dict of semantic_manifest.json
Returns:
SemanticManifestV1
"""
# Semantic manifest uses a flexible schema, so we accept any valid dict
# The schema version check is optional since the format may vary
return SemanticManifestV1(**semantic_manifest)