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