Class: BigShift::BigQuery::Dataset
- Inherits:
-
Object
- Object
- BigShift::BigQuery::Dataset
- Defined in:
- lib/bigshift/big_query/dataset.rb
Instance Method Summary collapse
- #create_table(table_name, options = {}) ⇒ Object
-
#initialize(big_query_service, project_id, dataset_id, options = {}) ⇒ Dataset
constructor
A new instance of Dataset.
- #table(table_name) ⇒ Object
Constructor Details
#initialize(big_query_service, project_id, dataset_id, options = {}) ⇒ Dataset
Returns a new instance of Dataset.
4 5 6 7 8 9 |
# File 'lib/bigshift/big_query/dataset.rb', line 4 def initialize(big_query_service, project_id, dataset_id, ={}) @big_query_service = big_query_service @project_id = project_id @dataset_id = dataset_id @logger = [:logger] || NullLogger::INSTANCE end |
Instance Method Details
#create_table(table_name, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bigshift/big_query/dataset.rb', line 22 def create_table(table_name, ={}) table_reference = Google::Apis::BigqueryV2::TableReference.new( project_id: @project_id, dataset_id: @dataset_id, table_id: table_name ) if [:schema] fields = [:schema]['fields'].map { |f| Google::Apis::BigqueryV2::TableFieldSchema.new(name: f['name'], type: f['type'], mode: f['mode']) } schema = Google::Apis::BigqueryV2::TableSchema.new(fields: fields) end table_spec = {} table_spec[:table_reference] = table_reference table_spec[:schema] = schema if schema table_data = Google::Apis::BigqueryV2::Table.new(table_spec) table_data = @big_query_service.insert_table(@project_id, @dataset_id, table_data) Table.new(@big_query_service, table_data, logger: @logger) end |
#table(table_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bigshift/big_query/dataset.rb', line 11 def table(table_name) table_data = @big_query_service.get_table(@project_id, @dataset_id, table_name) Table.new(@big_query_service, table_data, logger: @logger) rescue Google::Apis::ClientError => e if e.status_code == 404 nil else raise end end |