Skip to content
This repository was archived by the owner on Aug 25, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions target_postgres/db_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shutil

TARGET_REJECTED_DIR = os.getenv("TARGET_REJECTED_DIR")
NULL_TYPE = {'type': 'null'}

logger = singer.get_logger()

Expand Down Expand Up @@ -74,14 +75,16 @@ def flatten_schema(d, parent_key=[], sep='__'):
items.extend(flatten_schema(v, parent_key + [k], sep=sep).items())
else:
items.append((new_key, v))
elif 'anyOf' in v.keys():
properties = list(v.values())[0]
if NULL_TYPE not in properties or len(properties) > 2:
raise ValueError('Unsupported column type anyOf: {}'.format(k))
property = list(filter(lambda x: x != NULL_TYPE, properties))[0]
if not isinstance(property['type'], list):
property['type'] = ['null', property['type']]
items.append((new_key, property))
else:
property = list(v.values())[0][0]
if property['type'] == 'string':
property['type'] = ['null', 'string']
items.append((new_key, property))
elif property['type'] == 'array':
property['type'] = ['null', 'array']
items.append((new_key, property))
raise ValueError('Unsupported column type: {}'.format(k))

key_func = lambda item: item[0]
sorted_items = sorted(items, key=key_func)
Expand Down