{"data":{"slug":"github-google-skills-skills-cloud-bigquery-migration-data-loader-60bf0de04fb3","title":"BigQuery Data Loader for Migration and Ingestion","summary":"Load Parquet files into BigQuery tables and deploy translated views for data migration workflows. The deliverable includes native BigQuery tables and consumption views, with row count audits for verification.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-loader-60bf0de04fb3","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-loader-60bf0de04fb3","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-loader-60bf0de04fb3.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-bigquery-migration-data-loader-60bf0de04fb3\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Before executing any `gcloud`, REST API, or MCP command, you must read and follow the instructions in [Usage Attribution](references\/attribution.md). Additionally, install the Google Cloud CLI and configure your project and region using `gcloud config set project PROJECT_ID` and `gcloud config set compute\/region REGION`.","instructions":"---\nname: bigquery-migration-data-loader\nmetadata:\n  version: \"1.0.0\"\n  category: BigDataAndAnalytics\n  publisher: google\ndescription: >-\n  Provisions BigQuery datasets, ingests staged Parquet files directly into\n  native BigQuery tables by using bq load, and deploys already-translated views\n  from local or Cloud Storage BigQuery Migration Service (BQMS) translation\n  outputs. Use when provisioning target BigQuery datasets for warehouse\n  migrations, batch loading staged Parquet files into native BigQuery tables by\n  using bq load, auditing loaded table row counts, or deploying\n  already-translated BigQuery views into a target dataset. Don't use for\n  extracting source database catalog metadata, translating SQL queries, views,\n  stored procedures, or DDL schemas to GoogleSQL (use\n  bigquery-migration-sql-translator), exporting or unloading source database\n  tables (such as Snowflake, Databricks, Teradata, or Oracle) to Parquet on\n  Cloud Storage, or running post-migration cross-database data validation.\n---\n\n# BigQuery Migration Data Loader\n\nThis skill coordinates the automated provisioning of BigQuery datasets, direct\ningestion of staged Parquet files into native BigQuery tables by using the\n`bq load` command, and automated view deployment directly from BigQuery\nMigration Service (BQMS) translation output directories (local or Cloud\nStorage).\n\n## Usage attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read and follow the instructions in\n[Usage Attribution](references\/attribution.md).\n\n## Before you begin\n\n1.  **Google Cloud CLI, project, and location setup**: Install the\n    [Google Cloud CLI](https:\/\/cloud.google.com\/sdk\/docs\/install) (including\n    the `gcloud` and `bq` command-line tools), confirm that your Google Cloud\n    project has an active Cloud Billing account attached, and configure the\n    target project and default Compute Engine region:\n\n    ```bash\n    gcloud config set project PROJECT_ID\n    gcloud config set compute\/region REGION\n    ```\n\n    `gcloud config set compute\/region` sets the default Compute Engine region;\n    the `bq` CLI does not read `compute\/region` and defaults to `US` unless\n    `--location` is passed on `bq` commands or set in `~\/.bigqueryrc` (or\n    configured through a project or organization `default_location`). BigQuery\n    is retiring the *multi-region* designation\u2014including `US` and `EU` in the\n    single-regions list colocated with `us-central1` and `europe-west4`, with no\n    change to existing data residency (see\n    [BigQuery locations](https:\/\/cloud.google.com\/bigquery\/docs\/locations))\u2014so\n    always pass an explicit `--location` on `bq` commands that matches your\n    staged Cloud Storage bucket, as described in step 5 (check regional\n    service availability at\n    [Google Cloud locations](https:\/\/cloud.google.com\/about\/locations)).\n\n2.  **Enable the APIs**: Ask the user before enabling APIs, then enable the\n    BigQuery and Cloud Storage APIs (`bigquery.googleapis.com` and\n    `storage.googleapis.com`):\n\n    ```bash\n    gcloud services enable bigquery.googleapis.com storage.googleapis.com\n    ```\n\n3.  **Authentication and required IAM roles**: Authenticate with `gcloud auth\n    login` and `gcloud auth application-default login` (or set\n    `GOOGLE_APPLICATION_CREDENTIALS` for service account authentication). Verify\n    that your identity or service account has the required IAM roles on each\n    resource:\n\n    *   Grant **BigQuery Job User** (`roles\/bigquery.jobUser`) on the target\n        Google Cloud project.\n    *   Grant **BigQuery Data Editor** (`roles\/bigquery.dataEditor`) on the\n        target Google Cloud project (to create new datasets with `bq mk`) or on\n        an existing target dataset (to create or overwrite tables and views).\n    *   Grant **Storage Object Viewer** (`roles\/storage.objectViewer`) on the\n        Cloud Storage bucket holding staged Parquet files and translation\n        metadata.\n\n4.  **Python environment**: Ask the user for confirmation before installing\n    Python packages, then install PyYAML in a virtual environment:\n\n    ```bash\n    pip install pyyaml==6.0.2\n    ```\n\n5.  **Location, cost, and cleanup**: Use the location of your staged Cloud\n    Storage bucket for the dataset and every `bq` command: the bucket's region\n    for a regional bucket, or `US` or `EU` for a `US` or `EU` multi-region\n    bucket. Default to `us-central1` only when you also choose the bucket\n    location. Loading from a bucket in a different location incurs data\n    transfer charges (see\n    [BigQuery locations](https:\/\/cloud.google.com\/bigquery\/docs\/locations)).\n    Review\n    [Google Cloud pricing](https:\/\/cloud.google.com\/pricing) before loading\n    large datasets or running audit queries. Ask the user for confirmation\n    before deleting temporary staged Parquet files\n    (`gcloud storage rm -r gs:\/\/BUCKET\/EXPORT_PREFIX`) or test datasets\n    (`bq rm -r -f PROJECT_ID:DATASET_ID`) when no longer needed.\n\n--------------------------------------------------------------------------------\n\n## 1. Loader workflow overview\n\nThe following diagram illustrates the four-stage ingestion and view deployment\npipeline:\n\n```mermaid\nflowchart TD\n    subgraph 1. Inputs\n        A1[\"Translation Output Directory \/ Cloud Storage URI<br>gs:\/\/bucket\/translation_output\/metadata\/\"]\n        A2[\"Staged Parquet Files<br>gs:\/\/bucket\/data_unload\/TABLE\/*.parquet\"]\n    end\n\n    subgraph 2. Ingestion Pipeline\n        B1[\"1. Ensure Dataset Exists<br>bq mk --dataset --location=LOCATION DATASET\"]\n        B2[\"2. Concurrent Parquet Ingestion<br>bq load --source_format=PARQUET --replace=true<br>Auto-creates native tables\"]\n        B3[\"3. Row Count Audit<br>Print BigQuery Row Counts for Comparison\"]\n        B4[\"4. Deploy Consumption Views<br>Deploys views directly from consolidated views.sql or relations\/\"]\n    end\n\n    A1 & A2 --> B1 --> B2 --> B3 --> B4\n```\n\n--------------------------------------------------------------------------------\n\n## 2. Direct translation output ingestion\n\n> [!TIP] **Migration workflow context**: Before running the loader, translate\n> source schemas and views into GoogleSQL by using the\n> `bigquery-migration-sql-translator` skill and stage exported source table\n> Parquet files in Cloud Storage. After loading tables and deploying views,\n> compare row counts and data aggregates against the source database.\n\nThe data loader directly consumes BQMS translation output directories (the\n`--translation-metadata-dir` flag):\n\n*   **Zero-DDL native ingestion**: Table schemas are inferred and created\n    automatically from staged Parquet files during `bq load`. Inferred types\n    follow the Parquet types, not the translated DDL: naive source timestamps\n    (no time zone) load as `TIMESTAMP` instead of `DATETIME`, and\n    `STRING(n)` and `NUMERIC(p, s)` parameters are dropped (see Step 2 in\n    Section 3).\n*   **Automated object discovery**: Base tables and views are auto-discovered\n    directly from the translation output metadata. Pass the BQMS `metadata\/`\n    directory (or its parent), which contains `config\/DATABASE\/SCHEMA\/*.yaml`\n    files whose `sourceName` names each object (table configs also set\n    `externalTableName` or `externalTableDdlPath`; the others are views) and\n    view DDL in `relations\/db_DATABASE\/schema_SCHEMA\/VIEW.sql` (or a single\n    `views.sql`).\n*   **Automated view deployment**: Translated views are deployed directly into\n    the target dataset with source references rewritten to the target BigQuery\n    project and dataset. Plain `CREATE VIEW` statements are deployed as\n    `CREATE OR REPLACE VIEW` so that reruns don't fail on existing views.\n*   **Flexible Parquet path resolution**: Under the `--parquet-base-uri`\n    (`BASE_URI`) flag, the loader automatically checks schema-scoped\n    subfolders (`BASE_URI\/SCHEMA\/TABLE\/*.parquet`) first if present and falls\n    back to flat table paths (`BASE_URI\/TABLE\/*.parquet`). For example,\n    `gcloud storage cp -r LOCAL_DIR\/SCHEMA gs:\/\/BUCKET\/data_unload\/` stages a\n    local schema folder of table subfolders under `data_unload\/SCHEMA\/`.\n*   **Single target dataset**: All discovered schemas load into one\n    `--dataset` by table or view name. If tables or views from different\n    source databases or schemas share a name, the loader stops before creating\n    the dataset and lists the conflicting objects; load each schema into its\n    own dataset instead.\n\n--------------------------------------------------------------------------------\n\n## 3. CLI execution interface (`bq load`)\n\n### Step 1: Provision the target dataset\n\nSet the shell variables for your environment, and then create the target\ndataset if it doesn't already exist:\n\n```bash\nPROJECT_ID=\"PROJECT_ID\"\nDATASET_ID=\"DATASET_ID\"\nLOCATION=\"LOCATION\"\nTABLE_NAME=\"TABLE_NAME\"\nBUCKET=\"BUCKET\"\nPREFIX=\"data_unload\"\n\nbq show --dataset --project_id=${PROJECT_ID} ${DATASET_ID} >\/dev\/null 2>&1 || \\\nbq mk --dataset --project_id=${PROJECT_ID} --location=${LOCATION} ${DATASET_ID}\n```\n\nReplace the following:\n\n*   `PROJECT_ID`: the target Google Cloud project ID.\n*   `DATASET_ID`: the target BigQuery dataset ID.\n*   `LOCATION`: the BigQuery location for the dataset and load jobs (for\n    example, `us-central1`).\n*   `TABLE_NAME`: the name of the table to load.\n*   `BUCKET`: the name of the Cloud Storage bucket that holds the staged\n    Parquet files.\n\n### Step 2: Ingest Parquet tables (auto-creates native table schema)\n\nPass `--decimal_target_types=NUMERIC --decimal_target_types=BIGNUMERIC\n--decimal_target_types=STRING` so BigQuery selects the smallest compatible type\n(`NUMERIC` \u2192 `BIGNUMERIC` \u2192 `STRING`) based on each Parquet `DECIMAL(p, s)`\ncolumn's precision and scale: columns with `p - s <= 29, s <= 9` map to\n`NUMERIC`, columns with `p - s <= 38, s <= 38` (such as `DECIMAL(38, 10)`) widen\nto `BIGNUMERIC`, and larger `DECIMAL256` precisions or scales fall back to\n`STRING`:\n\n```bash\nbq load \\\n    --project_id=${PROJECT_ID} \\\n    --location=${LOCATION} \\\n    --source_format=PARQUET \\\n    --replace=true \\\n    --decimal_target_types=NUMERIC \\\n    --decimal_target_types=BIGNUMERIC \\\n    --decimal_target_types=STRING \\\n    ${DATASET_ID}.${TABLE_NAME} \\\n    \"gs:\/\/${BUCKET}\/${PREFIX}\/${TABLE_NAME}\/*.parquet\"\n```\n\nThe `--replace=true` flag overwrites the destination table, including its\nschema, with the schema inferred from the Parquet files. If you pre-created\ntables from translated BQMS DDL statements to preserve target types such as\n`JSON`, `INTERVAL`, or `RANGE`, either run `TRUNCATE TABLE` and then load with\n`--replace=false` (so that reruns stay idempotent and don't duplicate rows), or\nkeep `--replace=true` and pass an explicit `--schema`. If you use the loader\ntemplate with native `JSON` columns, also set\n`_WRAP_JSON_QUERY_WITH_PARSE_JSON = False` in the copied script: by default it\nwraps `JSON_QUERY()` calls in `SAFE.PARSE_JSON()` for `JSON` source columns that\nParquet loads as `STRING`, which fails on native `JSON` columns.\n\nParquet `TIMESTAMP` columns always load as BigQuery `TIMESTAMP`, including\nnaive timestamps (`isAdjustedToUTC=false`, such as source `TIMESTAMP WITHOUT\nTIME ZONE` columns) that the translated DDL maps to `DATETIME`; the wall-clock\nvalues are kept and read as UTC. To restore `DATETIME` after loading, rewrite\nthose columns with `DATETIME(column)`, which converts at UTC by default:\n\n```sql\nCREATE OR REPLACE TABLE `PROJECT_ID.DATASET_ID.TABLE_NAME` AS\nSELECT * REPLACE (DATETIME(created_at) AS created_at)\nFROM `PROJECT_ID.DATASET_ID.TABLE_NAME`;\n```\n\n### Step 3: Run a row-count audit\n\nCount the rows in the loaded table so that you can compare the result with the\nsource table:\n\n```bash\nbq query \\\n    --project_id=${PROJECT_ID} \\\n    --location=${LOCATION} \\\n    --use_legacy_sql=false \\\n    \"SELECT '${TABLE_NAME}' AS table_name, count(*) AS row_count FROM \\`${PROJECT_ID}\\`.\\`${DATASET_ID}\\`.\\`${TABLE_NAME}\\`;\"\n```\n\n--------------------------------------------------------------------------------\n\n## 4. Automated loader asset template (`assets\/bq_loader_template.py`)\n\nThis skill provides an [automated BigQuery loader template][loader_template]\n(`assets\/bq_loader_template.py`) for dataset creation, concurrent Parquet\nloading, direct view deployment, and table row-count auditing.\n\n### Agent workflow: Copy, conditionally customize, and execute\n\n1.  **Copy the asset template**: Always instruct the user to copy the\n    [automated BigQuery loader template][loader_template]\n    (`assets\/bq_loader_template.py`) from this skill's directory (`SKILL_DIR`)\n    into their working directory (`.\/bq_loader.py`) by using the `cp`\n    command\u2014never write, synthesize, or inline a custom Python loader script\n    from scratch, and never paste or re-type the template contents into the\n    response. The template already handles quote-aware SQL splitting,\n    destination name collision checks, chunked row-count audits, and\n    multi-pass view retries, which a rewritten script would likely miss.\n    `SKILL_DIR` is the directory containing this `SKILL.md`:\n\n    ```bash\n    cp SKILL_DIR\/assets\/bq_loader_template.py .\/bq_loader.py\n    ```\n\n2.  **Conditionally customize extension points**: Run the copy as-is. Modify it\n    only if one of the following applies (prefer editing the marked `#\n    CUSTOMIZE:` sections; `# DEFAULT SCAFFOLDING` sections can be kept unchanged\n    unless deeper orchestration adjustments are needed):\n\n    *   **Schema overrides and partitioning (`# CUSTOMIZE: Schema Overrides &\n        Partitioning`)**: Add custom `bq load` flags (such as\n        `--time_partitioning_field`, `--clustering_fields`, or explicit schema\n        JSON files) inside `load_parquet_table()`.\n    *   **Custom view rewriting (`# CUSTOMIZE: Custom View Rewriting &\n        Deployment`)**: Adjust view SQL regular expressions, cross-project\n        dataset mapping rules, or retry bounds in `_rewrite_view_sql()` and\n        `deploy_views()`. Set `_WRAP_JSON_QUERY_WITH_PARSE_JSON = False` if you\n        pre-created tables with native `JSON` columns.\n    *   **Connection and CLI wrapper (`# CUSTOMIZE: Connection & CLI\n        Wrapper`)**:\n        Pass custom `bq` CLI flags (for example, `--default_kms_key` in\n        `ensure_dataset()`, or `--destination_kms_key` and `--reservation_id` in\n        `load_parquet_table()` and `execute_sql()`).\n    *   **Post-load auditing (`# CUSTOMIZE: Post-Load Auditing`)**: Extend\n        `audit_row_counts()` with custom data integrity or column-level checksum\n        queries.\n\n3.  **Execute the script in your working directory**: Run the copied script\n    against a Cloud Storage URI or a local translation output folder:\n\n    ```bash\n    # Direct from a Cloud Storage translation_output URI with concurrency:\n    python3 .\/bq_loader.py \\\n        --project \"PROJECT_ID\" \\\n        --dataset \"DATASET_ID\" \\\n        --location \"LOCATION\" \\\n        --translation-metadata-dir \"gs:\/\/BUCKET\/translation_output\/metadata\/\" \\\n        --parquet-base-uri \"gs:\/\/BUCKET\/data_unload\/\" \\\n        --concurrency 8\n\n    # Using local translation output folder:\n    python3 .\/bq_loader.py \\\n        --project \"PROJECT_ID\" \\\n        --dataset \"DATASET_ID\" \\\n        --location \"LOCATION\" \\\n        --translation-metadata-dir \"TRANSLATION_OUTPUT\/metadata\" \\\n        --parquet-base-uri \"gs:\/\/BUCKET\/data_unload\/\" \\\n        --concurrency 4\n    ```\n\n    When a view depends on another view, the first batch and first pass print\n    `bq` errors such as `Not found: Table ...` for the dependent view. These\n    errors are expected if the run ends with\n    `All N views successfully deployed across M passes.`\n\n### Arguments\n\n*   `--project` *(Required)*: Google Cloud project ID.\n*   `--dataset` *(Required)*: Target BigQuery dataset name.\n*   `--parquet-base-uri` *(Required)*: Base Cloud Storage URI containing table\n    Parquet subfolders (`gs:\/\/BUCKET\/path\/`).\n*   `--translation-metadata-dir` *(Required)*: Local folder or Cloud Storage URI\n    to translation output metadata directory. Auto-discovers tables and views.\n*   `--location` *(Optional, Default: `us-central1`)*: Target BigQuery location.\n*   `--concurrency` *(Optional, Default: `4`)*: Number of parallel workers for\n    concurrent `bq load` operations.\n\n[loader_template]: assets\/bq_loader_template.py\n","use_cases":["Provisioning BigQuery datasets for warehouse migrations","Batch loading staged Parquet files into native BigQuery tables","Auditing loaded table row counts","Deploying already-translated BigQuery views"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/bigquery-migration-data-loader\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T11:48:25.000000Z","updated_at":"2026-11-17T05:10:16.000000Z","seo_title":"BigQuery Data Loader for Migration","seo_description":"Load Parquet files into BigQuery tables and deploy translated views for data migration workflows.","seo_keywords":["BigQuery data loader","Parquet to BigQuery","BigQuery migration tool","Load Parquet files","Deploy BigQuery views"]}}