Class: Superset::Dataset::Create
- Defined in:
- lib/superset/dataset/create.rb
Constant Summary
Constants inherited from Request
Instance Attribute Summary collapse
-
#new_dataset_name ⇒ Object
readonly
Returns the value of attribute new_dataset_name.
-
#new_dataset_schema ⇒ Object
readonly
Returns the value of attribute new_dataset_schema.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
-
#target_database_id ⇒ Object
readonly
Returns the value of attribute target_database_id.
Attributes inherited from Request
Instance Method Summary collapse
-
#initialize(target_database_id:, new_dataset_name:, new_dataset_schema: 'public', sql:) ⇒ Create
constructor
A new instance of Create.
- #params ⇒ Object
- #perform ⇒ Object
- #response ⇒ Object
Methods inherited from Request
call, #query_params, #result, #superset_host
Methods included from Superset::Display
#display_headers, #headings, #list, #list_attributes, #result, #rows, #table, #title
Constructor Details
#initialize(target_database_id:, new_dataset_name:, new_dataset_schema: 'public', sql:) ⇒ Create
Returns a new instance of Create.
10 11 12 13 14 15 |
# File 'lib/superset/dataset/create.rb', line 10 def initialize(target_database_id: , new_dataset_name: , new_dataset_schema: 'public', sql: ) @target_database_id = target_database_id @new_dataset_name = new_dataset_name @new_dataset_schema = new_dataset_schema @sql = sql end |
Instance Attribute Details
#new_dataset_name ⇒ Object (readonly)
Returns the value of attribute new_dataset_name.
8 9 10 |
# File 'lib/superset/dataset/create.rb', line 8 def new_dataset_name @new_dataset_name end |
#new_dataset_schema ⇒ Object (readonly)
Returns the value of attribute new_dataset_schema.
8 9 10 |
# File 'lib/superset/dataset/create.rb', line 8 def new_dataset_schema @new_dataset_schema end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
8 9 10 |
# File 'lib/superset/dataset/create.rb', line 8 def sql @sql end |
#target_database_id ⇒ Object (readonly)
Returns the value of attribute target_database_id.
8 9 10 |
# File 'lib/superset/dataset/create.rb', line 8 def target_database_id @target_database_id end |
Instance Method Details
#params ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/superset/dataset/create.rb', line 33 def params { "schema": new_dataset_schema, "sql": sql, "table_name": new_dataset_name, "database": target_database_id # Optional Params .. pulled straight from the GUI swagger example #"always_filter_main_dttm": false, #"external_url": "string", #"is_managed_externally": false, #"normalize_columns": false, # "owners": [ 0 ], } end |
#perform ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/superset/dataset/create.rb', line 17 def perform raise "Error: target_database_id integer is required" unless target_database_id.present? && target_database_id.is_a?(Integer) raise "Error: new_dataset_name string is required" unless new_dataset_name.present? && new_dataset_name.is_a?(String) raise "Error: Dataset Name #{new_dataset_name} is already in use in the schema: #{new_dataset_schema}. Suggest you add (COPY) as a suffix to the name" if new_dataset_name_already_in_use? raise "Error: sql string is required" unless sql.present? && sql.is_a?(String) logger.info("Creating New Dataset #{new_dataset_name} in DB #{target_database_id} Schema #{new_dataset_schema}") response { id: response['id'], dataset_name: response['data']['datasource_name'] } end |
#response ⇒ Object
29 30 31 |
# File 'lib/superset/dataset/create.rb', line 29 def response @response ||= client.post(route, params) end |