Module: TreasureData::API::Table
- Included in:
- TreasureData::API
- Defined in:
- lib/td/client/api/table.rb
Instance Method Summary collapse
- #change_database(db, table, dest_db) ⇒ Object
- #create_log_table(db, table, params = {}) ⇒ true
- #delete_table(db, table) ⇒ Symbol
- #list_tables(db) ⇒ Array
- #swap_table(db, table1, table2) ⇒ true
- #tail(db, table, count, to = nil, from = nil, &block) ⇒ Array?
- #update_expire(db, table, expire_days) ⇒ true
- #update_schema(db, table, schema_json) ⇒ true
- #update_table(db, table, params = {}) ⇒ true
Instance Method Details
#change_database(db, table, dest_db) ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/td/client/api/table.rb', line 143 def change_database(db, table, dest_db) params = { 'dest_database_name' => dest_db } code, body, res = post("/v3/table/change_database/#{e db}/#{e table}", params) if code != "200" raise_error("Change database failed", res) end return true end |
#create_log_table(db, table, params = {}) ⇒ true
38 39 40 |
# File 'lib/td/client/api/table.rb', line 38 def create_log_table(db, table, params={}) create_table(db, table, :log, params) end |
#delete_table(db, table) ⇒ Symbol
106 107 108 109 110 111 112 113 114 |
# File 'lib/td/client/api/table.rb', line 106 def delete_table(db, table) code, body, res = post("/v3/table/delete/#{e db}/#{e table}") if code != "200" raise_error("Delete table failed", res) end js = checked_json(body, %w[]) type = (js['type'] || '?').to_sym return type end |
#list_tables(db) ⇒ Array
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/td/client/api/table.rb', line 10 def list_tables(db) code, body, res = get("/v3/table/list/#{e db}") if code != "200" raise_error("List tables failed", res) end js = checked_json(body, %w[tables]) result = {} js["tables"].map {|m| name = m['name'] type = (m['type'] || '?').to_sym count = (m['count'] || 0).to_i # TODO? created_at = m['created_at'] updated_at = m['updated_at'] last_import = m['counter_updated_at'] = m['last_log_timestamp'] estimated_storage_size = m['estimated_storage_size'].to_i schema = JSON.parse(m['schema'] || '[]') expire_days = m['expire_days'] include_v = m['include_v'] result[name] = [type, schema, count, created_at, updated_at, estimated_storage_size, last_import, , expire_days, include_v] } return result end |
#swap_table(db, table1, table2) ⇒ true
61 62 63 64 65 66 67 |
# File 'lib/td/client/api/table.rb', line 61 def swap_table(db, table1, table2) code, body, res = post("/v3/table/swap/#{e db}/#{e table1}/#{e table2}") if code != "200" raise_error("Swap tables failed", res) end return true end |
#tail(db, table, count, to = nil, from = nil, &block) ⇒ Array?
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/td/client/api/table.rb', line 121 def tail(db, table, count, to = nil, from = nil, &block) unless to.nil? and from.nil? warn('parameter "to" and "from" no longer work') end params = {'format' => 'msgpack'} params['count'] = count.to_s if count code, body, res = get("/v3/table/tail/#{e db}/#{e table}", params) if code != "200" raise_error("Tail table failed", res) end if block MessagePack::Unpacker.new.feed_each(body, &block) nil else result = [] MessagePack::Unpacker.new.feed_each(body) {|row| result << row } return result end end |
#update_expire(db, table, expire_days) ⇒ true
85 86 87 |
# File 'lib/td/client/api/table.rb', line 85 def update_expire(db, table, expire_days) update_table(db, table, {:expire_days=>expire_days}) end |
#update_schema(db, table, schema_json) ⇒ true
73 74 75 76 77 78 79 |
# File 'lib/td/client/api/table.rb', line 73 def update_schema(db, table, schema_json) code, body, res = post("/v3/table/update-schema/#{e db}/#{e table}", {'schema'=>schema_json}) if code != "200" raise_error("Create schema table failed", res) end return true end |
#update_table(db, table, params = {}) ⇒ true
95 96 97 98 99 100 101 |
# File 'lib/td/client/api/table.rb', line 95 def update_table(db, table, params={}) code, body, res = post("/v3/table/update/#{e db}/#{e table}", params) if code != "200" raise_error("Update table failed", res) end return true end |