Class: BigQueryAdapter::Connection
- Inherits:
-
Object
- Object
- BigQueryAdapter::Connection
- Defined in:
- lib/big_query_adapter/connection.rb
Overview
Driver for bigquery connection
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #columns(table_name) ⇒ Object
-
#initialize(project:, keyfile:, timeout: nil, datasets: []) ⇒ Connection
constructor
A new instance of Connection.
- #run(statement) ⇒ Object
- #tables ⇒ Object
Constructor Details
#initialize(project:, keyfile:, timeout: nil, datasets: []) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 18 19 |
# File 'lib/big_query_adapter/connection.rb', line 11 def initialize(project:, keyfile:, timeout: nil, datasets: []) @project = project @bigquery = Google::Cloud::Bigquery.new( project: project, keyfile: keyfile ) @dataset_ids = datasets @timeout = timeout.to_i if timeout end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
9 10 11 |
# File 'lib/big_query_adapter/connection.rb', line 9 def project @project end |
Instance Method Details
#columns(table_name) ⇒ Object
43 44 45 46 47 |
# File 'lib/big_query_adapter/connection.rb', line 43 def columns(table_name) table_schema = table_schema(table_name) return [] if table_schema.fields.nil? table_schema.fields end |
#run(statement) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/big_query_adapter/connection.rb', line 21 def run(statement) columns = [] rows = [] = {} [:timeout] = @timeout if @timeout results = @bigquery.query(statement, ) # ms if results.complete? columns = results.first.keys.map(&:to_s) unless results.empty? rows = results.map(&:values) end Result.new(columns, rows) end |
#tables ⇒ Object
36 37 38 39 40 41 |
# File 'lib/big_query_adapter/connection.rb', line 36 def tables table_refs .map { |table_ref| table_ref_name(table_ref) } .group_by { |table_ref_name| table_ref_wildcard_name(table_ref_name) } .keys end |