Skip to content

Commit

Permalink
v0.0.42 minor fixes to dump_to_sql, add_computed_field
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Mar 9, 2019
1 parent f40a927 commit e464897
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dataflows/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.41
0.0.42
8 changes: 5 additions & 3 deletions dataflows/processors/add_computed_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def process_resource(fields, rows):
for row in rows:
for field in fields:
values = [
row.get(c) for c in field.get('source', []) if row.get(c) is not None
row.get(c)
for c in field.get('source', [])
if row.get(c) is not None
]
with_ = field.get('with', field.get('with_', ''))
new_col = AGGREGATORS[field['operation']].func(values, with_, row)
Expand All @@ -57,8 +59,8 @@ def func(package):
{
'name': f['target'],
'type': get_type(descriptor['schema']['fields'],
f.get('source', []),
f['operation'])
f.get('source', []),
f['operation'])
} for f in fields
]
descriptor['schema']['fields'].extend(new_fields)
Expand Down
22 changes: 13 additions & 9 deletions dataflows/processors/dumpers/to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ def __init__(self,
**options):
super(SQLDumper, self).__init__(options)
table_to_resource = tables
if engine.startswith('env://'):
env_var = engine[6:]
engine = os.environ.get(env_var)
if engine is None:
raise ValueError("Couldn't connect to DB - "
"Please set your '%s' environment variable" % env_var)

self.engine = create_engine(engine)
self.engine.connect()

if isinstance(engine, str):
if engine.startswith('env://'):
env_var = engine[6:]
engine = os.environ.get(env_var)
if engine is None:
raise ValueError("Couldn't connect to DB - "
"Please set your '%s' environment variable" % env_var)

self.engine = create_engine(engine)
self.engine.connect()
else:
self.engine = engine

for k, v in table_to_resource.items():
v['table-name'] = k
Expand Down

0 comments on commit e464897

Please sign in to comment.