Created
January 31, 2024 20:40
-
-
Save mjsqu/7197236238dabe0ece02876bb8164396 to your computer and use it in GitHub Desktop.
Singer Catalog Single Table Extractor
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
#!/usr/bin/env python | |
import json | |
import sys | |
full_catalog=sys.argv[1] | |
schema_table=sys.argv[2] | |
try: | |
replication_method = sys.argv[3] | |
replication_key = sys.argv[4] | |
except: | |
replication_method="FULL_TABLE" | |
with open(full_catalog,'r') as f: | |
npf = json.load(f) | |
stream = [x for x in npf['streams'] if x['tap_stream_id'] == schema_table] | |
if len(stream) > 1: | |
print(f"ERROR: Catalog may not have been created correctly {schema_table} matches more than one stream") | |
exit() | |
newobj = {'streams':[x for x in npf['streams'] if x['tap_stream_id'] == schema_table]} | |
newobj['streams'][0]['metadata'][0]['metadata']['selected'] = True | |
newobj['streams'][0]['metadata'][0]['metadata']['replication-method'] = replication_method | |
try: | |
newobj['streams'][0]['metadata'][0]['metadata']['replication-key'] = replication_key | |
except: | |
pass | |
#print('No replication key') | |
print(json.dumps(newobj,indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment