VOOZH about

URL: https://www.cdata.com/kb/tech/gsheets-tdv-setup.rst

⇱ Access Live Google Sheets Data in TIBCO Data Virtualization


Access Live Google Sheets Data in TIBCO Data Virtualization

👁 Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Use the Google Spreadsheets Tibco DV Adapter to create a Google Sheets data source in TIBCO Data Virtualization Studio and gain access to live Google Sheets data from your TDV Server.

TIBCO Data Virtualization (TDV) is an enterprise data virtualization solution that orchestrates access to multiple and varied data sources. When paired with the Google Spreadsheets Tibco DV Adapter, you get federated access to live Google Sheets data directly within TIBCO Data Virtualization. This article explains how to deploy an adapter and create a new data source based on Google Sheets.

With built-in optimized data processing, the CData TIBCO DV Adapter offers unmatched performance for interacting with live Google Sheets data. When you issue complex SQL queries to Google Sheets, the adapter pushes supported SQL operations, like filters and aggregations, directly to Google Sheets. Its built-in dynamic metadata querying allows you to work with and analyze Google Sheets data using native data types.

Deploy the Google Sheets TIBCO DV Adapter

  1. In a console, navigate to the bin folder in the TDV Server installation directory. If there is a current version of the adapter installed, you will need to undeploy it.

    .\server_util.bat -server localhost -user admin -password ******** -undeploy -version 1 -name GoogleSheets
    
  2. Extract the CData TIBCO DV Adapter to a local folder and deploy the JAR file (tdv.googlesheets.jar) to the server from the extract location.

    .\server_util.bat -server localhost -user admin -password ******** -deploy -package /PATH/TO/tdv.googlesheets.jar
    

You may need to restart the server to ensure the new JAR file is loaded properly, which can be accomplished by running the composite.bat script located at: C:\Program Files\TIBCO\TDV Server <version>\bin. Note that reauthenticating to the TDV Studio is required after restarting the server.

Sample Restart Call

.\composite.bat monitor restart

Authenticate with Google Sheets Using OAuth

Since Google Sheets authenticates using the OAuth protocol and TDV Studio does not support browser-based authentication internally, you will need to create and run a simple Java application to retrieve the OAuth tokens. Once retrieved, the tokens are used to connect to Google Sheets directly from the adapter.

Create the Java Application

  1. Create a new Java file with preferred name for example GenOAuthSettings.java. This Java file leverages the GoogleSheetsOAuth class contained within the TDV Adapter JAR to initiate a test connection and perform the required OAuth authentication flow
  2. Copy and insert the following code into the .java file:
  3. public class GenOAuthSettings {
     public static void main(String[] args) {
     try {
     	 if (args.length != 2) {
     			throw new Exception("Input must have two arguments: 'data source', 'connection string'");
     		}
     
     		String source = args[0].replace(" ", "").toLowerCase();
     		String connectionString = args[1];
     		String prefix;
     
     		if (source.equals("googlesheets")) {
     			prefix = "jdbc:googlesheets:";
     
     			com.cdata.cis.googlesheets.GoogleSheetsOAuth oauth = new com.cdata.cis.googlesheets.GoogleSheetsOAuth();
     
     			if (!connectionString.startsWith(prefix)) connectionString = prefix + connectionString;
     			oauth.generateOAuthSettingsFile(connectionString);
     		}
     		// More sources can be added below using the same format. You must add the import statement and ensure the jar file resides in the classpath
    			// else if (source.equals("googlebigquery") || source.equals("bigquery")) {
    			// prefix = "jdbc:googlebigquery:";
    			//
    			// com.cdata.cis.googlebigquery.GoogleBigQueryOAuth oauth = new com.cdata.cis.googlebigquery.GoogleBigQueryOAuth();
    			//
    			// if (!connectionString.startsWith(prefix)) connectionString = prefix + connectionString;
    			// oauth.generateOAuthSettingsFile(connectionString);
    			// }
     		else {
    				throw new Exception("Data Source not supported. Available Data Sources: Google Sheets");
    			}
    			
    			System.out.println("Test Connection Successful!");
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
    
  4. Place the .java file in the same directory as the tdv.googlesheets.jar file. This is required to prevent classpath resolution errors during compilation and execution

Build and run the Java Application

  1. Open Console and navigate to the directory containing the .java file and adapter jar
  2. Compile the Java file using the following command:
  3. javac -cp .;tdv.googlesheets.jar GenOAuthSettings.java
    
  4. Execute the application using one of the following commands:
  5. java -cp .;tdv.googlesheets.jar GenOAuthSettings "GoogleSheets" "connection string"
    

This command initiates the OAuth authentication flow and generates the OAuth settings file at the location specified in the OAuthSettingsLocation parameter. Once you deploy the adapter and authenticate, you can create a new data source for Google Sheets in TDV Studio.

Create a Google Sheets Data Source in TDV Studio

With the Google Spreadsheets Tibco DV Adapter, you can easily create a data source for Google Sheets and introspect the data source to add resources to TDV.

Create the Data Source

  1. Right-click on the folder you wish to add the data source to and select New -> New Data Source
  2. Scroll until you find the adapter (e.g. Google Sheets) and click Next
  3. Name the data source (e.g. CData Google Sheets Source)
  4. Fill in the required connection properties
  5. You can connect to a spreadsheet by providing authentication to Google and then setting the Spreadsheet connection property to the name or feed link of the spreadsheet. If you want to view a list of information about the spreadsheets in your Google Drive, execute a query to the Spreadsheets view after you authenticate.

    ClientLogin (username/password authentication) has been officially deprecated since April 20, 2012 and is now no longer available. Instead, use the OAuth 2.0 authentication standard. To access Google APIs on behalf on individual users, you can use the embedded credentials or you can register your own OAuth app.

    OAuth also enables you to use a service account to connect on behalf of users in a Google Apps domain. To authenticate with a service account, register an application to obtain the OAuth JWT values.

    See the Getting Started chapter in the help documentation to connect to Google Sheets from different types of accounts: Google accounts, Google Apps accounts, and accounts using two-step verification.

    NOTE: Ensure that the OAuthSettingsLocation property in the DV Adapter is set to the same file path used during the OAuth authentication process. Additionally, set the InitiateOAuth property to REFRESH so that the adapter can automatically handle OAuth access-token refreshes in the background without requiring any user action.

    👁 Filling in Connection Information (Salesforce is shown.)
  6. Click Create & Close.

Introspect the Data Source

Once the data source is created, you can introspect the data source by right-clicking and selecting Open. In the dashboard, click Add/Remove Resources and select the Tables, Views, and Stored Procedures to include as part of the data source. Click Next and Finish to add the selected Google Sheets tables, views, and stored procedures as resources.

👁 Introspecting the Data Source (Salesforce is shown.)

After creating and introspecting the data source, you are ready to work with Google Sheets data in TIBCO Data Virtualization just like you would any other relational data source. You can create views, query using SQL, publish the data source, and more.