Google BigQuery
- 4 minutes to read
The Dashboard Designer provides the capability to connect to multiple types of SQL databases using the Data Source wizard. You can also use the data access API to connect to the database and select the required data in code.
This tutorial describes how to establish a connection to a Google BigQuery data source and select the required data.
Important
The appropriate data provider must be installed on the client machine. For information on data providers, refer to the Supported Data Sources article.
Creating a Data Source in the Data Source Wizard
To connect to the Google BigQuery data source in the Dashboard Designer, perform the following steps.
Click the New Data Source button in the Data Source ribbon tab.
On the first page of the invoked Data Source Wizard dialog, select Database and click Next.
On the next page, select the Google BigQuery data provider and choose the required Authentication type. If you selected OAuth, the Data Source wizard provides the following connection settings.
Project ID
Specifies the project ID.
Client ID
Specifies the client identifier.
Client Secret
Specifies the client secret.
Refresh Token
Specifies the refresh token.
DataSet ID
Specifies the ID of the dataset that contains the required data.
If you selected the Key file Authentication type, the Data Source wizard provides the following connection settings.
Project ID
Specifies the name of the Firebird server to which the connection should be established.
Key file name
Specifies the path to the P12 private key file.
Service account email
Specifies the service account’s email address.
DataSet ID
Specifies the ID of the dataset that contains the required data.
After you have specified the required connection parameters, click Next and specify how to select data from the database.
Run the Query Builder by clicking the Run Query Builder… button. The Query Builder allows you to choose the required tables/columns visually and passes the resulting SQL query to the SQL String editor. After you constructed the query in the Query Builder, the text of the generated query will be passed to the Data Source wizard.
Click Finish to create the data source.
Note
If you applied filtering to this query and created the query parameter, you can click Next to specify the settings of the query parameter.
On the final page, you can optionally add query parameters and preview data.
Click Finish to create the data source.
Creating a Data Source in Code
To create a data source that uses a connection to the Firebird database, create an instance of the DashboardSqlDataSource class and perform the following steps.
Specify the connection parameters to the Google BigQuery database. Create the BigQueryConnectionParameters class object and specify the following properties.
- The project ID (BigQueryConnectionParameters.ProjectID).
- The authorization type (BigQueryConnectionParameters.AuthorizationType). Depending on the selected authorization type, you should specify additional authentication settings. To learn more, see the details below.
- The dataset ID (BigQueryConnectionParameters.DataSetID).
If a connection is established using the BigQueryAuthorizationType.OAuth authorization type, use the following properties to specify connection parameters.
Gets or sets a client identifier.
Gets or sets a client secret.
Gets or sets a refresh token.
If a connection is established using the BigQueryAuthorizationType.PrivateKeyFile authorization type, use the following properties to specify connection parameters.
Gets or sets the path to the P12 private key file.
Gets or sets the service account’s email address.
Note
As an alternative, you can add a connection string with the required parameters to the application configuration file. Then, assign the connection string name to the SqlDataSource.ConnectionName property.
Select the required data by specifying the query. You can do this in the following ways.
- The SelectQuery object allows you to specify a set of tables/columns, which form a SELECT statement when executing a query.
- The CustomSqlQuery object allows you to specify an SQL query manually.
Add the created query to the SqlDataSource.Queries collection exposed by the DashboardSqlDataSource object.
- Add the created DashboardSqlDataSource object to the Dashboard.DataSources collection.
The following code snippet shows how to supply the dashboard with data from the Northwind database deployed using Google BigQuery.
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
// ...
BigQueryConnectionParameters bigQueryParams = new BigQueryConnectionParameters();
bigQueryParams.ProjectID = "TestProject";
bigQueryParams.AuthorizationType = BigQueryAuthorizationType.OAuth;
bigQueryParams.OAuthClientID = "testclientid.apps.googleusercontent.com";
bigQueryParams.OAuthClientSecret = "sDYUtrpaiWSisC8OGLB5nVNV";
bigQueryParams.OAuthRefreshToken = "1/EvVgWitT3gttIhJu0F9DIhaYhOecE-WDH1Uwlxwgkx9";
bigQueryParams.DataSetID = "Norhwind";
DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("Data Source 1", bigQueryParams);
SelectQuery selectQuery = SelectQueryFluentBuilder
.AddTable("SalesPerson")
.SelectColumns("CategoryName", "Extended Price")
.Build("Query 1");
sqlDataSource.Queries.Add(selectQuery);
sqlDataSource.Fill();
dashboard.DataSources.Add(sqlDataSource);