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

Data Type Mapping

Spanner Type PuppyGraph Type Description
BOOL Boolean True or false
INT64 Long 64-bit signed integer
FLOAT64 Double 64-bit IEEE 754 floating point
NUMERIC Decimal(38, 9) Fixed-point decimal, precision 38, scale 9
STRING String Character strings
JSON String JSON document as text
DATE Date Calendar date without time or timezone
TIMESTAMP DateTime Date and time
  • Databases that use the PostgreSQL dialect map the same way through their equivalent types: boolean, bigint, double precision, numeric, varchar, text, jsonb, date and timestamptz.
  • Columns of any other type, such as FLOAT32 (real in the PostgreSQL dialect), BYTES, ARRAY, INTERVAL, PROTO, ENUM or TOKENLIST, are not supported. They are listed in Schema Builder, but you cannot add them to a node or edge as attributes.

If you need a data type that is not supported, or one that is not listed here, contact us.

Demo

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