1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 This component is used to read data.
24
25 Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
26 GNU General Public License
27 """
28
29
30 from etl.component import component
31
32
33 -class data(component):
34 """
35 This is an ETL Component that return python data from a list of dictionary.
36 """
37
38 - def __init__(self, datas, name='component.input.data', transformer=None, row_limit=0):
39 """
40 Required Parameters
41 datas : Input data
42
43 Extra Parameters
44 name : Name of Component.
45 transformer : Transformer object to transform string data into particular object.
46 """
47 super(data, self).__init__(name=name, transformer=transformer, row_limit=row_limit)
48 self._type = 'component.input.data'
49 self.datas = datas
50
52 res = data(self.datas, self.name, self.transformer, self.row_limit)
53 return res
54
56 for d in self.datas:
57 yield d, 'main'
58
59
60
62 from etl_test import etl_test
63 import etl
64 inp_data = etl.component.input.data([
65 {'id': 1, 'name': 'Fabien', 'country_id': 3},
66 {'id': 2, 'name': 'Luc', 'country_id': 3},
67 {'id': 3, 'name': 'Henry', 'country_id': 1}
68 ])
69 test = etl_test.etl_component_test(inp_data)
70 test.check_output([{'country_id': 3, 'id': 1, 'name': 'Fabien'}, {'country_id': 3, 'id': 2, 'name': 'Luc'}, {'country_id': 1, 'id': 3, 'name': 'Henry'}] )
71 res = test.output()
72 print res
73
74 if __name__ == '__main__':
75 test()
76