Google BigQuery ODBC Driver

We've released an ODBC driver for Google BigQuery. The driver lets you query and update BigQuery data in applications other than the Google BigQuery console. We thought we'd share some of the things you can do in these third party applications (for example, Perl, PHP, Excel and Oracle).

Installing the BigQuery ODBC Driver

  1. Install and license the Google BigQuery ODBC driver on the machine where the client application is installed.

    For example, if you want to work with BigQuery data in Excel, install the BigQuery ODBC driver on the machine where Excel is installed.

    To do this, execute the file distribution, and follow the on screen instructions.

    The install program starts the Easysoft License Manager, because you cannot use the BigQuery ODBC Driver until a license is obtained.

    The following types of license are available:

    • Free time-limited trial license which gives you free and unrestricted use of the product for a limited period (usually 14 days).
    • Full license if you have purchased the product. On purchasing the product you are given an authorization code, which you use to obtain a license
  2. In Easysoft License Manager, enter your details.

    You MUST enter the Name, E-Mail Address and Company fields.

    The E-Mail Address MUST be the same as the address used to register and download from the Easysoft web site or you will be unable to obtain trial licenses.

  3. Choose Request License.

    You are asked for a license type.

  4. Do one of the following:
    • For a trial license click Time Limited Trial and then click Next.

      The License Manager asks what software you are licensing. Select Easysoft BigQuery ODBC Driver from the drop-down list and then click Next.

    • If you have obtained an authorization code for a purchased license, select Non-expiring License and then click Next.

      The License Manager requests your authorization code.

      Enter the authorization code and then click Next.

  5. The License Manager displays a summary of the information you entered and allows you to choose the method of applying for your license.
  6. Do one of the following:
    • Choose On-line Request if your machine is connected to the internet and can make outgoing connections to port 8884.

      The License Manager then sends a request to the Easysoft license server to activate your license key automatically. This is the quickest method and results in your details being entered immediately into our support database.

    • The remaining three options (Email Request, Print Request and View Request) are all ways to obtain a license if your machine is off-line (i.e. does not have a connection to the internet).

      Each of these methods involves providing Easysoft with information including your machine number (a number unique to your machine) and then waiting to receive your license key.

      Instead of emailing your details to Easysoft, you can enter them directly at the Easysoft web site and your license key will be emailed to you automatically.

      To use this method, click View Request, and then visit:

      In the Licensing page, enter your machine number (and authorization code for purchased license), click Submit and your license key will be emailed to you.

      When you receive the license key, you can activate it either by double-clicking the email attachment or by clicking Enter License on the License Manager main screen and pasting the license key into the dialog box.

    • Choose Finish to exit the License Manager.

      The installation is complete.

Configuring an ODBC Data Source

Before the BigQuery ODBC Driver can be used to connect an application to BigQuery, it's necessary to configure an ODBC data source. An ODBC data source stores the connection details for the target database (e.g. BigQuery) and the ODBC driver that is required to connect to it (e.g. the BigQuery ODBC driver).

ODBC data sources are configured in ODBC Administrator, which is included with Windows. How ODBC Administrator is run depends on whether your application is 32-bit or 64-bit:

How to tell whether an application is 32-bit or 64-bit?

Application Notes
Excel There is both a 32-bit and a 64-bit version of Excel. To find out which version of Excel you have, start Excel, and then start Windows Task Manager. In Task Manager, choose the Processes tab. Look for Excel.exe in the list. If this process name is followed by *32, your version of Excel is 32-bit. Otherwise, your version of Excel is 64-bit.
GoodData CloudConnect Deigner is a 64-bit application.
MicroStrategy MicroStrategy is a 32-bit application.
Oracle The Oracle component that interacts with the MongoDB ODBC driver is called DG4ODBC. There is both a 32-bit and a 64-bit version of DG4ODBC. To find out which version of DG4ODBC you have, start the Windows Task Manager and choose the Processes tab. In a Command Prompt window, type dg4odbc --help. In the Windows Task Manager, look for the DG4ODBC process. If the Image Name is "dg4odbc.exe *32" DG4ODBC is 32-bit. If the Image Name is "dg4odbc.exe" DG4ODBC is 64-bit. Press CTRL+C in the Command Prompt window, when you have used the Windows Task Manager to find out DG4ODBC's architecture.
Oracle Business Intelligence Enterprise Edition (OBIEE) The OBIEE component that interacts with the MongoDB ODBC driver is called the Oracle BI Administration Tool. The Oracle BI Administration Tool is 64-bit.
PHPRunner PHPRunner is a 32-bit application.
QlikView QlikView is a 32-bit application if the Force 32 Bit check box is selected. Otherwise, QlikView is a 64-bit application.
SAP BusinessObjects Central Management Server is a 64-bit application. Business View Manager, Information Design Tool and Web Intelligence Rich Client are 32-bit applications.
SAP Crystal Reports Crystal Reports is a 32-bit application.
SQL Server There is both a 32-bit and a 64-bit version of SQL Server. To find out which version of SQL Server you have, connect to your SQL Server instance, and then run this SQL statement:
select SERVERPROPERTY('edition')

