JetBrains Rider 2024.2 Help

Create BigQuery data sources

Enable the Database Tools and SQL plugin

This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in JetBrains Rider by default. If the relevant features are not available, make sure that you did not disable the plugin.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.

Official documentation

BigQuery is a REST-based web service that allows you to run complex analytical SQL-based queries under large data sets.

To create a BigQuery data source and test the connection, you can use the following approaches:

Google user account

When you use authorization with the Google user account, you need to receive the authorization code in a web browser.

Connect to BigQuery

  1. In the Database tool window ( View | Tool Windows | Database) , click the New icon New and select Connect to Database.

  2. If you have a connection string for the database defined in your solution or elsewhere, leave the Use connection string option selected and choose BigQuery in the Database type selector.

    Use the String selector to choose the desired connection string from your solution or type it in manually, then click Connect.

  3. You can also choose Add data source manually, click Next and select BigQuery in the Database source selector. Follow the wizard steps to form the connection string by configuring individual options.

  4. To access all available options for the new database connection, click in the Database window, then click the New icon New and select BigQuery.

  5. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    Location for the downloaded JDBC drivers is the JetBrains Rider configuration directory.

    The Download missing driver files link

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  6. From the Authentication list, select Google User Account.

  7. In the Project ID field, type the project ID.

    Usually, it is a part of the service account email that goes after the at sign (@). For example, bigqueryproject-322409. For the project ID's format, refer to the official instructions on creating a service account.

  8. From the Authorization Code Required dialog, cut the URL, paste it into the address bar of your web browser, and press Enter to follow the URL.

  9. Authorize access to your BigQuery application in your Google account.

  10. Copy the authorization code received from Google, paste it in the Authorization Code Required dialog, and click OK.

  11. Ensure that the connection to the database can be established using the provided details. To do that, click the Test Connection link at the bottom of the connection details area.

    Test Connection link

    In case of any connection issues, refer to the Cannot connect to a database page.

  12. (Optional) By default, only the default project and dataset are introspected and available to work with. If you also want to work with other projects and datasets, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  13. Click OK to create the data source.

  14. Find your new data source in the Database tool window (⌘ 1) .

    • For more information about the Database tool window, see the corresponding reference topic.

    • For more information about working with database objects in JetBrains Rider, refer to Database objects.

    • To write and run queries, open the default query console by clicking the data source and pressing F4.

    • To view and edit data of a database object, open Data editor and viewer by double-clicking the object.

Application default credentials

For authorization, the BigQuery driver uses data from a special credentials file — a service account key file. By default, the path to the file is ~/.config/gcloud/application_default_credentials.json.

You can set a custom location for the credentials file by using the GOOGLE_APPLICATION_CREDENTIALS environment variable. Alternatively, set the path to the credentials file in the Service account key file field.

To generate the service account key file for the connection, you need to create a Google Cloud Platform service account.

Step 1. Obtain credentials file

  1. Create a service account by following the official instructions.

    On the Grant this service account access to the project step in the wizard, select roles for this service account.

    For example, for read-only access, select BigQuery Data Viewer, BigQuery Job User, and BigQuery User from the BigQuery menu. Alternatively, select BigQuery | BigQuery Admin for access to all resources within the project.

    For more information about roles and permissions, refer to Predefined roles and permissions at cloud.google.com.

  2. Generate and download the service account key file by following the official instructions.

