Class: Rangefinder::Bigquery
- Inherits:
-
Object
- Object
- Rangefinder::Bigquery
- Defined in:
- lib/rangefinder/bigquery.rb
Instance Method Summary collapse
- #find(namespace, kind, name) ⇒ Object
-
#initialize(options) ⇒ Bigquery
constructor
A new instance of Bigquery.
Constructor Details
#initialize(options) ⇒ Bigquery
Returns a new instance of Bigquery.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rangefinder/bigquery.rb', line 4 def initialize() $logger.info "Starting Bigquery connection" gcloud = [:gcloud] raise "Required gCloud configuration missing" unless gcloud gcloud[:keyfile] = File.(gcloud[:keyfile]) @bigquery = Google::Cloud::Bigquery.new( :project_id => gcloud[:project], :credentials => Google::Cloud::Bigquery::Credentials.new(gcloud[:keyfile]), ) @dataset = @bigquery.dataset(gcloud[:dataset]) raise "\nThere is a problem with the gCloud configuration: \n #{JSON.pretty_generate()}" if @dataset.nil? end |
Instance Method Details
#find(namespace, kind, name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rangefinder/bigquery.rb', line 19 def find(namespace, kind, name) sql = "SELECT DISTINCT module, i.source, m.source AS repo FROM `bto-dataops-datalake-prod.community.forge_itemized` AS i JOIN `bto-dataops-datalake-prod.community.forge_modules` AS m ON m.slug = i.module WHERE kind = @kind AND element = @name" data = @dataset.query(sql, params: {kind: kind.to_s, name: name}) exact, near = data.partition {|row| row[:source] == namespace and not namespace.nil?} { :kind => kind, :name => name, :exact => exact, :near => near, } end |