Skip to content

Instantly share code, notes, and snippets.

@MikeRzhevsky
Created April 13, 2022 07:27
Show Gist options
  • Save MikeRzhevsky/ef35f4e67c01dedef3798f24f90c72a1 to your computer and use it in GitHub Desktop.
Save MikeRzhevsky/ef35f4e67c01dedef3798f24f90c72a1 to your computer and use it in GitHub Desktop.
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