Class: Dag::Table

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

Instance Attribute Summary collapse

Attributes inherited from Model

#api

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, cluster_name, db_name, params: {}) ⇒ Table

Returns a new instance of Table.



3
4
5
6
7
8
# 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

Instance Attribute Details

#cluster_nameObject (readonly)

Returns the value of attribute cluster_name.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def cluster_name
  @cluster_name
end

#commentObject (readonly)

Returns the value of attribute comment.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def comment
  @comment
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def created_at
  @created_at
end

#db_nameObject (readonly)

Returns the value of attribute db_name.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def db_name
  @db_name
end

#formatObject (readonly)

Returns the value of attribute format.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def format
  @format
end

#locationObject (readonly)

Returns the value of attribute location.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def location
  @location
end

#modified_atObject (readonly)

Returns the value of attribute modified_at.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def modified_at
  @modified_at
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/dag/client/model/table.rb', line 10

def name
  @name
end

Class Method Details

.json_agent_partition_keys?(partition) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
# 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

Instance Method Details

#current_schemaObject Also known as: schema



31
32
33
# File 'lib/dag/client/model/table.rb', line 31

def current_schema
  @columns.map { |c| "#{c['name']} #{c['type']}" }.join(", ") if @columns.present?
end

#deleteObject



27
28
29
# File 'lib/dag/client/model/table.rb', line 27

def delete
  @api.delete_table(@cluster_name, @db_name, @name)
end

#update(schema: nil, format: nil, comment: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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