Sha256: 13a7c6fb87565d33a036c65ab90a1ff76a42591723700dd5fa525f55f9a7c7a0
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
require "embulk/parser/query_string" module Embulk module Guess # $ embulk guess -g "query_string" partial-config.yml class QueryString < LineGuessPlugin Plugin.register_guess("query_string", self) def guess_lines(config, sample_lines) return {} unless config.fetch("parser", {}).fetch("type", "query_string") == "query_string" options = { strip_quote: config.param("strip_quote", :bool, default: true), strip_whitespace: config.param("strip_whitespace", :bool, default: true) } records = sample_lines.map do |line| Parser::QueryString.parse(line, options) || {} end format = records.inject({}) do |result, record| record.each_pair do |key, value| (result[key] ||= []) << value end result end guessed = {type: "query_string", schema: []} format.each_pair do |key, values| if values.any? {|value| value.match(/[^0-9]/) } guessed[:schema] << {name: key, type: :string} else guessed[:schema] << {name: key, type: :long} end end return {"parser" => guessed} end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
embulk-parser-query_string-0.0.3 | lib/embulk/guess/query_string.rb |
embulk-parser-query_string-0.0.2 | lib/embulk/guess/query_string.rb |