BigQuery SQL Migration Translator

BigQuery SQL Migration Translator

Guides an AI agent in translating legacy SQL, schemas and procedures from Teradata, Oracle, Snowflake and others to BigQuery GoogleSQL using the Migration Service.

Skill files34 files

assets/

references/

assets/translation_config_examples/

assets/translation_config_schemas/

SKILL.md288 lines
1
---
2
name: bigquery-migration-sql-translator
3
metadata:
4
version: "1.0.3"
5
category: BigDataAndAnalytics
6
publisher: google
7
description: >-
8
Translates SQL queries, DDL schemas, and stored procedures from legacy database
9
dialects (Teradata, Oracle, Redshift, Snowflake, SparkSQL, HiveQL) to BigQuery
10
GoogleSQL using the BigQuery Migration Service (BQMS) MCP server. Use when
11
translating legacy SQL queries, migrating schemas or metadata zip archives,
12
or configuring BigQuery Migration Service (BQMS) YAML translation settings.
13
Don't use for executing BigQuery queries or managing datasets and tables (use
14
bigquery-basics), diagnosing runtime job errors (use bigquery-troubleshooting),
15
or tuning slot reservations (use bigquery-optimization).
16
---
17
18
# BigQuery Migration Service (BQMS) SQL Translator
19
20
The BigQuery Migration Service (BQMS) translates legacy database SQL scripts,
21
queries, and schemas into GoogleSQL. This skill coordinates translation
22
workflows, Cloud Storage staging, compiler error triage, and YAML configuration.
23
24
## Usage Attribution
25
26
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
27
MUST read and follow the instructions in
28
[Usage Attribution](references/attribution.md).
29
30
## Before you begin
31
32
Before translating queries or schemas, verify the following prerequisites:
33
34
1. **Google Cloud SDK & Project Setup**: Ensure the
35
[Google Cloud SDK](https://cloud.google.com/sdk/docs/install) is installed,
36
verify that your Google Cloud project has an active Cloud Billing account
37
attached, and select the target project:
38
39
```bash
40
gcloud config set project {project_id}
41
```
42
43
2. **Enable the API**: Enable the BigQuery Migration API
44
(`bigquerymigration.googleapis.com`) in your Google Cloud project:
45
46
```bash
47
gcloud services enable bigquerymigration.googleapis.com
48
```
49
50
3. **Required IAM Roles**: Verify that your identity or service account has:
51
- `roles/mcp.toolUser` (MCP Tool User)
52
- `roles/bigquerymigration.editor` (Migration Workflow Editor)
53
- For batch translation, `roles/storage.objectViewer` and
54
`roles/storage.objectCreator` (or `roles/storage.objectAdmin`) on the
55
Cloud Storage buckets that hold the input and output files.
56
4. **MCP Server Connection**: If BigQuery Migration Service (BQMS) tools (e.g.
57
`translate_query`, `translate_batch_queries`) are not present in your active
58
tool list, configure the remote BigQuery Migration Service (BQMS) MCP
59
server. For setup instructions across clients (Claude, Cursor, Gemini CLI,
60
VS Code), see [mcp_config.md](references/mcp_config.md).
61
5. **Cost & Cloud Storage Cleanup**: Review
62
[Google Cloud Pricing](https://cloud.google.com/pricing) for Cloud Storage
63
and BigQuery usage details. After completing a batch migration, clean up
64
temporary staged input and output folders in Cloud Storage:
65
66
```bash
67
gcloud storage rm -r gs://{bucket}/{folder}
68
```
69
70
6. **Translation Tracking**: For batch translations, and for queries that need
71
more than one translation iteration, keep a translation tracker (e.g.
72
`translation_tracker.md`) to document goals, planned steps, and progress.
73
After each translation, record one row with this template:
74
75
Iteration | Status | Total Errors | Correctness Errors | Completeness Errors | Compatibility Errors | Key Actions / Transformations
76
--------- | ------ | ------------ | ------------------ | ------------------- | -------------------- | -----------------------------
77
78
A single query that translates cleanly on the first attempt needs no
79
tracker: report its translation ID and logs in your response.
80
81
## Workflow Selection
82
83
Choose the workflow based on your migration scope:
84
85
- **Interactive Translation (Single Query)**: Best for ad-hoc queries,
86
exploratory testing, dialect syntax comparison, or quick error debugging.
87
- **Batch Translation (Multiple Files & Cloud Storage)**: Use for more than
88
one file or a directory, including SQL embedded in application code (extract
89
it into `.sql` files first). For multi-file Python codebases containing
90
embedded SQL, use
91
[python_embedded_sql_migrator_template.py](assets/python_embedded_sql_migrator_template.py)
92
to extract queries into staged files and re-inject translated SQL. Batch
93
translation is faster and cheaper than translating files one by one, and it
94
resolves cross-file dependencies, so it usually gives better results. Run
95
`translate_batch_queries` on the staged files first; use `translate_query`
96
only afterwards if needed to debug a specific statement from
97
`translation_report.csv`.
98
99
## 1. Interactive Translation Workflow
100
101
Use the interactive workflow to translate a single query string, inspect
102
compiler logs, and iteratively resolve issues.
103
104
### Steps
105
106
1. **Submit Query (`translate_query`)**: Call `translate_query` with
107
`projectNumber`, `location`, `inputQuery`, `sourceDialect`, and
108
`targetDialect` (`BigQuery`). Include optional parameters:
109
110
- `metadataFilePath`: Cloud Storage URI to a metadata zip file
111
(`gs://.../metadata.zip`) for schema resolution.
112
- `translationConfigs`: Inline YAML configurations (e.g. object renaming,
113
schema redirection, optimizer rules). Show the YAML you used in your
114
response so the user can reuse it (e.g. in batch translation).
115
116
2. **Poll Status (`get_translation`)**: If the returned `translation_state` is
117
`RUNNING` or `PENDING`, poll `get_translation` using the `translation` ID,
118
`projectNumber`, and `location` until `translation.state` is `SUCCEEDED` or
119
`FAILED`, at the interval given in the BigQuery Migration Service (BQMS) MCP
120
tool descriptions. While the job runs, do work that doesn't need the result
121
(e.g. read the dialect gotchas reference).
122
123
3. **Inspect Output & Logs**:
124
125
- Examine `translated_query` for the converted GoogleSQL.
126
- Review each entry in `translation_logs`: inspect `severity` (`ERROR`,
127
`WARNING`), `category` (e.g. `RelationNotFound`), and `effect`
128
(`CORRECTNESS`, `COMPLETENESS`, `COMPATIBILITY`).
129
- Check the SQL itself, not only the logs: BigQuery Migration Service
130
(BQMS) emits `ERROR_TYPE(...)` for types it cannot map, sometimes with
131
no log entry. Treat any `ERROR_TYPE` or inline error comment as an
132
error, and when a BigQuery project is available, dry-run the result (`bq
133
query --dry_run --use_legacy_sql=false`). A `Not found` or `must be
134
qualified with a dataset` error still means the SQL is syntactically
135
valid; the referenced objects just don't exist in BigQuery yet. Say so
136
and move on, even if the error suggests a fix: don't stub tables or
137
change the SQL or `bq` flags to get past it.
138
- A `NoSuchFunction` error means BigQuery Migration Service (BQMS) copied
139
that call unchanged, sometimes with the function name in backticks.
140
Treat it as untranslated even if BigQuery has a function with that name:
141
a dry run that stops at missing tables doesn't check it.
142
- If the source dialect has a gotchas reference (see
143
[Dialect-Specific Gotchas](#dialect-specific-gotchas)), read it and
144
check the output for the patterns it lists. Some semantic differences
145
produce no log entry and still pass a dry run.
146
147
4. **Iterate Until Clean**: If the logs contain errors or warnings, the
148
translated SQL contains `ERROR_TYPE` or inline error comments, the dry run
149
fails, or the output matches a dialect gotcha, resolve the issues as
150
described in [Resolving Translation Issues](#resolving-translation-issues)
151
and re-translate.
152
153
5. **Explain & Compare Differences (`explain_translation`)**: When requested to
154
explain a translation, compare syntax differences, or understand how
155
specific query logic was converted, call `explain_translation` with
156
`translation` (the translation ID), `projectNumber`, and `location`. This
157
returns a structured explanation of the query's purpose and a detailed
158
breakdown of syntax, function, and behavioral differences between the source
159
query and the translated GoogleSQL. The explanation doesn't validate the
160
output, so check the translation as in step 3 rather than relying on it.
161
162
## 2. Batch Translation Workflow
163
164
Batch translation handles multiple files staged in Cloud Storage. It resolves
165
cross-file dependencies and produces a consolidated translation summary report
166
(`translation_report.csv`).
167
168
### Steps
169
170
1. **Stage Input Files to Cloud Storage**: Upload the raw SQL files,
171
configuration files (`*.config.yaml`), and any metadata file from the local
172
workspace to a Cloud Storage input folder:
173
174
```bash
175
gcloud storage cp input/*.sql gs://my-bucket/migration/input/
176
gcloud storage cp *.config.yaml gs://my-bucket/migration/input/
177
```
178
179
*Note: Do not pass configuration file paths in tool parameters if those
180
files are already located inside `sourceBaseUri`.*
181
182
Use new, empty Cloud Storage input and output folders for each run (e.g.
183
with a timestamp suffix). Stage only files from the local workspace or
184
generated in this run. Never reuse or copy inputs, DDL, or outputs that are
185
already in a bucket from earlier runs: they may come from different inputs
186
or settings.
187
188
2. **Initiate Batch Translation**:
189
190
- **Translating SQL Queries (`translate_batch_queries`)**: Call
191
`translate_batch_queries` with `projectNumber`, `location`,
192
`sourceDialect`, `targetDialect`, `sourceBaseUri`, and `targetBaseUri`.
193
- **Translating Metadata Zip Files (`translate_metadata`)**: To aid batch
194
translation by generating target BigQuery DDL schema definitions from an
195
extracted database metadata zip file (`metadata.zip` from Teradata,
196
Oracle, etc.), call `translate_metadata` specifying `sourceBaseUri`
197
(Cloud Storage URI to `metadata.zip`) and `targetBaseUri` (destination
198
Cloud Storage folder).
199
200
3. **Poll Completion (`fetch_batch_translation`)**: Poll using the returned
201
workflow ID until `translation.state` is `SUCCEEDED` or `FAILED`, at the
202
interval given in the BigQuery Migration Service (BQMS) MCP tool
203
descriptions.
204
205
4. **Retrieve & Inspect Outputs**: Download the generated files from
206
`translation.target_base_uri`:
207
208
```bash
209
gcloud storage cp -r gs://my-bucket/migration/output/ ./local_output/
210
```
211
212
Locate and inspect `report/translation_report.csv` to review all warnings,
213
errors, and line-level diagnostics. Then scan the generated `.sql` files for
214
`ERROR_TYPE(...)` and inline error comments, which the report can miss, and
215
dry-run the generated SQL when a BigQuery project is available (handle `Not
216
found` errors as in the interactive workflow). Check the output for the
217
patterns in the source dialect's gotchas reference, if one exists. Resolve
218
or clearly report every remaining issue; do not describe the output as clean
219
until this check passes.
220
221
5. **Iterate Until Clean**: Resolve the issues found in step 4 as described in
222
[Resolving Translation Issues](#resolving-translation-issues), and re-run
223
from step 1 with the changed inputs.
224
225
6. **Post-processing (Final Step Only)**: Only after resolving every compiler
226
error that re-translation can fix, execute any application-level
227
post-processing (e.g. AST re-injection) to restore host source files.
228
[effect_correctness.md](references/effect_correctness.md) lists the errors
229
that may remain when re-injecting embedded SQL.
230
231
## Resolving Translation Issues
232
233
Both workflows resolve issues the same way:
234
235
- Identify the **Effect** (`CORRECTNESS`, `COMPLETENESS`, `COMPATIBILITY`) of
236
each issue, and resolve them in order of compiler phase dependencies:
237
`CORRECTNESS` (parse errors) first, then `COMPLETENESS` (missing objects),
238
then `COMPATIBILITY` (unsupported features).
239
- **MUST Read the Reference Guide** for each effect in
240
[Troubleshooting by Error Effect](#troubleshooting-by-error-effect) BEFORE
241
applying fixes, and follow its resolution workflow.
242
- Fixes can preprocess the input (e.g. prepend DDL) or post-process the
243
BigQuery Migration Service (BQMS) output (e.g. a rewrite that a dialect
244
gotcha calls for). Run BigQuery Migration Service (BQMS) on the preprocessed
245
input rather than translating it yourself.
246
- Keep the source system's dialect for every re-translation. Another dialect
247
may accept the same SQL but translate it with different semantics (e.g.
248
return types, numeric types, or identifier case), so don't switch dialects
249
to get cleaner output.
250
- Rewrites of the BigQuery Migration Service (BQMS) output, including
251
optimizations the user asks for, must return the same rows as the source
252
query. For example, a filter that runs after a row limit (`TOP`, `LIMIT`)
253
can't be merged into the query before the limit.
254
- Wait for each re-translation to finish, record its translation ID, error
255
counts, and any pre- or post-processing in the tracker, and compare the
256
counts with the previous iteration. Repeat until no errors remain or all
257
options are exhausted.
258
- Report the final SQL from the tracked iteration, the pre- and
259
post-processing you applied, and any errors that remain.
260
261
## Reference Lookup Index
262
263
Use these reference guides when troubleshooting errors or authoring
264
configuration files:
265
266
### Troubleshooting by Error Effect
267
268
Effect | Common Causes | Reference Guide
269
:-------------- | :----------------------------------------------------------------------------------------- | :--------------
270
`CORRECTNESS` | Syntax errors, unescaped literals, application script wrappers, `NoSuchFunction`. | [effect_correctness.md](references/effect_correctness.md)
271
`COMPLETENESS` | Missing tables, views, columns (`RelationNotFound`, `AttributeNotFound`), DDL suggestions. | [effect_completeness.md](references/effect_completeness.md)
272
`COMPATIBILITY` | Functions or features without direct GoogleSQL mapping. | [effect_compatibility.md](references/effect_compatibility.md)
273
274
### Configuration & Setup Guides
275
276
Task | Description | Reference Guide
277
:---------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------
278
**YAML Configurations** | Database/schema redirection, name mapping, table partitioning and clustering injection, optimizer transformations, statement rewriters, and environment settings. Schemas in `assets/translation_config_schemas/` and examples in `assets/translation_config_examples/`. | [translation_yaml_config.md](references/translation_yaml_config.md)
279
**MCP Server Setup** | Configuring the remote BigQuery Migration Service (BQMS) MCP server, OAuth scopes, and IAM roles. | [mcp_config.md](references/mcp_config.md)
280
281
### Dialect-Specific Gotchas
282
283
Dialect | Key Considerations | Reference Guide
284
:------------ | :-------------------------------------------------------------------- | :--------------
285
**Teradata** | SET/MULTISET tables, `SAMPLE` clause, primary index mapping. | [teradata_gotchas.md](references/teradata_gotchas.md)
286
**Oracle** | PL/SQL procedures, `ROWNUM` emulation, outer join `(+)`, sequences. | [oracle_gotchas.md](references/oracle_gotchas.md)
287
**Snowflake** | Dynamic templates, `USE` statements, metadata merging, lateral joins. | [snowflake_gotchas.md](references/snowflake_gotchas.md)
288

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

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 11,643 prompts

More by @OpenSourceBuffGuy

See all
Yellow Graffiti Fisheye Manga Street Poster Style prompt image

Yellow Graffiti Fisheye Manga Street Poster Style

Defines a street-poster style mixing a cool fisheye city photo, a large manga ink cutout character and oversized sprayed yellow graffiti lettering.

image-prompt, json-prompt, placeholders, poster, manga, graffiti, fisheye, cityscape, typography, collage, vibrant-colors, text-rendering, vertical-format, widescreen, graphic-design, for-designers, for-artists, ink-drawing, high-angle, street-photography, character-design, structured-output, long-form, advanced, style-reference

GitHub Actions Runtime Upgrade prompt image

GitHub Actions Runtime Upgrade

Upgrades GitHub Actions workflows off deprecated runtimes by picking safe action versions, pinning them to commit SHAs and keeping behaviour unchanged.

agent-skill, github-actions, ci-cd, migration, devops, github, best-practices, deployment, nodejs, for-developers, for-devops-engineers, checklist, security-review, release-management, step-by-step-guide, quick

Test Strategy Development Expert prompt image

Test Strategy Development Expert

Designs a software test strategy covering the test pyramid, automation frameworks, CI/CD quality gates and non-functional testing for a team's application.

system-prompt, expert-advice, planner, testing, ci-cd, unit-testing, end-to-end-testing, devops, software-architecture, performance-optimization, security-review, accessibility, test-cases, technical-spec, xml-tags, structured-output, guardrails, for-developers, for-devops-engineers, advanced, long-form, best-practices, roadmap

Reviews

Loading reviews…

Discussion

Loading comments…