class Dag::Table

Attributes

cluster_name[R]
comment[R]
created_at[R]
db_name[R]
format[R]
location[R]
modified_at[R]
name[R]

Public Class Methods

json_agent_partition_keys?(partition) click to toggle source
# File lib/dag/client/model/table.rb, line 37
def self.json_agent_partition_keys?(partition)
  (partition['name'] == 'date' && partition['type'] == 'string') ||
    (partition['name'] == 'hour' && partition['type'] == 'string')
end
new(api, cluster_name, db_name, params: {}) click to toggle source
Calls superclass method Dag::Model::new
# File lib/dag/client/model/table.rb, line 3
def initialize(api, cluster_name, db_name, params: {})
  super(api)
  @cluster_name = cluster_name
  @db_name = db_name
  load_table_info(params)
end

Public Instance Methods

current_schema() click to toggle source
# File lib/dag/client/model/table.rb, line 31
def current_schema
  @columns.map { |c| "#{c['name']} #{c['type']}" }.join(", ") if @columns.present?
end
Also aliased as: schema
delete() click to toggle source
# File lib/dag/client/model/table.rb, line 27
def delete
  @api.delete_table(@cluster_name, @db_name, @name)
end
schema()
Alias for: current_schema
update(schema: nil, format: nil, comment: nil) click to toggle source
# File lib/dag/client/model/table.rb, line 12
def update(schema: nil, format: nil, comment: nil)
  parameters = {
    table: @name,
    comment: comment || @comment,
    format: format || @table_info['format'],
    schema: schema || current_schema,
  }

  @api.create_table(@cluster_name, @db_name, params: parameters)
  info = @api.table(@cluster_name, @db_name, @name)
  load_table_info(info)

  self
end

Private Instance Methods

load_table_info(params) click to toggle source
# File lib/dag/client/model/table.rb, line 44
def load_table_info(params)
  @table_info = params
  @name = @table_info["tableName"]
  @format = @table_info["format"]
  @comment = @table_info["comment"]
  @location = @table_info["location"]
  @created_at = Time.at(@table_info["createTime"])
  @modified_at = Time.at(@table_info["modifiedTime"])
  @columns = params['columns']
end