Skip to content

Connecting to Google Spanner

Prerequisites

  • The Spanner service is accessible over the network from the PuppyGraph instance.
  • A service account with proper permissions (see below) is available for PuppyGraph to connect to Spanner with.

Service Account Permission

PuppyGraph uses a Google Service Account for reading data from Spanner. The service account needs to have the following permissions:

To validate required permission on the service account, you can use the following gcloud command:

gcloud projects get-iam-policy [PROJECT_ID] --flatten="bindings[].members" --format="table(bindings.role)"
Replace <PROJECT_ID> with your project ID. The output should contain the following lines:
roles/spanner.databaseReader

Configuration

Configuration Explanation
JDBC URI jdbc:cloudspanner:/projects/{ProjectId}/instances/{InstanceName}/databases/{Database}

A JDBC compatible connection URI of the data source. Read this page for more details on how to construct the URI.

Specifically, the following parameters need to be set according to your service account config:

  • ProjectId Set your service account project id.
  • InstanceName Set your spanner instance name.
  • Database Choose the database.

JDBC Driver Class

The class name of the JDBC Driver.

The default value is com.google.cloud.spanner.jdbc.JdbcDriver

Demo

See Querying Google Spanner Data as a Graph for a complete demo for Spanner.