BigQuery Migration Validator

BigQuery Migration Validator

Guides an AI agent in validating that tables migrated to BigQuery match their source by writing validation configs, running the migration validation tool and investigating mismatches.

Skill files10 files

references/

SKILL.md307 lines
1
---
2
name: bigquery-migration-validator
3
metadata:
4
version: "1.0.0"
5
category: BigDataAndAnalytics
6
publisher: google
7
description: >-
8
Validates that tables migrated to BigQuery match their source (Teradata,
9
Snowflake, Oracle, Redshift, Databricks, PostgreSQL, SQL Server, MySQL,
10
MariaDB, Hive, Impala, Vertica) with the BigQuery Migration Service (BQMS)
11
validation tool: schema and data type comparison, column aggregate
12
comparison, and row-level data comparison. Use when generating or editing a
13
validation config, running a validation, choosing sampling or partitioning,
14
fixing connection or driver errors, or investigating validation results in
15
BigQuery and Cloud Storage to decide which mismatches to fix. Don't use for
16
SQL translation (use bigquery-migration-sql-translator), extracting source
17
database catalog metadata or query logs, generating SQL scripts (such as COPY
18
INTO) or exporting or unloading source tables to Parquet on Cloud Storage,
19
loading staged files into BigQuery (such as bq load), or general BigQuery
20
query failures and tuning (use bigquery-troubleshooting or
21
bigquery-optimization).
22
---
23
24
# BigQuery Migration Validator
25
26
The validation tool compares a source table with its migrated BigQuery table. It
27
runs in two halves:
28
29
1. **Client (this machine)**: Reads the config, queries the source database,
30
and stages a row sample, source aggregates, and run metadata in Cloud
31
Storage. It then starts a BigQuery Migration workflow for each table and
32
exits.
33
2. **Backend (Google Cloud, asynchronous)**: Loads the staged sample into
34
BigQuery, compares it with the target table, and writes the results to
35
BigQuery and Cloud Storage.
36
37
Results do not exist when the command exits. Wait for the workflow to finish
38
before reading them (Section 4).
39
40
## Usage attribution
41
42
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
43
MUST read and follow the instructions in
44
[Usage Attribution](references/attribution.md).
45
46
## Before you begin
47
48
1. **Google Cloud CLI and project**: Ensure the
49
[Google Cloud CLI][gcloud_install] is installed, verify that the Google
50
Cloud project has an active Cloud Billing account, and configure the target
51
project (check regional service availability at
52
[Google Cloud locations][cloud_locations] when choosing `--location` for
53
validation workflows):
54
55
```bash
56
gcloud config set project PROJECT_ID
57
```
58
59
2. **Enable the APIs** (ask the user before enabling APIs): BigQuery
60
(`bigquery.googleapis.com`), BigQuery Migration
61
(`bigquerymigration.googleapis.com`), Cloud Storage
62
(`storage.googleapis.com`), and Secret Manager
63
(`secretmanager.googleapis.com`, when reading source passwords from Secret
64
Manager):
65
66
```bash
67
gcloud services enable \
68
bigquery.googleapis.com \
69
bigquerymigration.googleapis.com \
70
storage.googleapis.com
71
# Only when source passwords come from Secret Manager:
72
gcloud services enable secretmanager.googleapis.com
73
```
74
75
3. **Local runtime, authentication, and IAM permissions** (ask before
76
installing software):
77
78
* **Runtime and drivers**: Java 11 or later (JRE 11+) first on `PATH`, the
79
`bqms` gcloud component (installed on first use or with
80
`gcloud components install bqms`), local network access to the source
81
database, and vendor JDBC driver JARs for Teradata (`terajdbc4.jar`),
82
Vertica (`vertica-jdbc.jar`), Impala, and DuckDB in `./drivers` or
83
`BQMS_DRIVER_DIR` when required (other JDBC drivers download on first
84
use; see [connections and drivers](references/connections.md)).
85
* **Google Cloud credentials and IAM**: Authenticate the Google Cloud CLI
86
and Application Default Credentials with `gcloud auth login` and
87
`gcloud auth application-default login` (or set
88
`GOOGLE_APPLICATION_CREDENTIALS` for a service account). The identity
89
needs write access to the staging Cloud Storage bucket
90
(`roles/storage.objectAdmin`), permission to create BigQuery Migration
91
workflows (`roles/bigquerymigration.editor`), and permission to run
92
BigQuery jobs and write validation results in the target project and,
93
if set, the `results.projectId` project (`roles/bigquery.dataEditor`
94
and `roles/bigquery.jobUser`). With Secret Manager passwords, it also
95
needs `roles/secretmanager.secretAccessor` on the secret, or
96
`roles/iam.serviceAccountTokenCreator` on the service account named in
97
`secretImpersonateServiceAccount` (which then needs the accessor role).
98
99
4. **Cost and cleanup**: Review
100
[Google Cloud Pricing](https://cloud.google.com/pricing) for BigQuery, Cloud
101
Storage, and Secret Manager. Staged samples in Cloud Storage contain source
102
rows. When validation is complete, ask the user before deleting the staged
103
run directory (a `gcs_paths` entry in `run_state.json`) and any per-run
104
tables they no longer need (list them as in the
105
[results reference](references/results.md), Section 5). Deleting the run
106
directory also deletes the backend reports stored there (`results.json`,
107
`validation_summary.txt`, `column_details.txt`, `queries.sql`) and
108
`sample_metadata.json`, so `run_history.gcs_uri` no longer resolves;
109
say so and offer to copy the reports locally first:
110
111
```bash
112
gcloud storage cp GCS_RUN_PATH/results.json \
113
GCS_RUN_PATH/validation_summary.txt GCS_RUN_PATH/column_details.txt \
114
GCS_RUN_PATH/queries.sql LOCAL_DIR/
115
gcloud storage rm --recursive GCS_RUN_PATH
116
bq rm -f -t RESULTS_PROJECT:DATASET.TABLE_NAME
117
```
118
119
## 1. What gets compared
120
121
Pillar | `--validation-types` | Compares | Coverage
122
:------------ | :------------------- | :-------------------------------------------------------------------------------------------------------------------------- | :-------
123
**Schema** | `schema` | Column presence, mapping, and data type compatibility (one of 9 compatibility notes) | All columns
124
**Aggregate** | `aggregate` | Column statistics per type (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`, `SUM_LENGTH`, ...), computed per partition, then rolled up | 100% of rows (pushed down)
125
**Data** | `data` | Cell-by-cell values joined on comparison keys, with a distance per mismatched cell | Sampled or full rows
126
127
With `--validation-types` omitted, all three run. With `--validation-types` set
128
(for example `--validation-types=schema,aggregate`), only the listed types run.
129
Query (code) validation is not available in this tool.
130
131
Each pillar catches what the others miss. Aggregates cover every row cheaply but
132
cannot see offsetting errors (one row +5, another -5). Row sampling sees those
133
but only in the sample. Run both for sign-off.
134
135
## 2. Quick start
136
137
Both validation commands run in the **alpha** release track through the Google
138
Cloud CLI, which calls the `bqms` component (Java 11+ required). Arguments after
139
`--` are forwarded unchanged to the validation client.
140
141
> [!IMPORTANT]
142
> The commands are in the alpha track. If gcloud reports an invalid choice or
143
> unknown command, ask the user before running `gcloud components update` (or
144
> `gcloud components install alpha bqms`). If the Google Cloud CLI was
145
> installed with a system package manager such as `apt` or `yum`, the
146
> component manager is disabled; have the user upgrade `google-cloud-cli`
147
> through that package manager instead. If the command is still unavailable,
148
> stop and point the user to the [CLI reference](references/cli.md) and the
149
> [installation guide][gcloud_install] rather than retrying.
150
151
```bash
152
# 1. Generate per-table configs offline from extractor metadata or BQMS
153
# translation output (writes ./validation_config/).
154
gcloud alpha bq migration validation configure \
155
--metadata=dwh-migration-oracle-metadata.zip \
156
--target-dataset=warehouse \
157
--output=validation_config
158
159
# 2. Edit validation_config/connections.yaml (check the source dialect;
160
# set the target dataset) and settings.yaml (googleCloudStorage.gcsPath),
161
# then run schema and aggregate checks first.
162
gcloud alpha bq migration validation run validation_config/ \
163
--location=us --validation-types=schema,aggregate
164
165
# 3. Run row-level comparison, optionally on a subset of tables.
166
gcloud alpha bq migration validation run validation_config/ \
167
--location=us --validation-types=data --tables=orders
168
```
169
170
Then wait for the workflows (Section 4) and investigate (Section 5).
171
172
Every answer that runs or recommends `validation run` must tell the user that
173
the comparison finishes later in a BigQuery Migration workflow, that exit code 0
174
does not mean the data matched, and how to check the workflow before reading
175
results. Users who skip this read an empty or stale results dataset as a pass.
176
177
## 3. Configure
178
179
Settings come from YAML (modular `validation_config/` directory or one
180
`validation-config.yaml`), then CLI flags. The essentials:
181
182
* `connections`: a `source` and a BigQuery `target`. The target needs
183
`projectId` and `dataset`; without `dataset` the run fails, even when every
184
`targetTable.name` is fully qualified. `configure` can scaffold the wrong
185
source `dialect` (for example `snowflake` for PostgreSQL metadata), so
186
check it and its properties before the first run. Connection names are
187
letters and digits only; a name with `_` or `-` fails config validation. If
188
the user asks for such a name, drop the separators (for example `sales-db`
189
becomes `salesdb`) and tell them why, because the name also forms the
190
environment variable prefix. Keep secrets out of YAML: use
191
`BQMS_VALIDATION_<CONNECTION>_PASSWORD` or a Secret Manager reference (see
192
[connections and drivers](references/connections.md)). Never ask the user
193
to type a password into the conversation and never echo one. For commands
194
you run yourself, use a Secret Manager reference (`passwordSecret` or
195
`BQMS_VALIDATION_<CONNECTION>_PASSWORD_SECRET`); give plaintext `export`
196
lines only for the user to run in their own terminal.
197
* `googleCloudStorage.gcsPath`: required staging bucket (`gs://bucket/path`,
198
no trailing slash). Results artifacts also land here.
199
* Per table: `sourceTable` and `targetTable` (each with `name` and, under
200
`sourceTable`, `comparisonKeys`: the columns that uniquely identify a row
201
for the validation join when the table has no primary key — explain that
202
`comparisonKeys` only control how validation matches rows, so no database
203
primary key or schema change is needed; `configure` fills them in only
204
when the metadata includes primary keys), `columnSettings` (exclusions,
205
transforms, tolerances), `sampleSize`, and `partitioning`.
206
* `results.dataset` and optional `results.projectId`: BigQuery dataset and
207
project for results (defaults `validation_results` and the target
208
connection's project). Query results where these point.
209
210
Details: [configuration reference](references/configuration.md).
211
212
## 4. Run and wait
213
214
1. Run `gcloud alpha bq migration validation run`. Exit code 1 means a config
215
or source-side failure; read the error and fix it. Exit code 0 means the
216
samples were staged (or that usage was printed for a bad forwarded flag;
217
check the output). Mismatches never change the exit code.
218
2. Confirm a workflow started. The client prints a workflow name per table and
219
writes `run_state.json` (run ID, Cloud Storage paths, workflow names,
220
results dataset) to `--output-dir` (default `/tmp/validation_outputs`,
221
passed after `--`). If it instead prints "Could not initiate BigQuery
222
Migration validation workflow", fix the cause it reports (usually
223
permissions or the API not enabled) and re-run, or create the workflow from
224
the console link it prints.
225
3. Poll until the workflow finishes:
226
227
```bash
228
gcloud bq migration-workflows describe WORKFLOW_NAME
229
```
230
231
Or check `run_history.status` in the results dataset; `IN_PROGRESS` means
232
the backend is still working.
233
234
## 5. Investigate results
235
236
Results are in three places. Pick by question, not by habit:
237
238
Surface | Audience | Grain | Use for
239
:--------------------------------------------- | :------------- | :--------------------------------------------- | :------
240
BigQuery results dataset | Agents, humans | Run, slice (partition), column, aggregate, row | All investigation; the only source for per-partition and per-row detail
241
Cloud Storage `results.json` | Agents | One run (whole table) | Quick status of one table without BigQuery access; execution times
242
`validation_summary.txt`, `column_details.txt` | Humans | One run | Show the user; do not parse
243
Web UI | Humans | All of the above, visual | Point the user to it if the printed link is a real URL
244
245
Investigate by zooming in one level at a time, stopping as soon as the cause is
246
clear:
247
248
1. **All tables**: Latest run per table with status, row deltas, and mismatch
249
counts. Errors first, then the largest mismatch counts.
250
2. **One table, by pillar**: Schema compatibility, then failed aggregates, then
251
missing rows, then per-column mismatch statistics.
252
3. **Partitions**: Per-slice metrics show whether mismatches are local (one day
253
or range: a failed load) or everywhere (a systematic conversion).
254
4. **Rows**: Group mismatched cells by column and distance, then read a few
255
rows to confirm the pattern.
256
5. **Fix and re-run narrowly**: Pass `--tables` and `-- --where`, then compare
257
the new run with the old one.
258
259
Then zoom back out: say which tables pass, which have explained differences, and
260
which need a fix in the migration itself. A narrower re-run (some
261
`--validation-types`, or `--where`) becomes the table's latest run without
262
covering the rest; a table passes only when every pillar and the whole table
263
passed.
264
265
Queries, field names, and decision rules for each level:
266
[investigation workflow](references/investigation.md). What every status, field,
267
and table means: [results reference](references/results.md).
268
269
## 6. Reference guides
270
271
Guide | Read when
272
:------------------------------------------------------------ | :--------
273
[CLI reference](references/cli.md) | Installing, running, flags, exit codes, workflow status
274
[Configuration reference](references/configuration.md) | Writing or auditing YAML, keys, transforms, tolerances
275
[Connections and drivers](references/connections.md) | Credentials, Secret Manager, JDBC drivers, JDBC URLs
276
[Sampling and partitioning](references/performance_tuning.md) | Sample sizes, partitioned runs, wide tables, concurrency
277
[Results reference](references/results.md) | Statuses, `results.json`, BigQuery tables and views, distances
278
[Investigation workflow](references/investigation.md) | Step-by-step drill-down queries and decision rules
279
[Dialects and types](references/dialect_mapping.md) | Default aggregates, type compatibility, dialect quirks
280
[Troubleshooting](references/troubleshooting.md) | Mismatch signatures and their config fixes, run errors
281
282
## 7. Operating principles
283
284
1. **Read-only**: Validation only runs `SELECT` on the source and target. Never
285
modify source or target data to make a validation pass.
286
2. **Mismatches are findings, not failures**: A run that finishes with
287
mismatches (`COMPLETED_WITH_MISMATCHES`) succeeded and found differences.
288
Reserve "failed" for `ERROR` runs and non-zero exit codes.
289
3. **Explain before excluding**: Do not add `exclude`, tolerances, or
290
transforms to hide a difference until the row-level evidence shows it is a
291
representation difference (padding, precision, empty string versus NULL) and
292
not lost or wrong data. Say which one it is.
293
4. **Protect row data**: Mismatch tables hold real customer values. Query
294
aggregates and small samples (`LIMIT`), and do not paste bulk row values
295
into the conversation unless the user asks.
296
5. **Edit the user's config in place**: When the user names a config file, read
297
it, change only what the task needs, and keep everything else as written:
298
table names (including dataset or schema prefixes), `comparisonKeys`,
299
filters, and settings. Do not normalize or shorten existing names. A changed
300
`targetTable.name` points the comparison at a different table, and a dropped
301
`comparisonKeys` changes what counts as a missing row, so either silently
302
changes what is validated. If something existing looks wrong, say so instead
303
of changing it.
304
305
[cloud_locations]: https://cloud.google.com/about/locations
306
[gcloud_install]: https://cloud.google.com/sdk/docs/install
307

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…