Hi all! When I run this code for BigQuery Connecti...
# gd-beginners
r
Hi all! When I run this code for BigQuery Connection:
Copy code
# encoding: utf-8
require 'gooddata'
require 'json'

input_data = JSON.parse(ARGV[0])

bigquery_ds_model = {
  'dataSource' => {
    'name' => input_data["dataSource"]["name"],
    'alias' => input_data["dataSource"]["alias"],
    'prefix' => input_data["dataSource"]["prefix"],
    'connectionInfo' => {
      'bigQuery' => {
        'authentication' => {
          'serviceAccount' => {
            'clientEmail' => input_data["dataSource"]["authentication"]["clientEmail"],
            'privateKey' => input_data["dataSource"]["authentication"]["privateKey"]
          }
        },
        'project' => input_data["dataSource"]["project"]
      }
    }
  }
}

client = GoodData.connect
bigquery_ds = client.create(GoodData::DataSource, bigquery_ds_model)
bigquery_ds.save
I get this error: .rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/gooddata-2.2.0/lib/gooddata/rest/client.rb109in `connect’: No username specified (ArgumentError) am i supposed to pass clientEmail and privateKey to connect?
m
Hi Ramsha, yes, this information is required as per the example here:
Copy code
# encoding: utf-8

require 'gooddata'

bigquery_ds_model = {
          'dataSource' => {
              'name' => 'My Data Source',
              'alias' => 'ds_alias',
              'prefix' => 'ds_prefix_',
              'connectionInfo' => {
                  'bigQuery' => {
                      'authentication' => {
                          'serviceAccount' => {
                              'clientEmail' => '<mailto:test@abc.com|test@abc.com>',
                              'privateKey' => '***'
                          }
                      },
                      'project' => 'project_test',
                      'schema' => 'schema_test'
                  }
              }
          }
      }
client = GoodData.connect
bigquery_ds = client.create(GoodData::DataSource, bigquery_ds_model)
bigquery_ds.save
For example:
Copy code
#!/usr/bin/env ruby

require 'rubygems'
require 'sequel'
require 'jdbc/dss'

Jdbc::DSS.load_driver
Java.com.gooddata.dss.jdbc.driver.DssDriver

# replace with your Data Warehouse instance:
dss_jdbc_url = 'jdbc:gdc:<datawarehouse://secure.gooddata.com/gdc/datawarehouse/instances/[DW_ID]>'
# replace with your GoodData platform login name:
username = '<mailto:joe.user@example.com|joe.user@example.com>'
# replace with your GoodData platform password:
password = 'MyPassword'

# example query 
Sequel.connect dss_jdbc_url, :username => username, :password => password do |conn|
  conn.run "CREATE TABLE IF NOT EXISTS my_first_table (id INT, value VARCHAR(255))"
  conn.run "INSERT INTO my_first_table (id, value) VALUES (1, 'one')"
  conn.run "INSERT INTO my_first_table (id, value) VALUES (2, 'two')"
  conn.fetch "SELECT * FROM my_first_table WHERE id < ?", 3 do |row|
    puts row
  end
end
r
but in the example u just shared, connect doesnt take username or password in it - just like how i wrote it
Copy code
client = GoodData.connect
bigquery_ds = client.create(GoodData::DataSource, bigquery_ds_model)
bigquery_ds.save
even if i make the google cloud connection manually in the UI, username password doesnt show up under connection settings as it does in a mysql connection
i am passing client email and credentials to it from a google cloud user in the datasource ServiceAccount - if i try the same credentials in connect, it doesnt work
and if i try the same credentials with which i can make the manual BigQuery connection on Gooddata inside connect(), i get this error: .rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb249in `exception_with_response’: 401 Unauthorized (RestClient::Unauthorized)
m
I noticed your new question right after this one. Could you confirm you were able to connect to your data base? Was the linked documentation helpful?
r
i was able to connect but in documentation it doesnt mention that i need admin user, password and server. I had to add those in connect. Documentation leaves them blank