Cloud Storage Avro to Spanner Data Validation template

The Cloud Storage Avro files to Spanner Data Validation template is a batch pipeline that reads data from Cloud Storage and Spanner and compares them to validate migration correctness.

Pipeline requirements

  • The Cloud Storage directory for Avro files must exist before pipeline execution. Generate these Avro files by running the SourceDB to Cloud Spanner pipeline with the gcsOutputDirectory parameter.
  • The target BigQuery dataset for validation results must exist before pipeline execution.
  • The Spanner tables must exist before pipeline execution.
  • The Spanner tables must have a compatible schema (either directly or through schema mapping).
  • To validate a migration performed by the SourceDB to Cloud Spanner pipeline, you must pass identical values for any shared configurations (such as sessionFilePath, schemaOverridesFilePath, and transformationJarPath).

Template parameters

Required parameters

  • gcsInputDirectory: This directory is used to read the AVRO files of the records read from source. For example, gs://your-bucket/your-path.
  • projectId: This is the name of the Cloud Spanner project.
  • instanceId: The destination Cloud Spanner instance.
  • databaseId: The destination Cloud Spanner database.
  • bigQueryDataset: The BigQuery dataset ID where the validation results will be stored. For example, validation_report_dataset.

Optional parameters

  • spannerHost: The Cloud Spanner endpoint to call in the template. For example, https://batch-spanner.googleapis.com. Defaults to: https://batch-spanner.googleapis.com.
  • spannerPriority: The request priority for Cloud Spanner calls. The value must be one of: [HIGH,MEDIUM,LOW]. Defaults to HIGH.
  • sessionFilePath: Session file path in Cloud Storage that contains mapping information from Spanner Migration Tool. Defaults to empty.
  • schemaOverridesFilePath: A file which specifies the table and the column name overrides from source to spanner. Defaults to empty.
  • tableOverrides: These are the table name overrides from source to spanner. They are written in the following format: [{SourceTableName1, SpannerTableName1}, {SourceTableName2, SpannerTableName2}] This example shows mapping Singers table to Vocalists and Albums table to Records. For example, [{Singers, Vocalists}, {Albums, Records}]. Defaults to empty.
  • columnOverrides: These are the column name overrides from source to spanner. They are written in the following format: [{SourceTableName1.SourceColumnName1, SourceTableName1.SpannerColumnName1}, {SourceTableName2.SourceColumnName1, SourceTableName2.SpannerColumnName1}]. Note that the SourceTableName should remain the same in both the source and spanner pair. To override table names, use tableOverrides.The example shows mapping SingerName to TalentName and AlbumName to RecordName in Singers and Albums table respectively. For example, [{Singers.SingerName, Singers.TalentName}, {Albums.AlbumName, Albums.RecordName}]. Defaults to empty.
  • runId: A unique identifier for the validation run. If not provided, the Dataflow Job Name will be used. For example, run_20230101_120000.
  • transformationJarPath: Custom jar location in Cloud Storage that contains the custom transformation logic for processing records. Defaults to empty.
  • transformationClassName: Fully qualified class name having the custom transformation logic. It is a mandatory field in case transformationJarPath is specified. Defaults to empty.
  • transformationCustomParameters: String containing any custom parameters to be passed to the custom transformation class. Defaults to empty.
  • tables: A comma-separated list of source tables to include in the validation run. Defaults to empty.
  • tableConfigurationFilePath: A GCS file path containing a JSON list of source tables to validate. This must be a JSON file with the structure {"tableNames": ["table1", "table2"]}. Defaults to empty.

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 Storage Avro files to Spanner Data Validation template.
  6. In the provided parameter fields, enter your parameter values.
  7. Click Run job.

gcloud CLI

In your shell or terminal, run the template:

gcloud dataflow flex-template run JOB_NAME \
    --template-file-gcs-location=gs://dataflow-templates/VERSION/flex/Avro_to_Spanner_Data_Validator \
    --region=REGION_NAME \
    --parameters \
       gcsInputDirectory=PATH_TO_AVRO_FILES,\
       projectId=PROJECT_ID,\
       instanceId=INSTANCE_ID,\
       databaseId=DATABASE_ID,\
       bigQueryDataset=BIGQUERY_DATASET

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:

    • latest to use the latest version of the template, which is available in the non-dated parent folder in the bucket— gs://dataflow-templates/latest/
    • the version name, like 2023-09-12-00_RC00, to use a specific version of the template, which can be found nested in the respective dated parent folder in the bucket— gs://dataflow-templates/
  • REGION_NAME: the region where you want to deploy your Dataflow job—for example, us-central1
  • PATH_TO_AVRO_FILES: the Cloud Storage path to the Avro files.
  • PROJECT_ID: the Spanner project ID.
  • INSTANCE_ID: the destination Spanner instance ID.
  • DATABASE_ID: the destination Spanner database ID.
  • BIGQUERY_DATASET: the BigQuery dataset ID for the validation results.

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/flexTemplates:launch
{
   "launchParameter": {
     "jobName": "JOB_NAME",
     "parameters": {
       "gcsInputDirectory": "PATH_TO_AVRO_FILES",
       "projectId": "PROJECT_ID",
       "instanceId": "INSTANCE_ID",
       "databaseId": "DATABASE_ID",
       "bigQueryDataset": "BIGQUERY_DATASET"
     },
     "containerSpecGcsPath": "gs://dataflow-templates/VERSION/flex/Avro_to_Spanner_Data_Validator"
  }
}

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:

    • latest to use the latest version of the template, which is available in the non-dated parent folder in the bucket— gs://dataflow-templates/latest/
    • the version name, like 2023-09-12-00_RC00, to use a specific version of the template, which can be found nested in the respective dated parent folder in the bucket— gs://dataflow-templates/
  • LOCATION: the region where you want to deploy your Dataflow job—for example, us-central1
  • PATH_TO_AVRO_FILES: the Cloud Storage path to the Avro files.
  • PROJECT_ID: the Spanner project ID.
  • INSTANCE_ID: the destination Spanner instance ID.
  • DATABASE_ID: the destination Spanner database ID.
  • BIGQUERY_DATASET: the BigQuery dataset ID for the validation results.