added new filter for changing field names (keys)

This commit is contained in:
Bob Lannon 2013-04-16 16:56:43 -04:00
parent 65347b5993
commit 0c13be7813

View File

@ -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.