If you have the 64-bit version of SQL Server and want to use a linked server with the BigQuery ODBC driver, your application is 64-bit.

If you have the 32-bit version of SQL Server or want to use SSIS with the BigQuery ODBC driver, your application is 32-bit.

Tableau Tableau is a 32-bit application.
TIBCO Spotfire TIBCO Spotfire is a 64-bit application.

In ODBC Administrator:

  1. Choose the System DSN tab, and then choose Add.
  2. In the Create New Data Source dialog box, choose Easysoft ODBC-BigQuery Driver, and then choose Finish.
  3. Complete these fields in the Easysoft ODBC-BigQuery Driver DSN Setup dialog box:
    Setting Value
    DSN BigQuery
    Refresh Token Choose the Authenticate and obtain token and grant the BigQuery ODBC driver permission to access your BigQuery data to populate this field.
  4. In your application, connect to your newly configured data source and run a sample query. For example:
    select * from MyTable limit 10

Work with BigQuery data in Perl

Strawberry Perl is a Perl distribution for Windows that includes the necessary middleware layers (Perl DBI and Perl DBD::ODBC) to enable the BigQuery ODBC driver to connect your Perl applications to BigQuery.

  1. Here's a Perl script that retrieves some BiqQuery data:
    #!/usr/bin/perl -w
    use strict;
    use DBI;
    my $dbh = DBI-> connect('dbi:ODBC:MyBigQueryDataSource');
    
    my $sql = "SELECT residential_ratio  FROM `bigquery-public-data.hud_zipcode_crosswalk.census_tracts_to_zipcode` LIMIT 10";
    
    # Prepare the statement.
    my $sth = $dbh->prepare($sql)
        or die "Can't prepare statement: $DBI::errstr";
    
    # Execute the statement.
    $sth->execute();
    
    my($BigQueryCol);
    
    # Fetch and display the result set value.
    while(($BigQueryCol) = $sth->fetchrow()){
       print("$BigQueryCol\n");                   
    }
    
    $dbh->disconnect if ($dbh);
  2. Here's a Perl script that inserts some BigQuery data:
    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use DBI;
    
    my $data_source = q/dbi:ODBC:MyBigQueryDataSource/;
    
    my $h = DBI-"connect($data_source)
        or die "Can't connect to $data_source: $DBI::errstr";
    $h->{RaiseError} = 1;
    
    my $s = $h->prepare(q/insert into MyTable(MyStringCol, MyIntegerCol, MyFloatCol, MyNumericCol, MyBooleanCol,MyDateCol,MyTimeCol,MyDateTimeCol,MyTimeStampCol) values(?,?,?,?,?,?,?,?,?)/);
    my $string='MyValue';
    my $int=46683;
    my $float=8.3;
    my $numeric=0.00333;
    my $bool=0;
    my $date='2021-01-23';
    my $time='00:00:20';
    my $datetime='2021-02-05 00:00:00';
    my $timestamp='2019-01-27 00:00:00';
    
    $s->bind_param(1, $string, DBI::SQL_WVARCHAR);
    $s->bind_param(2, $int, DBI::SQL_INTEGER);
    $s->bind_param(3, $float, DBI::SQL_FLOAT);
    $s->bind_param(4, $numeric, DBI::SQL_NUMERIC);
    #$s->bind_param(5, $bignumeric, DBI::SQL_WVARCHAR);
    $s->bind_param(5, $bool, DBI::SQL_TINYINT);
    $s->bind_param(6, $date, DBI::SQL_DATE);
    $s->bind_param(7, $time, DBI::SQL_TIME);
    $s->bind_param(8, $datetime, DBI::SQL_DATETIME);
    $s->bind_param(9, $timestamp, DBI::SQL_TIMESTAMP);
    $s->execute($string,$int,$float,$numeric,$bool,$date,$time,$datetime,$timestamp);
    $h->disconnect;
    	  
  3. Here's a Perl script that updates a BigQuery record:
    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use DBI;
    
    my $data_source = q/dbi:ODBC:MyBigQueryDataSource/;
    
    my $h = DBI->connect($data_source)
        or die "Can't connect to $data_source: $DBI::errstr";
    $h->{RaiseError} = 1;
    
    my $s = $h->prepare(q/UPDATE MyTestTable SET MyStringCol = ? WHERE MyStringCol = 'MyValue' /);
    my $string='MyNewValue';
    
    $s->bind_param(1, $string, DBI::SQL_WVARCHAR);
    
    $s->execute($string);
    $h->disconnect;

