Home / Market / bigquery migration data exporter

bigquery migration data exporter

Generates type-safe, schema-aligned database data export SQL files (.sql) for Snowflake, Databricks, Teradata, Oracle, and PostgreSQL directly from BigQuery Migration Service (BQMS) translation_output/metadata configs, exporting into target file formats (such as Parquet). Use when generating source database export SQL scripts for BigQuery ingestion without connecting to the source database. Don't use for executing SQL against source databases or streaming/staging exported files, extracting sourc

skill★ 254940 dlgithubApache-2.0Install in CosmosUpstream Source

Documentation & Preview

--- name: bigquery-migration-data-exporter metadata: version: "1.0.0" category: BigDataAndAnalytics publisher: google description: >- Generates type-safe, schema-aligned database data export SQL files (.sql) for Snowflake, Databricks, Teradata, Oracle, and PostgreSQL directly from BigQuery Migration Service (BQMS) translation_output/metadata configs, exporting into target file formats (such as Parquet). Use when generating source database export SQL scripts for BigQuery ingestion without connecting to the source database. Don't use for executing SQL against source databases or streaming/staging exported files, extracting source database catalog metadata, translating SQL queries or DDL schemas (use bigquery-migration-sql-translator), loading staged Parquet files into BigQuery, or running post-migration data validation.

---

BigQuery Migration Data Exporter

This skill coordinates the generation of type-aware data export SQL scripts (.sql files) for source data warehouses (such as Snowflake, Databricks, Teradata, Oracle, and PostgreSQL) into target file formats (such as

BigQuery-aligned Parquet files), guided by dialect and format specifications in the references/ directory.

All templates in this skill are pure SQL generators with zero JDBC or database connector dependencies.

