add keep_records parameter on FieldMerger to prevent it from removing merged fields
This commit is contained in:
parent
dcda3db140
commit
2cde3badad
@ -169,13 +169,17 @@ class FieldMerger(Filter):
|
||||
column bacon that is the result of spam+eggs
|
||||
"""
|
||||
|
||||
def __init__(self, mapping, merge_func):
|
||||
def __init__(self, mapping, merge_func, keep_fields=False):
|
||||
super(FieldMerger, self).__init__()
|
||||
self._field_mapping = mapping
|
||||
self._merge_func = merge_func
|
||||
self._keep_fields = keep_fields
|
||||
|
||||
def process_record(self, record):
|
||||
for to_col, from_cols in self._field_mapping.iteritems():
|
||||
if self._keep_fields:
|
||||
values = [record.get(col, None) for col in from_cols]
|
||||
else:
|
||||
values = [record.pop(col, None) for col in from_cols]
|
||||
record[to_col] = self._merge_func(*values)
|
||||
return record
|
||||
|
Loading…
Reference in New Issue
Block a user