Dbt sf to bq translator

From google/skills · View interactive version

Dbt sf to bq translator is an AI agent skill from the GitHub repository google/skills. Translates Snowflake dbt SQL models to Standardized BigQuery SQL. Handles SQL compilation, Jinja macro placeholder masking, BigQuery Translation Service migration workflows, AST-based config transformations, explicit type casting, JSON extraction standardization, and deduplication. Use when migratin

How to use this skill

Skill file

dbt Snowflake to BigQuery Translator

You are responsible for:

  1. Dialect Translation: Translating Snowflake dbt SQL models to Standardized BigQuery SQL on Google Cloud.
  2. Standardization & Compliance: Enforcing Google-specific standards including copyright headers at the very top of each file, explicit type casting, standardized JSON extraction, and deduplication via QUALIFY with _extracted_at.
  3. Workflow Integration: Preserving dbt Jinja constructs and storing the final BigQuery-compatible models.

Follow the instructions given you under migration_plan/[mig_prefix]/tasks.md. You will add your progress during operation and summary at the end to the tasks file so that human supervisor can track where you are. You recover from errors by checking the tasks file.

Attribution

MUST READ: Before executing any gcloud, REST API, or MCP command, you

MUST read Usage Attribution. For commands executed

directly in the terminal (never in generated scripts, Terraform, or user code),

prefix gcloud with

CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:dbt-sf-to-bq-translator)"

and append agent-skills/1.0 (skill:dbt-sf-to-bq-translator) to

User-Agent headers.

Prerequisites & Environment Setup

Before starting the translation, ensure your Google Cloud environment is properly configured:

  1. Google Cloud SDK: Install the Google Cloud SDK if not already installed.
  2. Authentication: Authenticate your CLI session:

```bash

gcloud auth login

gcloud auth application-default login

```

  1. Project Configuration: Set your active Google Cloud project:

```bash

gcloud config set project {project_id}

```

  1. Billing Account: Verify that an active Google Cloud Billing account is attached to the target project.
  2. Enable Required APIs: Ensure BigQuery, Migration, and Storage services are enabled:

```bash

gcloud services enable bigquerymigration.googleapis.com storage.googleapis.com bigquery.googleapis.com

```

  1. Region Selection: Configure your preferred compute/BigQuery region (default recommended: us-central1 or us). See Google Cloud Locations:

```bash

gcloud config set compute/region us-central1

```

Steps

1. Migration Project Name (e.g. my_migration_project).

2. Input directory containing Snowflake SQL files.

3. Output directory where BigQuery SQL files should be saved.

4. Cloud Storage bucket name for staging translation assets.

5. Google Cloud region (e.g. us or eu).

6. (Optional) Local path to a directory or .zip file containing source database metadata (such as columns.csv or tables.csv).

Once provided, create the tasks checklist file under migration_plan/[mig_prefix]/tasks.md with unchecked tasks representing the migration steps.

Execute the deterministic end-to-end migration using the bundled translation script scripts/bulk_translate_via_gcloud.py:

```bash

python3 scripts/bulk_translate_via_gcloud.py \

--input {input_dir} \

--output {output_dir} \

--bucket {gcs_bucket} \

--location {region} \

[--metadata {metadata_path}] \

[--array-cast-mode {array_cast_mode}] \

[--struct-columns {struct_columns}]

```

| Flag | Default | Description |

| :--- | :--- | :--- |

| --input | (Required) | Local directory containing source Snowflake dbt .sql and .yml files. |

| --output | (Required) | Target directory for translated BigQuery dbt .sql and .yml files. |

| --bucket | (Required) | Cloud Storage bucket name used to stage translation inputs and outputs. |

| --location | us | Google Cloud region for BigQuery Translation Service execution (e.g., us, eu). |

| --metadata | None | Optional path to a directory or .zip archive containing source tables.csv and columns.csv. |

| --array-cast-mode | array_string | Target conversion for BQMS ARRAY<JSON> casts. Use array_string (ARRAY<STRING>) by default; use string (STRING), json_extract_string_array, or preserve as escape hatches when required by the source table schema. |

| --struct-columns | None | Optional comma-separated list of additional BigQuery STRUCT column names (e.g., struct_col,record_col) to convert from JSON_VALUE to native dot notation (col.field). |

The migration tools bundled in scripts/ perform the following coordinated actions:

1. Compile to Standard SQL using Placeholders (Pre-Translation):

2. Isolate the SQL Files:

3. Pre-Process Metadata & Translate SQL via BigQuery Translation Service:

gcloud storage cp <staging_input_dir>/*.sql gs://[YOUR_BUCKET]/migration_input/

gcloud bq migration-workflows create --location=<region> --config-file=migration_config.yaml --no-async

gcloud storage cp gs://[YOUR_BUCKET]/migration_output/*.sql <translated_output_dir>/

4. Restore Placeholders & Re-Embed dbt Logic:

5. Write to the New BigQuery dbt File & Copy YAML Configurations:

Mandates & Behavioral Rules

1. Mandatory File Header

Every translated file MUST start with the following exact header at the very top:

# Copyright 2026 Google. This software is provided as-is, without warranty or
# representation for any use or purpose. Your use of it is subject to your
# agreement with Google.

2. Standardized JSON & Array Extraction

Never use Snowflake colon notation (:) in BigQuery SQL because BigQuery Standard SQL does not recognize colon syntax for semi-structured field access and throws a syntax error. Translate semi-structured lookups using BigQuery's standard functions and consult dbt_migration_patterns.md for detailed patterns and error remedies:

for native JSON columns (omit dots before array indexes, e.g.,

$.items[1]), and

CAST(JSON_EXTRACT_SCALAR(SAFE.PARSE_JSON(CAST(source.col AS STRING)), '$.path') AS TYPE)

for stringified JSON columns. Preserve 1:1 warehouse cast semantics: wrap

typed extractions in CAST(... AS INT64|BOOL|TIMESTAMP|NUMERIC) for Snowflake

CAST / ::TYPE / TO_* (failing fast on invalid data), and use

SAFE_CAST(...) only when the Snowflake source explicitly uses TRY_CAST or

TRY_TO_* (returning NULL on malformed values).

3. Explicit Type Safety

not identical (using AS STRING for universal comparison safety if

necessary). Preserve 1:1 cast parity with Snowflake (CAST / ::TYPE to

CAST, and TRY_CAST / TRY_TO_* to SAFE_CAST); do not introduce

SAFE_CAST for standard Snowflake casts because silently coercing malformed

keys to NULL changes warehouse behavior and masks join or primary-key

errors.

4. Prescriptive String & Date Functions

5. Mandatory Deduplication & Joins

6. Preserve Jinja Constructs

Do not alter {{ config(...) }}, {{ ref(...) }}, or {{ source(...) }}. Keep {% if is_incremental() %} blocks functional. Do not inject historical data unions or other custom macros/tables unless they are present in the source files.

Outputs

You will output BigQuery-compatible dbt SQL models under migration_plan/[mig_prefix]/translated_models/. The translated files must strictly adhere to the structural pattern and dialectic formatting.

For translation examples, see: dbt_migration_patterns.md

Constraints

Before handing over to the root agent, first get approval from the user about the translated models. After applying user's requests, then hand over the root agent.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.