Class: Embulk::Guess::Jsonl
- Inherits:
-
LineGuessPlugin
- Object
- LineGuessPlugin
- Embulk::Guess::Jsonl
- Defined in:
- lib/embulk/guess/jsonl.rb
Overview
$ embulk guess -g “jsonl” partial-config.yml
Instance Method Summary collapse
Instance Method Details
#guess_lines(config, sample_lines) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/embulk/guess/jsonl.rb', line 11 def guess_lines(config, sample_lines) #return {} unless config.fetch("parser", {}).fetch("type", "jsonl") == "jsonl" rows = [] columns = {} sample_lines.each do |line| rows << JSON.parse(line) end return {} if rows.size <= 3 columns = Embulk::Guess::SchemaGuess.from_hash_records(rows).map do |c| column = {name: c.name, type: c.type} column[:format] = c.format if c.format column end parser_guessed = {"type" => "jsonl"} parser_guessed["columns"] = columns return {"parser" => parser_guessed} end |