Module: BigQuery::Client::Tables
- Included in:
- BigQuery::Client
- Defined in:
- lib/big_query/client/tables.rb
Constant Summary collapse
- ALLOWED_FIELD_TYPES =
['STRING', 'INTEGER', 'FLOAT', 'BOOLEAN', 'RECORD', 'TIMESTAMP']
- ALLOWED_FIELD_MODES =
['NULLABLE', 'REQUIRED', 'REPEATED']
Instance Method Summary collapse
-
#create_table(tableId, schema = {}) ⇒ Object
Creating a new table.
-
#delete_table(tableId) ⇒ Object
Deletes the given tableId.
-
#describe_table(tableId, dataset = @dataset) ⇒ Hash
Describe the schema of the given tableId.
-
#insert(tableId, opts) ⇒ Hash
insert row into table.
-
#table_data(tableId, dataset = @dataset) ⇒ Hash
Returns all rows of table data.
-
#tables(dataset = @dataset) ⇒ Hash
Lists the tables.
-
#tables_formatted(dataset = @dataset) ⇒ Hash
Lists the tables returnning only the tableId.
Instance Method Details
#create_table(tableId, schema = {}) ⇒ Object
Creating a new table
examples:
@bq.create_table(‘new_table’, id: { type: ‘INTEGER’, mode: ‘required’ }) @bq.create_table(‘new_table’, price: { type: ‘FLOAT’ })
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/big_query/client/tables.rb', line 72 def create_table(tableId, schema={}) api( api_method: @bq.tables.insert, parameters: { "datasetId" => @dataset }, body_object: { "tableReference" => { "tableId" => tableId, "projectId" => @project_id, "datasetId" => @dataset }, "schema" => { "fields" => validate_schema(schema) } } ) end |
#delete_table(tableId) ⇒ Object
Deletes the given tableId
91 92 93 94 95 96 |
# File 'lib/big_query/client/tables.rb', line 91 def delete_table(tableId) api(api_method: @bq.tables.delete, parameters: { 'tableId' => tableId, 'datasetId' => @dataset } ) end |
#describe_table(tableId, dataset = @dataset) ⇒ Hash
Describe the schema of the given tableId
103 104 105 106 107 108 109 |
# File 'lib/big_query/client/tables.rb', line 103 def describe_table(tableId, dataset = @dataset) api( api_method: @bq.tables.get, parameters: { 'tableId' => tableId, 'datasetId' => @dataset } ) end |
#insert(tableId, opts) ⇒ Hash
insert row into table
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/big_query/client/tables.rb', line 48 def insert(tableId, opts) if opts.class == Array body = { 'rows' => opts = opts.map{|x| {"json" => x}} } else body = { 'rows' => [{ 'json' => opts }] } end api( api_method: @bq.tabledata.insert_all, parameters: { 'tableId' => tableId, 'datasetId' => @dataset }, body_object: body ) end |
#table_data(tableId, dataset = @dataset) ⇒ Hash
Returns all rows of table data
36 37 38 39 40 41 |
# File 'lib/big_query/client/tables.rb', line 36 def table_data(tableId, dataset = @dataset) response = api(api_method: @bq.tabledata.list, parameters: { 'datasetId' => dataset, 'tableId' => tableId }) response['rows'] || [] end |
#tables(dataset = @dataset) ⇒ Hash
Lists the tables
14 15 16 17 18 19 20 21 |
# File 'lib/big_query/client/tables.rb', line 14 def tables(dataset = @dataset) response = api({ :api_method => @bq.tables.list, :parameters => {"datasetId" => dataset} }) response['tables'] || [] end |
#tables_formatted(dataset = @dataset) ⇒ Hash
Lists the tables returnning only the tableId
27 28 29 |
# File 'lib/big_query/client/tables.rb', line 27 def tables_formatted(dataset = @dataset) tables(dataset).map { |t| t['tableReference']['tableId'] } end |