Step 2. Connect to BigQuery

  1. In the Database tool window ( View | Tool Windows | Database) , click the New icon New and select Connect to Database.

  2. If you have a connection string for the database defined in your solution or elsewhere, leave the Use connection string option selected and choose BigQuery in the Database type selector.

    Use the String selector to choose the desired connection string from your solution or type it in manually, then click Connect.

  3. You can also choose Add data source manually, click Next and select BigQuery in the Database source selector. Follow the wizard steps to form the connection string by configuring individual options.

  4. To access all available options for the new database connection, click in the Database window, then click the New icon New and select BigQuery.

  5. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    Location for the downloaded JDBC drivers is the JetBrains Rider configuration directory.

    The Download missing driver files link

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  6. From the Authentication list, select Application Default Credentials.

  7. In the Service account key file field, type the path to the JSON service account key file that you obtained on Step 1. Obtain credentials.

  8. Ensure that the connection to the database can be established using the provided details. To do that, click the Test Connection link at the bottom of the connection details area.

    Test Connection link

    In case of any connection issues, refer to the Cannot connect to a database page.

  9. (Optional) By default, only the default project and dataset are introspected and available to work with. If you also want to work with other projects and datasets, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  10. Click OK to create the data source.

  11. Find your new data source in the Database tool window (⌘ 1) .

    • For more information about the Database tool window, see the corresponding reference topic.

    • For more information about working with database objects in JetBrains Rider, refer to Database objects.

    • To write and run queries, open the default query console by clicking the data source and pressing F4.

    • To view and edit data of a database object, open Data editor and viewer by double-clicking the object.

Connecting with Application Default Credentials

Google service account

For authorization, the BigQuery driver uses data from a special credentials file — a service account key file. By default, the path to the file is ~/.config/gcloud/application_default_credentials.json.

You can set a custom location for the credentials file by using the GOOGLE_APPLICATION_CREDENTIALS environment variable. Alternatively, set the path to the credentials file in the Key file field.

To generate the service account key file for the connection, you need to create a Google Cloud Platform service account.

Step 1. Obtain credentials file

  1. Create a service account by following the official instructions.

    On the Grant this service account access to the project step in the wizard, select roles for this service account.

    For example, for read-only access, select BigQuery Data Viewer, BigQuery Job User, and BigQuery User from the BigQuery menu. Alternatively, select BigQuery | BigQuery Admin for access to all resources within the project.

    For more information about roles and permissions, refer to Predefined roles and permissions at cloud.google.com.

  2. Generate and download the service account key file by following the official instructions.

Step 2. Connect to BigQuery

  1. In the Database tool window ( View | Tool Windows | Database) , click the New icon New and select Connect to Database.

  2. If you have a connection string for the database defined in your solution or elsewhere, leave the Use connection string option selected and choose BigQuery in the Database type selector.

    Use the String selector to choose the desired connection string from your solution or type it in manually, then click Connect.

  3. You can also choose Add data source manually, click Next and select BigQuery in the Database source selector. Follow the wizard steps to form the connection string by configuring individual options.

  4. To access all available options for the new database connection, click in the Database window, then click the New icon New and select BigQuery.

  5. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    Location for the downloaded JDBC drivers is the JetBrains Rider configuration directory.

    The Download missing driver files link

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  6. From the Authentication list, select Google Service Account.

  7. In the Service account email field, type the service account's name.

    You can find the service account's name as Email on the Service accounts page (IAM & Admin | Service accounts) of the Google Cloud Platform. For more information about creating a service account for the name's format, refer to the official instructions. The service account's name should look like this: intellij-ide@bigqueryproject-322409.iam.gserviceaccount.com.

  8. In the Project ID field, type the project ID.

    Usually, it is a part of the service account email that goes after the at sign (@). For example, bigqueryproject-322409. For the project ID's format, refer to the official instructions on creating a service account.

  9. In the Key file field, type the path to the JSON service account key file that you obtained on Step 1. Obtain credentials.

  10. Ensure that the connection to the database can be established using the provided details. To do that, click the Test Connection link at the bottom of the connection details area.

    Test Connection link

    In case of any connection issues, refer to the Cannot connect to a database page.

  11. (Optional) By default, only the default project and dataset are introspected and available to work with. If you also want to work with other projects and datasets, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  12. Click OK to create the data source.

  13. Find your new data source in the Database tool window (⌘ 1) .

    • For more information about the Database tool window, see the corresponding reference topic.

    • For more information about working with database objects in JetBrains Rider, refer to Database objects.

    • To write and run queries, open the default query console by clicking the data source and pressing F4.

    • To view and edit data of a database object, open Data editor and viewer by double-clicking the object.

