Skip to content

Instantly share code, notes, and snippets.

@mjsqu
Created January 31, 2024 20:40
Show Gist options
  • Save mjsqu/7197236238dabe0ece02876bb8164396 to your computer and use it in GitHub Desktop.
Save mjsqu/7197236238dabe0ece02876bb8164396 to your computer and use it in GitHub Desktop.
Singer Catalog Single Table Extractor
#!/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