Work with BigQuery data in PHP

  1. Here's a PHP script that retrieves some BiqQuery data:
    <?php
      $con = odbc_connect("MyBigQueryDataSource", "", "");
      $err = odbc_errormsg();
      if (strlen($err) <> 0) {
        echo odbc_errormsg();
      } else {
        $rs2 = odbc_exec($con, "select MyCol from MyTable");
        odbc_result_all($rs2);
        odbc_close($con);
      }
    ?>

Connecting Excel to BigQuery

Follow these steps to return data from BigQuery to Microsoft Excel by using Microsoft Query:

  1. On the Data tab, choose New Query > From Other Source > From ODBC.
  2. Choose the BigQuery ODBC data source when prompted.
  3. Choose a table from the available data sets.
  4. Choose the Load to return the BiqQuery data to the worksheet.

    Note that for large result sets, you may have to have to filter the data using Excel before the data can be returned to the worksheet.

Connect to BigQuery from Oracle

  1. Create a DG4ODBC init file on your Oracle machine. To do this, change to the %ORACLE_HOME%\hs\admin directory. Create a copy of the file initdg4odbc.ora. Name the new file initbq.ora.

    Note In these instructions, replace %ORACLE_HOME% with the location of your Oracle HOME directory. For example, C:\oraclexe\app\oracle\product\11.2.0\server.

  2. Ensure these parameters and values are present in your init file:
    HS_FDS_CONNECT_INFO = MyBigQueryDataSource
  3. Comment out the line that enables DG4ODBC tracing. For example:
    #HS_FDS_TRACE_LEVEL = <trace_level>
    
  4. Add an entry to %ORACLE_HOME%\network\admin\listener.ora that creates a SID_NAME for DG4ODBC. For example:
    SID_LIST_LISTENER =
     (SID_LIST =
       (SID_DESC=
         (SID_NAME=bq)
         (ORACLE_HOME=%ORACLE_HOME%)
         (PROGRAM=dg4odbc)
       )
     )
    
  5. Add a DG4ODBC entry to %ORACLE_HOME%\network\admin\tnsnames.ora that specifies the SID_NAME created in the previous step. For example:
    BQ =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = oracle_host)(PORT = 1521))
        (CONNECT_DATA =
          (SID = bq)
        )
        (HS = OK)
      )
    

    Replace oracle_host with the host name of your Oracle machine.

  6. Start (or restart) the Oracle Listener:
    cd %ORACLE_HOME%\bin
    lsnrctl stop
    lsnrctl start
    
  7. Connect to your Oracle database in SQL*Plus.
  8. In SQL*Plus, create a database link for the target BigQuery instance. For example:
    CREATE PUBLIC DATABASE LINK bqlink CONNECT TO "mydummyuser" IDENTIFIED BY "mydummypassword" USING 'bq';
    
  9. Try querying your BigQuery data. For example:
    SELECT * FROM "MyTable"@BQLINK;
    
Notes