Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Fix: accept empty schema #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion target_snowflake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def reset_new_value(record: Dict, key: str, format: str):
reset_new_value(record, key, type_dict['format'])
break
else:
if 'string' in schema['properties'][key]['type'] and \
if 'string' in schema['properties'][key].get('type', []) and \
schema['properties'][key].get('format', None) in {'date-time', 'time', 'date'}:
reset_new_value(record, key, schema['properties'][key]['format'])

Expand Down
13 changes: 9 additions & 4 deletions target_snowflake/db_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def validate_config(config):


def column_type(schema_property):
property_type = schema_property['type']
property_type = schema_property.get('type', [])
property_format = schema_property['format'] if 'format' in schema_property else None
column_type = 'text'
if 'object' in property_type or 'array' in property_type:
if 'object' in property_type or 'array' in property_type or property_type == []:
column_type = 'variant'

# Every date-time JSON value is currently mapped to TIMESTAMP_NTZ
Expand All @@ -80,9 +80,11 @@ def column_type(schema_property):


def column_trans(schema_property):
property_type = schema_property['type']
property_type = schema_property.get('type', [])
column_trans = ''
if 'object' in property_type or 'array' in property_type:
if property_type == []:
column_trans = 'to_variant'
elif 'object' in property_type or 'array' in property_type:
column_trans = 'parse_json'
elif schema_property.get('format') == 'binary':
column_trans = 'to_binary'
Expand Down Expand Up @@ -135,6 +137,9 @@ def flatten_schema(d, parent_key=[], sep='__', level=0, max_level=0):
elif list(v.values())[0][0]['type'] == 'object':
list(v.values())[0][0]['type'] = ['null', 'object']
items.append((new_key, list(v.values())[0][0]))
else:
# In case of empty schema {}
items.append((new_key, {}))

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