Created
April 13, 2022 07:29
-
-
Save MikeRzhevsky/72d3a280bee3798eb14fd496e4a65797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.debug import DEBUG | |
from pickle import TRUE | |
import json | |
import os | |
import collections | |
from collections import defaultdict | |
DEBUG = TRUE | |
dwh_m_json = [] | |
trino_m_json = [] | |
click_m_json = [] | |
with open(f"A:/DBT+Docker/dbt-tutorial/tutorial-shop/python/manifest_s.json") as jsonFile: | |
dwh_m_json = json.load(jsonFile) | |
with open(f"A:/DBT+Docker/dbt-tutorial/tutorial-shop/python/manifest_t.json") as jsonFile: | |
trino_m_json = json.load(jsonFile) | |
with open(f"A:/DBT+Docker/dbt-tutorial/tutorial-shop/python/manifest_c.json") as jsonFile: | |
click_m_json = json.load(jsonFile) | |
def mergeDictionary(dict_1, dict_2,dict_3): | |
dicts = [dict_1, dict_2, dict_3] | |
result = dict() | |
result = defaultdict(set) # uses set to avoid duplicates | |
for d in dicts: | |
for k, v in d.items(): | |
if isinstance(v ,set): | |
result[k].add(tuple(v)) | |
if type(v) is dict: | |
result[k].add(tuple(v)) | |
if type(v) is list: | |
result[k].add(tuple(v)) | |
if isinstance(v,int): | |
result[k].add(v) | |
if isinstance(v,str): | |
result[k].add(v) | |
return result | |
res = dict() | |
res = mergeDictionary(dwh_m_json, trino_m_json,click_m_json) | |
with open(f"A:/DBT+Docker/dbt-tutorial/tutorial-shop/python/manifest_mrg.txt", 'w') as output_file: | |
# json.dump(res, output_file) # Error Object of type set is not JSON serializable | |
output_file.write(str(res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment