added new filter for changing field names (keys)
This commit is contained in:
parent
65347b5993
commit
0c13be7813
@ -351,6 +351,23 @@ class FieldRenamer(Filter):
|
||||
record[dest] = record.pop(source)
|
||||
return record
|
||||
|
||||
class FieldNameModifier(Filter):
|
||||
""" Filter that calls a given function on a given set of fields.
|
||||
|
||||
FieldNameModifier(('spam','eggs'), abs) to call the abs method on the spam
|
||||
and eggs field names in each record filtered.
|
||||
"""
|
||||
|
||||
def __init__(self, func):
|
||||
super(FieldNameModifier, self).__init__()
|
||||
self._filter_func = func
|
||||
|
||||
def process_record(self, record):
|
||||
for source in record.keys():
|
||||
dest = self._filter_func(source)
|
||||
record[dest] = record.pop(source)
|
||||
return record
|
||||
|
||||
class Splitter(Filter):
|
||||
""" Filter that splits nested data into different paths.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user