Spanner to Cloud Storage Text template

The Spanner to Cloud Storage Text template is a batch pipeline that reads in data from a Spanner table, and writes it to Cloud Storage as CSV text files.

Pipeline requirements

  • The input Spanner table must exist before running the pipeline.

Template parameters

Parameter Description
spannerProjectId The Google Cloud Project ID of the Spanner database that you want to read data from.
spannerDatabaseId The database ID of the requested table.
spannerInstanceId The instance ID of the requested table.
spannerTable The table to read the data from.
textWritePrefix The Cloud Storage path where output text files are written. Add / at the end. For example, gs://mybucket/somefolder/.
spannerSnapshotTime (Optional) The timestamp that corresponds to the version of the Spanner database that you want to read. The timestamp must be specified as per RFC 3339 UTC "Zulu" format. For example, 1990-12-31T23:59:60Z. The timestamp must be in the past and Maximum timestamp staleness applies.
dataBoostEnabled (Optional) Set to true to use the compute resources of Spanner Data Boost to run the job with near-zero impact on Spanner OLTP workflows. This requires the spanner.databases.useDataBoost Identity and Access Management (IAM) permission. For more information, see Data Boost overview.
csvTempDirectory (Optional) The Cloud Storage path where temporary CSV files are written.
spannerPriority (Optional) The request priority for Spanner calls. Possible values are HIGH, MEDIUM, LOW. The default value is MEDIUM.

Run the template

Console

  1. Go to the Dataflow Create job from template page.
  2. Go to Create job from template
  3. In the Job name field, enter a unique job name.
  4. Optional: For Regional endpoint, select a value from the drop-down menu. The default region is us-central1.

    For a list of regions where you can run a Dataflow job, see Dataflow locations.

  5. From the Dataflow template drop-down menu, select the Cloud Spanner to Text Files on Cloud Storage template.
  6. In the provided parameter fields, enter your parameter values.
  7. Click Run job.

gcloud

In your shell or terminal, run the template:

gcloud dataflow jobs run JOB_NAME \
    --gcs-location gs://dataflow-templates-REGION_NAME/VERSION/Spanner_to_GCS_Text \
    --region REGION_NAME \
    --parameters \
spannerProjectId=SPANNER_PROJECT_ID,\
spannerDatabaseId=DATABASE_ID,\
spannerInstanceId=INSTANCE_ID,\
spannerTable=TABLE_ID,\
textWritePrefix=gs://BUCKET_NAME/output/

Replace the following:

  • JOB_NAME: a unique job name of your choice
  • VERSION: the version of the template that you want to use

    You can use the following values:

  • REGION_NAME: the region where you want to deploy your Dataflow job—for example, us-central1
  • SPANNER_PROJECT_ID: the Google Cloud project ID of the Spanner database from which you want to read data
  • DATABASE_ID: the Spanner database ID
  • BUCKET_NAME: the name of your Cloud Storage bucket
  • INSTANCE_ID: the Spanner instance ID
  • TABLE_ID: the Spanner table ID

API

To run the template using the REST API, send an HTTP POST request. For more information on the API and its authorization scopes, see projects.templates.launch.

POST https://dataflow.googleapis.com/v1b3/projects/PROJECT_ID/locations/LOCATION/templates:launch?gcsPath=gs://dataflow-templates-LOCATION/VERSION/Spanner_to_GCS_Text
{
   "jobName": "JOB_NAME",
   "parameters": {
       "spannerProjectId": "SPANNER_PROJECT_ID",
       "spannerDatabaseId": "DATABASE_ID",
       "spannerInstanceId": "INSTANCE_ID",
       "spannerTable": "TABLE_ID",
       "textWritePrefix": "gs://BUCKET_NAME/output/"
   },
   "environment": { "zone": "us-central1-f" }
}

Replace the following:

  • PROJECT_ID: the Google Cloud project ID where you want to run the Dataflow job
  • JOB_NAME: a unique job name of your choice
  • VERSION: the version of the template that you want to use

    You can use the following values:

  • LOCATION: the region where you want to deploy your Dataflow job—for example, us-central1
  • SPANNER_PROJECT_ID: the Google Cloud project ID of the Spanner database from which you want to read data
  • DATABASE_ID: the Spanner database ID
  • BUCKET_NAME: the name of your Cloud Storage bucket
  • INSTANCE_ID: the Spanner instance ID
  • TABLE_ID: the Spanner table ID

What's next