Class: TreasureData::Table

Inherits:
Model
  • Object
show all
Defined in:
lib/td/client/model.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#client

Instance Method Summary collapse

Constructor Details

#initialize(client, db_name, table_name, type, schema, count, created_at = nil, updated_at = nil, estimated_storage_size = nil, last_import = nil, last_log_timestamp = nil, expire_days = nil, include_v = false) ⇒ Table

Returns a new instance of Table.

Parameters:

  • client (TreasureData::Client)
  • db_name (String)
  • table_name (String)
  • type (String)
  • schema (String)
  • count (Fixnum)
  • created_at (String) (defaults to: nil)
  • updated_at (String) (defaults to: nil)
  • estimated_storage_size (Fixnum) (defaults to: nil)
  • last_import (String) (defaults to: nil)
  • last_log_timestamp (String) (defaults to: nil)
  • expire_days (Fixnum, String) (defaults to: nil)


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/td/client/model.rb', line 156

def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil, estimated_storage_size=nil, last_import=nil, last_log_timestamp=nil, expire_days=nil, include_v=false)
  super(client)
  @database = nil
  @db_name = db_name
  @table_name = table_name
  @type = type
  @schema = schema
  @count = count
  @created_at = created_at
  @updated_at = updated_at
  @estimated_storage_size = estimated_storage_size
  @last_import = last_import
  @last_log_timestamp = last_log_timestamp
  @expire_days = expire_days
  @include_v = include_v
end

Instance Attribute Details

#countObject (readonly)



179
# File 'lib/td/client/model.rb', line 179

attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size, :include_v

#db_nameObject (readonly) Also known as: database_name



179
# File 'lib/td/client/model.rb', line 179

attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size, :include_v

#estimated_storage_sizeObject (readonly)



179
# File 'lib/td/client/model.rb', line 179

attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size, :include_v

#include_vObject (readonly)

Returns the value of attribute include_v.



179
180
181
# File 'lib/td/client/model.rb', line 179

def include_v
  @include_v
end

#schemaObject (readonly)



179
# File 'lib/td/client/model.rb', line 179

attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size, :include_v

#table_nameObject (readonly) Also known as: name



179
# File 'lib/td/client/model.rb', line 179

attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size, :include_v

#typeObject (readonly)



179
180
181
# File 'lib/td/client/model.rb', line 179

def type
  @type
end

Instance Method Details

#created_atTime?

Returns:

  • (Time, nil)


190
191
192
# File 'lib/td/client/model.rb', line 190

def created_at
  @created_at && !@created_at.empty? ? Time.parse(@created_at) : nil
end

#databaseDatabase

Returns:



215
216
217
218
# File 'lib/td/client/model.rb', line 215

def database
  update_database! unless @database
  @database
end

#database=(database) ⇒ Object

Parameters:

  • database (String)


185
186
187
# File 'lib/td/client/model.rb', line 185

def database=(database)
  @database = database if database.instance_of?(Database)
end

#deleteSymbol

Returns:

  • (Symbol)


232
233
234
# File 'lib/td/client/model.rb', line 232

def delete
  @client.delete_table(@db_name, @table_name)
end

#estimated_storage_size_stringString

Returns:

  • (String)


258
259
260
261
262
263
264
265
266
267
268
# File 'lib/td/client/model.rb', line 258

def estimated_storage_size_string
  if @estimated_storage_size <= 1024*1024
    return "0.0 GB"
  elsif @estimated_storage_size <= 60*1024*1024
    return "0.01 GB"
  elsif @estimated_storage_size <= 60*1024*1024*1024
    "%.1f GB" % (@estimated_storage_size.to_f / (1024*1024*1024))
  else
    "%d GB" % (@estimated_storage_size.to_f / (1024*1024*1024)).to_i
  end
end

#expire_daysFixnum?

Returns:

  • (Fixnum, nil)


210
211
212
# File 'lib/td/client/model.rb', line 210

def expire_days
  @expire_days ? @expire_days.to_i : nil
end

#export(storage_type, opts = {}) ⇒ Job

Parameters:

  • storage_type (String)
  • opts (Hash) (defaults to: {})

Returns:



253
254
255
# File 'lib/td/client/model.rb', line 253

def export(storage_type, opts={})
  @client.export(@db_name, @table_name, storage_type, opts)
end

#identifierString

Returns:

  • (String)


227
228
229
# File 'lib/td/client/model.rb', line 227

def identifier
  "#{@db_name}.#{@table_name}"
end

#import(format, stream, size) ⇒ Float

Parameters:

  • format (String)
  • stream (String, StringIO)
  • size (Fixnum)

Returns:

  • (Float)


246
247
248
# File 'lib/td/client/model.rb', line 246

def import(format, stream, size)
  @client.import(@db_name, @table_name, format, stream, size)
end

#inspectString

Returns:

  • (String)


275
276
277
278
# File 'lib/td/client/model.rb', line 275

def inspect
  %[#<%s:%#0#{1.size*2}x @db_name="%s" @table_name="%s">] %
  [self.class.name, self.__id__*2, @db_name, @table_name]
end

#last_importTime?

Returns:

  • (Time, nil)


200
201
202
# File 'lib/td/client/model.rb', line 200

def last_import
  @last_import && !@last_import.empty? ? Time.parse(@last_import) : nil
end

#last_log_timestampTime?

Returns:

  • (Time, nil)


205
206
207
# File 'lib/td/client/model.rb', line 205

def last_log_timestamp
  @last_log_timestamp && !@last_log_timestamp.empty? ? Time.parse(@last_log_timestamp) : nil
end

#permissionString

get the database’s permission as if they were the table’s

Returns:

  • (String)


222
223
224
# File 'lib/td/client/model.rb', line 222

def permission
  database.permission
end

#tail(count) ⇒ Array?

Parameters:

  • count (Fixnum)

Returns:

  • (Array, nil)


238
239
240
# File 'lib/td/client/model.rb', line 238

def tail(count)
  @client.tail(@db_name, @table_name, count)
end

#update_database!Object



270
271
272
# File 'lib/td/client/model.rb', line 270

def update_database!
  @database = @client.database(@db_name)
end

#updated_atTime?

Returns:

  • (Time, nil)


195
196
197
# File 'lib/td/client/model.rb', line 195

def updated_at
  @updated_at && !@updated_at.empty? ? Time.parse(@updated_at) : nil
end