Class: Embulk::Input::Redash::Plugin

Inherits:
InputPlugin
  • Object
show all
Defined in:
lib/embulk/input/redash/plugin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.embulk_columns(config) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/embulk/input/redash/plugin.rb', line 55

def self.embulk_columns(config)
  config.param(:columns, :array).map do |column|
    name = column['name']
    type = column['type'].to_sym

    Column.new(nil, name, type, column['format'])
  end
end

.guess(_config) ⇒ Object



27
28
29
30
31
# File 'lib/embulk/input/redash/plugin.rb', line 27

def self.guess(_config)
  sample_records = get_rows(_config['url'], _config['api_key']).first(10)
  columns = Guess::SchemaGuess.from_hash_records(sample_records)
  { 'columns' => columns }
end

.resume(task, columns, count) ⇒ Object



20
21
22
23
24
25
# File 'lib/embulk/input/redash/plugin.rb', line 20

def self.resume(task, columns, count)
  task_reports = yield(task, columns, count)

  next_config_diff = {}
  next_config_diff
end

.transaction(config, &control) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/embulk/input/redash/plugin.rb', line 9

def self.transaction(config, &control)
  task = {
    'url' => config.param('url', :string),
    'api_key' => config.param('api_key', :string)
  }

  columns = embulk_columns(config)

  resume(task, columns, 1, &control)
end

Instance Method Details

#initObject



33
34
35
36
# File 'lib/embulk/input/redash/plugin.rb', line 33

def init
  @url = task['url']
  @api_key = task['api_key']
end

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/embulk/input/redash/plugin.rb', line 38

def run
  column_names = @schema.map(&:name)

  Plugin.get_rows(@url, @api_key).each do |row|
    values = schema.map do |col|
      convert(col.type, row[col.name])
    end
    page_builder.add(values)
  end

  page_builder.finish

  task_report = {}

  task_report
end