Class: RbBigQuery::Table
- Inherits:
-
Object
- Object
- RbBigQuery::Table
- Defined in:
- lib/rbbigquery/table.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#create ⇒ Hash
Row response json.
-
#initialize(client, dataset, table_id, schema) ⇒ Table
constructor
A new instance of Table.
-
#insert(rows) ⇒ Hash
insert rows.
-
#sql_name ⇒ String
GQL style table name.
Constructor Details
#initialize(client, dataset, table_id, schema) ⇒ Table
Returns a new instance of Table.
5 6 7 8 9 10 11 12 |
# File 'lib/rbbigquery/table.rb', line 5 def initialize(client, dataset, table_id, schema) @client = client @dataset = dataset @table_id = table_id @schema = schema create end |
Instance Attribute Details
#schema ⇒ Object
Returns the value of attribute schema.
3 4 5 |
# File 'lib/rbbigquery/table.rb', line 3 def schema @schema end |
Instance Method Details
#create ⇒ Hash
Returns row response json.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rbbigquery/table.rb', line 20 def create response = @client.client.execute({ :api_method => @client.bq.tables.insert, :parameters => { 'projectId' => @client.project_id, 'datasetId' => @dataset }, :body_object => { 'tableReference' => { 'projectId' => @client.project_id, 'datasetId' => @dataset, 'tableId' => @table_id }, 'schema' => { 'fields' => @schema } } }) JSON.parse(response.body) end |
#insert(rows) ⇒ Hash
insert rows
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rbbigquery/table.rb', line 45 def insert(rows) rows = rows.map { |row| {'json' => row} } response = @client.client.execute({ :api_method => @client.bq.tabledata.insert_all, :parameters => { 'projectId' => @client.project_id, 'datasetId' => @dataset, 'tableId' => @table_id, }, :body_object => { "rows" => rows } }) JSON.parse(response.body) end |
#sql_name ⇒ String
Returns GQL style table name. (dataset.table_id).
15 16 17 |
# File 'lib/rbbigquery/table.rb', line 15 def sql_name "#{@dataset}.#{@table_id}" end |