Class: Embulk::Filter::ExpandJsonArray
- Inherits:
-
FilterPlugin
- Object
- FilterPlugin
- Embulk::Filter::ExpandJsonArray
- Defined in:
- lib/embulk/filter/expand_json_array.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.transaction(config, in_schema) {|task, out_columns| ... } ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/embulk/filter/expand_json_array.rb', line 9 def self.transaction(config, in_schema, &control) # configuration code: task = { "json_column_name" => config.param("json_column_name", :string), "root" => config.param("root", :string), "expanded_column_name" => config.param("expanded_column_name", :string) } task['parse_target_column'] = in_schema.find{|c| c.name == task['json_column_name']} columns = [ Column.new(nil, task["expanded_column_name"], :string), ] out_columns = in_schema + columns yield(task, out_columns) end |
Instance Method Details
#add(page) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/embulk/filter/expand_json_array.rb', line 42 def add(page) # filtering code: page.each do |record| = @json_path.on(record[@parse_target_column['index']]).flatten .each do |ec| page_builder.add(record + [ec]) end end end |
#close ⇒ Object
39 40 |
# File 'lib/embulk/filter/expand_json_array.rb', line 39 def close end |
#finish ⇒ Object
53 54 55 |
# File 'lib/embulk/filter/expand_json_array.rb', line 53 def finish page_builder.finish end |
#init ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/embulk/filter/expand_json_array.rb', line 28 def init # initialization code: @json_column_name = task["json_column_name"] @root = task["root"] @expanded_column_name = task["expanded_column_name"] @parse_target_column = task['parse_target_column'] @json_path = JsonPath.new(@root) end |