Module: BigQuery::Tables

Included in:
Client
Defined in:
lib/bigquery-client/tables.rb

Instance Method Summary collapse

Instance Method Details

#create_table(name, schema) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bigquery-client/tables.rb', line 5

def create_table(name, schema)
  result = access_api(
    api_method: bigquery.tables.insert,
    body_object: {
      tableReference: {
        tableId: name
      },
      schema: {
        fields: schema
      }
    }
  )
  handle_error(result) if result.error?
end

#drop_table(name) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/bigquery-client/tables.rb', line 68

def drop_table(name)
  result = access_api(
    api_method: bigquery.tables.delete,
    parameters: {
      tableId: name
    }
  )
  handle_error(result) if result.error?
end

#fetch_schema(table) ⇒ Object



53
54
55
# File 'lib/bigquery-client/tables.rb', line 53

def fetch_schema(table)
  fetch_table_info(table)['schema']['fields']
end

#fetch_table_info(table) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/bigquery-client/tables.rb', line 57

def fetch_table_info(table)
  result = access_api(
    api_method: bigquery.tables.get,
    parameters: {
      tableId: table
    }
  )
  handle_error(result) if result.error?
  JSON.parse(result.body)
end

#list_tables(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/bigquery-client/tables.rb', line 20

def list_tables(options = {})
  result = access_api(
    api_method: bigquery.tables.list,
    parameters: options
  )
  handle_error(result) if result.error?
  JSON.parse(result.body)
end

#patch_table(name, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bigquery-client/tables.rb', line 41

def patch_table(name, options = {})
  result = access_api(
    api_method: bigquery.tables.patch,
    parameters: {
      tableId: name
    },
    body_object: options
  )
  handle_error(result) if result.error?
  JSON.parse(result.body)
end

#update_table(name, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bigquery-client/tables.rb', line 29

def update_table(name, options = {})
  result = access_api(
    api_method: bigquery.tables.update,
    parameters: {
      tableId: name
    },
    body_object: options
  )
  handle_error(result) if result.error?
  JSON.parse(result.body)
end