Class: Superset::Dashboard::Datasets::List

Inherits:
Request
  • Object
show all
Defined in:
lib/superset/dashboard/datasets/list.rb

Constant Summary

Constants inherited from Request

Request::DEFAULT_PAGE_SIZE

Instance Attribute Summary collapse

Attributes inherited from Request

#page_num, #page_size

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

#query_params, #response, #result, #superset_host

Methods included from Superset::Display

#ids, #list, #result, #table, #to_h

Constructor Details

#initialize(dashboard_id:, include_filter_datasets: false) ⇒ List



16
17
18
19
# File 'lib/superset/dashboard/datasets/list.rb', line 16

def initialize(dashboard_id:, include_filter_datasets: false)
  @id = dashboard_id
  @include_filter_datasets = include_filter_datasets
end

Instance Attribute Details

#idObject (readonly)

id - dashboard id



10
11
12
# File 'lib/superset/dashboard/datasets/list.rb', line 10

def id
  @id
end

#include_filter_datasetsObject (readonly)

id - dashboard id



10
11
12
# File 'lib/superset/dashboard/datasets/list.rb', line 10

def include_filter_datasets
  @include_filter_datasets
end

Class Method Details

.call(id) ⇒ Object



12
13
14
# File 'lib/superset/dashboard/datasets/list.rb', line 12

def self.call(id)
  self.new(id).list
end

Instance Method Details

#databasesObject



26
27
28
# File 'lib/superset/dashboard/datasets/list.rb', line 26

def databases
  @databases ||= datasets_details.map {|d| d[:database] }.uniq
end

#datasets_detailsObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/superset/dashboard/datasets/list.rb', line 43

def datasets_details
  chart_datasets = result.map do |details|
    details.slice('id', 'datasource_name', 'schema', 'sql').merge('database' => details['database'].slice('id', 'name', 'backend')).with_indifferent_access
  end
  return chart_datasets unless include_filter_datasets
  chart_dataset_ids = chart_datasets.map{|d| d['id'] }
  filter_dataset_ids_not_used_in_charts = filter_dataset_ids - chart_dataset_ids
  return chart_datasets if filter_dataset_ids_not_used_in_charts.empty?
  # returning chart and filter datasets
  chart_datasets + filter_datasets(filter_dataset_ids_not_used_in_charts)
end

#performObject



21
22
23
24
# File 'lib/superset/dashboard/datasets/list.rb', line 21

def perform
  response
  self
end

#rowsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/superset/dashboard/datasets/list.rb', line 55

def rows
  datasets_details.map do |d|
    [
      d[:id],
      d[:datasource_name],
      d[:database][:id],
      d[:database][:name],
      d[:database][:backend],
      d[:schema],
      d[:filter_only]
    ]
  end
end

#schemasObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/superset/dashboard/datasets/list.rb', line 30

def schemas
  @schemas ||= begin
    all_dashboard_schemas = datasets_details.map {|d| d[:schema] }.uniq

    # For the current superset setup we will assume a dashboard datasets will point to EXACTLY one schema, their own.
    # if not .. we need to know about it. Potentially we could override this check if others do not consider it a problem.
    if all_dashboard_schemas.count > 1
      Rollbar.error("SUPERSET DASHBOARD ERROR: Dashboard id #{id} has multiple dataset schema linked: #{all_dashboard_schemas.to_s}") if defined?(Rollbar)
    end
    all_dashboard_schemas
  end
end