Module: Dag::Client::Database

Includes:
ClusterValidation
Included in:
Dag::Client
Defined in:
lib/dag/client/database.rb

Constant Summary

Constants included from ClusterValidation

ClusterValidation::VALID_WHERE_KEYS

Instance Method Summary collapse

Methods included from 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

Instance Method Details

#create_database(db_name) ⇒ Object



12
13
14
15
16
17
# File 'lib/dag/client/database.rb', line 12

def create_database(db_name)
  validate_cluster

  @api.create_database(@cluster_name, db_name)
  Dag::Database.new(@api, @cluster_name, db_name)
end

#create_table(db_name, tbl_name, 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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dag/client/database.rb', line 50

def create_table(db_name, tbl_name, format: nil, schema: nil, comment: nil)
  validate_cluster

  params = {
    table: tbl_name,
    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, tbl_name)
  Dag::Table.new(@api, @cluster_name, db_name, params: table_info)
end

#database(db_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dag/client/database.rb', line 19

def database(db_name)
  validate_cluster

  raise Dag::Client::ParameterInvalid.new("db_name is blank")if db_name.blank?

  unless db = databases.detect { |d| d.db_name == db_name }
    raise Dag::Client::DatabaseNotFound.new('Database not found')
  end

  db
end

#databasesObject



6
7
8
9
10
# File 'lib/dag/client/database.rb', line 6

def databases
  validate_cluster

  Dag::DatabaseCollection.new(@api, @cluster_name, cluster_status: @cluster_status)
end

#split_table(db_name, tbl_name, params) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dag/client/database.rb', line 66

def split_table(db_name, tbl_name, params)
  unless cluster_norm?
    raise Dag::Client::StatusInvalid.new("cluster status is invalid: #{cluster_status}")
  end

  split_info = @api.split_table(@cluster_name, db_name, tbl_name, params)
  job_id = split_info['queryId']

  query_info = @api.query_info(job_id)
  Dag::Job.new(@api, query_info)
end

#table(db_name, tbl_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dag/client/database.rb', line 31

def table(db_name, tbl_name)
  validate_cluster

  raise Dag::Client::ParameterInvalid.new("db_name is blank")if db_name.blank?
  raise Dag::Client::ParameterInvalid.new("tbl_name is blank")if tbl_name.blank?

  unless table_info = @api.table(@cluster_name, db_name, tbl_name)
    raise Dag::Client::TableNotFound.new('Table not found')
  end

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