class RbBigQuery::Table
Attributes
schema[RW]
Public Class Methods
new(client, dataset, table_id, schema)
click to toggle source
# 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
Public Instance Methods
create()
click to toggle source
@return [Hash] row response json
# 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)
click to toggle source
insert rows @param rows [Array<Hash>] [{#{column_name}=>value}] @return [Hash] row response json
# 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()
click to toggle source
@return [String] GQL style table name. (dataset.table_id)
# File lib/rbbigquery/table.rb, line 15 def sql_name "#{@dataset}.#{@table_id}" end