Connecting to BigQuery
PopSQL allows two ways to connect to your BigQuery data warehouse: OAuth and Service Account. The initial steps for creating the connecting are the same, and then the differences are separated below. If you choose to share the connection, then it must be shared as a cloud connection. OAuth connections can only be made on cloud connections.
Creating a new BigQuery Connection
- Open the connections page in preferences, see managing connections for more information.
- Click the
Add new Connection
button at the top of the connections page.
- Select
BigQuery
from the list.
- Give a
Connection name
for your own internal reference.
Using a Service Account
You'll need to be an owner in your Google Cloud project to create a service account. If you're not, please contact the administrator of your BigQuery database.
- Visit the Credentials page in Google Cloud Console
- Select your project
- Click
Create credentials
, and thenService account key
- Name your service account (ie "PopSQL BigQuery" or your full name) and click
CREATE AND CONTINUE
.
- We recommend setting the role to
BigQuery Admin
and clickCONTINUE
for step 3.- If you have more detailed security requirements, just be sure to add the
BigQuery Job User
andBigQuery Data Viewer
roles for all projects you plan to run queries on, at minimum. - If you need to give your service account access to other BigQuery projects, copy the service account email address, navigate to the IAM page, and add the service account as a user of the other projects. Again, either give the account the
BigQuery Admin
role, or at minimumBigQuery Job User
andBigQuery Data Viewer
to ensure queries work in PopSQL.
- If you have more detailed security requirements, just be sure to add the
- Click
DONE
to complete set-up.
- Click on your newly created service account under the credentials page.
- Select
KEYS
and thenADD KEY
then onCreate new key
- Select
JSON
as the key type and then clickCREATE
- Download the .json file, open it in a text editor, and copy the entire file contents to your clipboard.
- Within PopSQL, under the
How would you like to connect
dropdown, select theService Account
option. - Paste the contents of your clipboard (the .json file contents) into the Service account field.
- Toggle connection type for direct or cloud (only available if not sharing connection).
Using OAuth
- Under the
How to connect
dropdown, select theOAuth
option. - Click the
Sign in with Google
button. You will be taken to an external page hosted by Google for authentication.- Note: the
BigQuery Admin
role is recommended for whatever Google user you use. If you have more detailed security requirements, just be sure to add theBigQuery Job User
andBigQuery Data Viewer
roles for all projects you plan to run queries on, at minimum.
- Note: the
- Upon successful authentication, return to PopSQL.
- Enter the Project ID of your desired
BigQuery Project
. If you have multiple projects, this will be the default project in the PopSQL SQL editor when you run queries on this BigQuery connection.
BigQuery Cost Estimator
On the connections page, you will see a setting called "See BigQuery's estimate of the number of bytes read before running your query":
If you turn on that setting, you will see a cost estimate next to the Run Button in your query editor. The cost estimate is calculated by taking the bytes of data the query will process multiplied by a standard conversion of $5.00 per TB to determine the estimated cost of running that query.
Restricting access to specific tables
If you want to restrict PopSQL's access to only specific tables (or specific datasets or views) you'll need to use a service account to connect to PopSQL. You can grant/revoke access to tables, views, datasets using BigQuery IAM resource access.
Querying from Google Docs
If you wish to query from Google Docs, please contact us and we can manually enable a setting to allow this. Additionally, you will need to make sure the email address associated with the service account (e.g. [email protected]
) or your oauth account has been given access to the Google Doc you are wishing to query from.
Wrapping up
Finally, share the connection with your team. Once you're connected using
either of the above methods, try the following query:
SELECT title FROM `bigquery-public-data.samples.wikipedia` LIMIT 5;
Happy querying! 🍭
Updated about 1 year ago