Connecting with a Google Service Account

Access and refresh tokens (OAuth 2.0)

To connect to the BigQuery database by using the Access and Refresh Tokens authentication method, the following credentials are required: client ID and client secret, refresh and access tokens.

When you use OAuth 2.0 for authentication, your users are authenticated after they agree to terms that are presented to them on a user consent screen. The OAuth consent screen is a dialog that displays a notification about who requests access to the user's data and a type of this data.

Before you generate a client ID and a client secret, you need to configure the OAuth consent screen.

Step 1. Obtain credentials

  1. Create OAuth consent screen by following the official instructions.

    For more information about user consent, refer to the User consent section at support.google.com

  2. Get a client ID and a client secret by following the official instructions.

    For the URI, use the following one:

    https://developers.google.com/oauthplayground

    Find your client ID and client secret in the OAuth client created window. Alternatively, you can click the created OAuth client ID configuration and get your credentials here.

  3. Having a client ID and a client secret, you can generate authorization code and tokens. To do that, perform the following steps:

    1. Open the OAuth 2.0 Playground in a separate browser tab.

    2. Click the OAuth 2.0 Configuration icon, select the Use your own OAuth credentials checkbox.

    3. Paste your client ID and client secret in OAuth Client ID and OAuth Client secret fields.

      OAuth 2.0 Configuration
    4. Click Close in the OAuth 2.0 Configuration window.

    5. In the wizard on Step 1. Select & authorize APIs, select BigQuery API v2 | https://www.googleapis.com/auth/bigquery.

    6. Click Authorize APIs.

    7. Follow the wizard in a browser and give permissions to the application.

      give permissions to the application
    8. On Step 2 Exchange authorization code for tokens, click Exchange authorization code for tokens.

    9. Copy received refresh and access tokens.

      refresh and access tokens

Step 2. Connect to BigQuery

  1. In the Database tool window ( View | Tool Windows | Database) , click the New icon New and select Connect to Database.

  2. If you have a connection string for the database defined in your solution or elsewhere, leave the Use connection string option selected and choose BigQuery in the Database type selector.

    Use the String selector to choose the desired connection string from your solution or type it in manually, then click Connect.

  3. You can also choose Add data source manually, click Next and select BigQuery in the Database source selector. Follow the wizard steps to form the connection string by configuring individual options.

  4. To access all available options for the new database connection, click in the Database window, then click the New icon New and select BigQuery.

  5. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    Location for the downloaded JDBC drivers is the JetBrains Rider configuration directory.

    The Download missing driver files link

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  6. From the Authentication list, select Access and Refresh Tokens.

  7. In the Project ID field, type the project ID.

    Usually, it is a part of the service account email that goes after the at sign (@). For example, bigqueryproject-322409. For the project ID's format, refer to the official instructions on creating a service account.

  8. In the Access token field, paste your access token.

  9. In the Refresh token field, paste your refresh token.

  10. In the Client ID field, paste your client ID.

  11. In the Client secret field, paste your client secret.

  12. Ensure that the connection to the database can be established using the provided details. To do that, click the Test Connection link at the bottom of the connection details area.

    Test Connection link

    In case of any connection issues, refer to the Cannot connect to a database page.

  13. (Optional) By default, only the default project and dataset are introspected and available to work with. If you also want to work with other projects and datasets, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  14. Click OK to create the data source.

  15. Find your new data source in the Database tool window (⌘ 1) .

    • For more information about the Database tool window, see the corresponding reference topic.

    • For more information about working with database objects in JetBrains Rider, refer to Database objects.

    • To write and run queries, open the default query console by clicking the data source and pressing F4.

    • To view and edit data of a database object, open Data editor and viewer by double-clicking the object.

connecting with tokens
Last modified: 11 October 2024