forked from luck02/sample-dbt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
process_generated.py
68 lines (41 loc) · 1.96 KB
/
process_generated.py
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
import json
def process_catalog(catalog):
return catalog
def process_manifest(manifest):
def process_root_path(item):
if "root_path" in item:
item["root_path"] = "/some-path/sample-dbt"
return item
root_path_fields = ["nodes", "docs", "macros", "sources"]
for root_path_field in root_path_fields:
for item_key, item in manifest[root_path_field].items():
manifest[root_path_field][item_key] = process_root_path(item)
manifest["metadata"]["generated_at"] = "2021-06-18T21:38:36.384613Z"
manifest["metadata"]["invocation_id"] = "just-some-random-id"
return manifest
def process_sources(sources):
def process_result(result):
result["max_loaded_at_time_ago_in_s"] = 42276862.910052
result["snapshotted_at"] = "2021-06-18T17:08:55.925443+00:00"
return result
sources["elapsed_time"] = 3.1415
sources["metadata"]["generated_at"] = "2021-06-18T21:38:36.384613Z"
sources["metadata"]["invocation_id"] = "just-some-random-id"
sources["results"] = [process_result(result) for result in sources["results"]]
return sources
if __name__ == "__main__":
with open("./target/catalog.json", "r") as file:
catalog = json.load(file)
with open("./target/manifest.json", "r") as file:
manifest = json.load(file)
with open("./target/sources.json", "r") as file:
sources = json.load(file)
processed_catalog = process_catalog(catalog)
processed_manifest = process_manifest(manifest)
processed_sources = process_sources(sources)
with open("./target_processed/dbt_catalog.json", "w") as file:
json.dump(processed_catalog, file, indent=2, sort_keys=True)
with open("./target_processed/dbt_manifest.json", "w") as file:
json.dump(processed_manifest, file, indent=2, sort_keys=True)
with open("./target_processed/dbt_sources.json", "w") as file:
json.dump(processed_sources, file, indent=2, sort_keys=True)