Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make validation optional #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions target_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def flatten(d, parent_key='', sep='__'):
items.append((new_key, str(v) if type(v) is list else v))
return dict(items)

def persist_messages(delimiter, quotechar, messages, destination_path):
def persist_messages(delimiter, quotechar, messages, destination_path, validate_records):
state = None
schemas = {}
key_properties = {}
Expand All @@ -55,8 +55,8 @@ def persist_messages(delimiter, quotechar, messages, destination_path):
if o['stream'] not in schemas:
raise Exception("A record for stream {}"
"was encountered before a corresponding schema".format(o['stream']))

validators[o['stream']].validate(o['record'])
if validate_records:
validators[o['stream']].validate(o['record'])

filename = o['stream'] + '-' + now + '.csv'
filename = os.path.expanduser(os.path.join(destination_path, filename))
Expand Down Expand Up @@ -141,7 +141,8 @@ def main():
state = persist_messages(config.get('delimiter', ','),
config.get('quotechar', '"'),
input_messages,
config.get('destination_path', ''))
config.get('destination_path', ''),
config.get('validate_records', True))

emit_state(state)
logger.debug("Exiting normally")
Expand Down