class Embulk::Input::Redash::Plugin

Redash input plugin for Embulk

Public Class Methods

embulk_columns(config) click to toggle source
# File lib/embulk/input/redash/plugin.rb, line 49
def self.embulk_columns(config)
  config.param(:columns, :array).map do |column|
    name = column['name']
    type = column['type'].to_sym
    format = column['format']

    Column.new(nil, name, type, format)
  end
end
guess(config) click to toggle source
# File lib/embulk/input/redash/plugin.rb, line 24
def self.guess(config)
  sample_records = Client.get_rows(config['url'], config['api_key'])
                         .first(10)
  columns = Guess::SchemaGuess.from_hash_records(sample_records)
  { columns: columns }
end
transaction(config) { |task, columns, 1| ... } click to toggle source
# File lib/embulk/input/redash/plugin.rb, line 11
def self.transaction(config, &_control)
  task = {
    url: config.param('url', :string),
    api_key: config.param('api_key', :string)
  }

  columns = embulk_columns(config)

  task_reports = yield(task, columns, 1)

  task_reports.first
end

Public Instance Methods

init() click to toggle source
# File lib/embulk/input/redash/plugin.rb, line 31
def init
  @url = task['url']
  @api_key = task['api_key']
end
run() click to toggle source
# File lib/embulk/input/redash/plugin.rb, line 36
def run
  Client.get_rows(@url, @api_key).each do |row|
    values = schema.map do |col|
      Converter.convert(col.type, row[col.name])
    end
    page_builder.add(values)
  end

  page_builder.finish

  {}
end