/
jsonl.rb
47 lines (38 loc) · 1 KB
/
jsonl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Embulk
module Formatter
class JsonlFormatterPlugin < FormatterPlugin
Plugin.register_formatter("jsonl", self)
def self.transaction(config, schema, &control)
# configuration code:
task = {
"property1" => config.param("property1", :string),
"property2" => config.param("property2", :integer, default: 0),
}
yield(task)
end
def init
# initialization code:
@property1 = task["property1"]
@property2 = task["property2"]
# your data
@current_file == nil
@current_file_size = 0
end
def close
end
def add(page)
# output code:
page.each do |record|
if @current_file == nil || @current_file_size > 32*1024
@current_file = file_output.next_file
@current_file_size = 0
end
@current_file.write "|mydata|"
end
end
def finish
file_output.finish
end
end
end
end