> [!TIP] > Point directly to the BigQuery Migration Service (BQMS) > translation_output/metadata directory (local path or Cloud Storage URI). > It automatically discovers all physical tables and target BigQuery logical > types from metadata/config/*.yaml.

Usage Attribution

MUST READ: Before executing any gcloud, REST API, or MCP command, you MUST read and follow the instructions in Usage Attribution.

Before you begin

  1. Google Cloud CLI & Project Setup: When reading translation outputs or

metadata archives from gs:// Cloud Storage URIs, ensure the Google Cloud CLI is installed, verify that your Google Cloud project has an active Cloud Billing account attached, and configure the target project:

    gcloud config set project {project_id}
  1. Enable the API: When reading metadata from Cloud Storage (gs://), ask

the user before enabling APIs, then enable the Cloud Storage API (storage.googleapis.com):

    gcloud services enable storage.googleapis.com
  1. Authentication & Required Identity and Access Management (IAM) Roles:

Authenticate with gcloud auth login and gcloud auth application-default login (or set GOOGLE_APPLICATION_CREDENTIALS for service account authentication). Verify that your identity or service account has roles/storage.objectViewer (Storage Object Viewer) on any Cloud Storage bucket holding input metadata. Creating a staging bucket requires roles/storage.admin (Storage Admin) on the Google Cloud project, and deleting staged files requires roles/storage.objectAdmin (Storage Object Admin) on the staging bucket.

  1. Python Environment: The generator templates require Python 3.9 or

later. Ask the user for confirmation before installing Python packages, then install PyYAML in a virtual environment (generator templates have zero JDBC or database connector dependencies):

    pip install pyyaml==6.0.2
  1. Region, Cost & Cleanup: Ask the user for confirmation before creating

a new Cloud Storage bucket for staging exported Parquet files (gcloud storage buckets create gs://{bucket} --location={region}), and default to us-central1 unless your target BigQuery dataset uses another region (co-locate buckets with your dataset; see Google Cloud locations). Review Google Cloud Pricing before staging large exports. After BigQuery ingestion, temporary staged Parquet prefixes can be removed with gcloud storage rm -r gs://{bucket}/{export_prefix}. This deletion is permanent: run it only after the user explicitly confirms the exact URI, and never with an empty {export_prefix} (which would delete every object in the bucket).

  1. Snowflake Storage Integration: To unload Snowflake tables directly to a

private Cloud Storage bucket (--stage-path 'gcs://...'), Snowflake requires a [storage integration][snowflake_gcs_integration] that grants its service account access to the bucket. Ask the user for the integration name and pass it with the --storage-integration flag, which adds a STORAGE_INTEGRATION clause to each generated COPY INTO statement. Unloads to a Snowflake stage (for example, @~/bqms_export/ or a named external stage) don't need this flag.

--------------------------------------------------------------------------------

1. Direct Consumption of Translation Output Metadata

bigquery-migration-data-exporter consumes the native BigQuery Migration Service (BQMS) metadata translation output: translation_output/metadata/config/<database>/<schema>/<table_name>.yaml

Each configuration file specifies:

  1. sourceName: Fully qualified source table name.
  2. columns: Source data types, precision, scale, and BigQuery target types.
  3. Table versus view: A config with neither externalTableName nor

externalTableDdlPath describes a view, which is recreated as a SQL view and isn't exported. The Databricks generator also honors an explicit TableType field when present.

--------------------------------------------------------------------------------

2. Format-Guided Type-Safe Export Fundamentals

A plain unguided COPY INTO @stage FROM table or SELECT * often fails during BigQuery ingestion (bq load) due to serializer discrepancies (for example, VARIANT JSON encoding, CHAR(n) fixed-width space padding, unbounded Teradata/Oracle/PostgreSQL NUMBER/NUMERIC scale truncation, PostgreSQL MONEY locale currency formatting, Oracle DATE time-of-day components, or timestamp nanosecond ticks).

To ensure zero type drift and clean BigQuery ingestion, apply type-aware projections guided by the target format and dialect specifications in the

references/ directory. While Parquet is the standard and recommended format for BigQuery batch ingestion due to columnar compression and strict typing, the export structure adapts based on target format requirements.

For Parquet data exports, the core rules are summarized below; the mapping references listed after them hold the full per-dialect type matrices:

  1. Session Parameters (Snowflake):
    ALTER SESSION SET TIME_OUTPUT_FORMAT = 'HH24:MI:SS.FF6';
    ALTER SESSION SET TIMESTAMP_NTZ_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF6';
    ALTER SESSION SET TIMESTAMP_TZ_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF6 TZHTZM';
  1. **Semi-Structured / JSON (VARIANT, OBJECT, STRUCT, MAP, ARRAY,

JSON, JSONB, XMLTYPE, XML, UUID, INET)**:

STRUCT/ARRAY when targeting JSON or STRING; native passthrough col when targeting RECORD/ARRAY); CAST(col AS STRING) AS col for VARIANT/JSON/INTERVAL.

JSON, and XMLSERIALIZE(CONTENT col AS CLOB) AS col for XMLTYPE.

UUID, INET, CIDR, MACADDR, INTERVAL, BIT, and ARRAY.

  1. Decimals, Numbers, Integers & Floats:

CAST(col AS DECIMAL(p, s)) AS col (or CAST(col AS NUMBER(p, s)) AS col in Oracle, or CAST(col AS NUMERIC(p, s)) AS col in PostgreSQL).

DECIMAL → CAST(col AS DECIMAL(38, 9)) AS col in Snowflake and Teradata, CAST(col AS NUMBER(38, 9)) AS col in Oracle, or CAST(col AS NUMERIC(38, 9)) AS col in PostgreSQL (supports <= 29 integer digits and 9 fractional digits by default; override scale in Teradata, Oracle, and PostgreSQL by using --unbounded-number-scale); PostgreSQL MONEY → CAST(col AS NUMERIC(38, 2)) AS col.

SERIAL → CAST(col AS BIGINT) AS col. In Oracle, SMALLINT → CAST(col AS NUMBER(19, 0)) AS col and the ANSI NUMBER(38) aliases INT / INTEGER → CAST(col AS NUMBER(38, 0)) AS col. Scale-0 decimals with a TargetType of INT64 project as 64-bit integers; the mapping references list which NUMBER(p, 0) / DECIMAL(p, 0) precisions become 64-bit integers by default.

PostgreSQL REAL / DOUBLE PRECISION → CAST(col AS DOUBLE PRECISION) AS col; Oracle BINARY_FLOAT / BINARY_DOUBLE / FLOAT(p) → CAST(col AS BINARY_DOUBLE) AS col (widens to 64-bit IEEE-754 FLOAT64).

  1. **Temporal (DATE, TIME, TIMESTAMP, TIMESTAMP_NTZ, `TIMESTAMP WITH

TIME ZONE`)**:

CAST(CONVERT_TIMEZONE('UTC', col) AS TIMESTAMP_NTZ(6)) AS col.

TIMESTAMP, or leave TIMESTAMP_NTZ uncast when targeting BigQuery DATETIME. TIMESTAMP_NTZ to TIMESTAMP casts (and back) use the session time zone, so run the scripts in a UTC session (see the [Databricks reference][databricks_map]).

'GMT') AS TIMESTAMP(6)) AS col, and CAST((col AT TIME ZONE 'GMT') AS TIME(6)) AS col`.

TIMESTAMP(p) (or TRUNC(col) AS col when DATE explicitly targets BigQuery DATE), CAST(SYS_EXTRACT_UTC(col) AS TIMESTAMP(6)) AS col for TIMESTAMP WITH TIME ZONE, and CAST(SYS_EXTRACT_UTC(CAST(col AS TIMESTAMP WITH TIME ZONE)) AS TIMESTAMP(6)) AS col for TIMESTAMP WITH LOCAL TIME ZONE (UTC, whatever the session time zone).

CAST(col AS TIMESTAMP(6) WITHOUT TIME ZONE) AS col for TIMESTAMP [WITHOUT TIME ZONE], and CAST(col AS TIMESTAMP(6) WITH TIME ZONE) AS col for TIMESTAMPTZ / TIMESTAMP WITH TIME ZONE.

  1. **Fixed-Width Character Padding (CHAR(n) / NCHAR(n) / BPCHAR /

GRAPHIC(n))**: TRIM(TRAILING FROM col) AS col (Teradata) or RTRIM(col) AS col (Oracle and PostgreSQL) to strip fixed-width trailing pad spaces.

  1. Explicit Target Types: A BigQuery TargetType from the BQMS config

(for example a schema override to INT64, NUMERIC, DATE, or TIMESTAMP) wins over the source-type defaults above so the Parquet column matches the BigQuery DDL. Cross-type overrides that a template doesn't convert keep the default projection: STRING, JSON, and BYTES in Oracle and Teradata (text columns stay text, binary columns stay bytes, and numeric or datetime columns keep their type); BOOL in Teradata and Oracle; TIME in Oracle and Databricks; DATE on Oracle columns other than DATE / TIMESTAMP; and targets other than numeric or STRING on Databricks DECIMAL columns. If bq load reports a type mismatch, edit the template's # CUSTOMIZE: Custom Type Projections hook.

> [!IMPORTANT] > Always cons