Class: Dag::TableCollection

Inherits:
Model
  • Object
show all
Includes:
Client::ClusterValidation, Enumerable
Defined in:
lib/dag/client/model/table_collection.rb

Constant Summary

Constants included from Client::ClusterValidation

Client::ClusterValidation::VALID_WHERE_KEYS

Instance Attribute Summary collapse

Attributes inherited from Model

#api

Instance Method Summary collapse

Methods included from Client::ClusterValidation

#cluster_norm?, #cluster_norm_or_ptfailed?, #cluster_restart_status?, #cluster_status, #valid_cluster_info_list_status?, #valid_cluster_status?, #validate_cluster, #validate_cluster_param_keys

Constructor Details

#initialize(api, cluster_name, db_name) ⇒ TableCollection

Returns a new instance of TableCollection.



8
9
10
11
12
13
# File 'lib/dag/client/model/table_collection.rb', line 8

def initialize(api, cluster_name, db_name)
  super(api)

  @cluster_name = cluster_name
  @db_name = db_name
end

Instance Attribute Details

#cluster_nameObject (readonly)

Returns the value of attribute cluster_name.



6
7
8
# File 'lib/dag/client/model/table_collection.rb', line 6

def cluster_name
  @cluster_name
end

Instance Method Details

#create(table: '', format: nil, schema: nil, comment: nil) ⇒ Object

parameters ==

  • table - table name

  • format - ‘csv’ or ‘tsv’ or ‘json’ or ‘json_agent’

  • <tt>schema/tt> - schema

  • comment - comment



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dag/client/model/table_collection.rb', line 34

def create(table: '', format: nil, schema: nil, comment: nil)
  params = {
    table: table,
    schema: schema,
    create_api: true
  }
  params.merge!({ format: format }) if format
  params.merge!({ comment: comment }) if comment

  @api.create_table(@cluster_name, @db_name, params: params)
  table_info = @api.table(@cluster_name, @db_name, table)
  Dag::Table.new(@api, @cluster_name, @db_name, params: table_info)
end

#eachObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dag/client/model/table_collection.rb', line 15

def each
  marker = nil
  truncated = false
  begin
    table_info_list = @api.table_info_list(@cluster_name, @db_name, make_options(marker))
    table_info_list['tables'].each do |table_info|
      yield Dag::Table.new(@api, @cluster_name, @db_name, params: table_info)
    end
    truncated = table_info_list['isTruncated']
    marker = table_info_list['nextMarker']
  end while truncated
end