Class: Aliyun::Odps::Tables
- Inherits:
-
ServiceObject
- Object
- ServiceObject
- Aliyun::Odps::Tables
- Defined in:
- lib/aliyun/odps/model/tables.rb
Overview
Methods for Tables
Instance Attribute Summary
Attributes inherited from ServiceObject
Instance Method Summary collapse
-
#create(name, schema, options = {}) ⇒ Object
Create Table.
-
#delete(name) ⇒ Object
Delete Table.
-
#get(name) ⇒ Object
(also: #table)
Get Table.
-
#list(options = {}) ⇒ Object
List tables in this project.
Methods inherited from ServiceObject
build, #client, #initialize, #project, service_pool
Constructor Details
This class inherits a constructor from Aliyun::Odps::ServiceObject
Instance Method Details
#create(name, schema, options = {}) ⇒ Object
Create Table
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/aliyun/odps/model/tables.rb', line 56 def create(name, schema, = {}) Utils.stringify_keys!() table = Table.new(name: name, schema: schema, project: project) table.comment = ['comment'] if .key?('comment') task = InstanceTask.new(name: 'SQLCreateTableTask', type: 'SQL', query: generate_create_sql(table)) instance = project.instances.create([task]) instance.wait_for_success table end |
#delete(name) ⇒ Object
Delete Table
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/aliyun/odps/model/tables.rb', line 75 def delete(name) table = Table.new(name: name, project: project) task = InstanceTask.new( name: 'SQLDropTableTask', type: 'SQL', query: generate_drop_sql(table) ) instance = project.instances.create([task]) instance.wait_for_success true end |
#get(name) ⇒ Object Also known as: table
Get Table
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/aliyun/odps/model/tables.rb', line 31 def get(name) path = "/projects/#{project.name}/tables/#{name}" resp = client.get(path) build_table( Utils.dig_value(resp.parsed_response, 'Table') .merge( 'creation_time' => resp.headers['x-odps-creation-time'], 'last_modified' => resp.headers['Last-Modified'], 'owner' => resp.headers['x-odps-owner'] ) ) end |
#list(options = {}) ⇒ Object
List tables in this project
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/aliyun/odps/model/tables.rb', line 14 def list( = {}) Utils.stringify_keys!() path = "/projects/#{project.name}/tables" query = Utils.hash_slice(, 'name', 'owner', 'marker', 'maxitems') query.merge!(tables: true, expectmarker: true) result = client.get(path, query: query).parsed_response Aliyun::Odps::List.build(result, %w(Tables Table)) do |hash| build_table(hash) end end |