Create a schema mapping with metadata translation
Metadata translation in the BigQuery Migration Service lets you generate
GoogleSQL data definition language (DDL) scripts and per-table schema
mapping files from a source metadata archive. When you pair your metadata
archive with *.config.yaml configuration YAML files, you define target
BigQuery names, data types, partitioning, and clustering once and
reuse that mapping across downstream migration tools.
Benefits of creating a schema mapping first
When data ingestion, SQL pipeline translation, and post-migration validation
configure target schemas separately, dataset names, column renames, and data
types can drift across tools. Mismatched join keys, truncated precision on
NUMBER or DECIMAL columns, or unintended VARIANT and timestamp mappings
often surface only after data moves to BigQuery.
Running metadata translation right after you extract source metadata compiles
your source catalog and *.config.yaml rules into shared GoogleSQL
DDL scripts and per-table YAML mappings before you transfer data. When you
update a *.config.yaml file and rerun metadata translation, the translator
operates on the extracted ZIP archive without reconnecting to your source
database. This workflow lets you inspect and refine target names, data types,
PARTITION BY, and CLUSTER BY clauses in minutes while keeping downstream
tools aligned.
Schema mapping workflow across migration tools
After you extract a source metadata ZIP archive, you run a translation job with
the metadata target type and optional *.config.yaml files. The job produces
GoogleSQL DDL scripts in metadata/relations/ and per-table schema
mapping files in metadata/config/ that keep your downstream migration tools
aligned on the same BigQuery schema.
The following table summarizes how downstream tools use your configuration rules and generated outputs, with links to each tool's documentation:
| Tool or stage | Input consumed | How the mapping is applied | Documentation |
|---|---|---|---|
| Target table and view creation | Generated DDL scripts in metadata/relations/ |
You run the translated CREATE TABLE and
CREATE VIEW scripts in BigQuery to
provision target schemas.
|
Run a query |
| SQL query and pipeline translation | The same *.config.yaml files |
The SQL translator rewrites table references, column names, and type casts in your queries so that they match your target tables. | Provide configuration files to a translation |
| BigQuery Data Transfer Service for Snowflake and Teradata |
A
metadata/config/DATABASE_NAME/SCHEMA_NAME/
directory
|
The transfer connector reads target table names, column names, data types, primary keys, partitioning, and clustering from each YAML file. | |
| Migration validation (Preview) |
Per-table schema mapping files in metadata/config/,
downloaded locally and passed to the --tables-yaml flag
|
The validation client maps source tables, renamed columns, and primary keys to their migrated BigQuery counterparts. |
Before you begin
Before you create a schema mapping, complete the following prerequisites:
- Enable the BigQuery Migration API. For more information, see Enable the BigQuery Migration API.
- Grant the required Identity and Access Management (IAM) roles for metadata translation and Cloud Storage.
- Extract a metadata ZIP archive from your source system by using the metadata extractor, and upload it to a Cloud Storage bucket. For more information, see Generate metadata for translation and assessment.
Required roles
To get the permissions that you need to create and monitor metadata translation jobs, ask your administrator to grant you the following IAM roles:
-
Submit metadata translation jobs:
MigrationWorkflow Editor (
roles/bigquerymigration.editor) on the project -
View and monitor metadata translation jobs:
MigrationWorkflow Viewer (
roles/bigquerymigration.viewer) on the project -
Read input archives and configuration files, and write translation outputs:
Storage Object Admin (
roles/storage.objectAdmin) on the source and destination Cloud Storage buckets
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to create and monitor metadata translation jobs. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create and monitor metadata translation jobs:
-
Submit and monitor metadata translation jobs:
-
bigquerymigration.workflows.createon the project -
bigquerymigration.workflows.geton the project -
bigquerymigration.workflows.liston the project -
bigquerymigration.workflows.deleteon the project -
bigquerymigration.subtasks.geton the project -
bigquerymigration.subtasks.liston the project
-
-
Read input archives and configuration files, and write translation outputs:
-
storage.objects.geton the source and destination Cloud Storage buckets -
storage.objects.liston the source and destination Cloud Storage buckets -
storage.objects.createon the destination Cloud Storage bucket
-
You might also be able to get these permissions with custom roles or other predefined roles.
Create a schema mapping
To generate target DDL scripts and per-table schema mapping files, do the following:
Create translation configuration files: create one or more
*.config.yamlfiles that define target BigQuery names, data types, partitioning, clustering, or session defaults. You can also run metadata translation with only a metadata ZIP archive. Without*.config.yamlrules, metadata translation keeps your source object names and applies default BigQuery type conversions. For more information, see Configure target schema rules in this document.Upload or reference your configuration files: upload your
*.config.yamlfiles to Cloud Storage alongside your metadata ZIP archive, or pass their Cloud Storage URIs when you submit the job. For more information, see Provide configuration files to a translation.Run a metadata translation job: submit a metadata translation job on your metadata ZIP archive and optional
*.config.yamlfiles. For more information, see Translate metadata or Create a batch translation.When your metadata archive format differs from your SQL workload dialect, select the source dialect for metadata translation that matches the archive format:
- For a Databricks metadata archive extracted from Unity Catalog or the
Databricks-managed
hive_metastorecatalog, specify thesparksqlsource dialect orSparkSQL2BigQuery_Translationtask type. For more information, see Extracted Databricks metadata archive. - For a self-managed Apache Hive Metastore archive, specify the
hiveqlsource dialect orHiveQL2BigQuery_Translationtask type for this metadata translation job, even when your downstream SQL queries use Apache Spark SQL, Apache Impala, or Trino and Presto. - For an Azure Synapse Analytics archive, specify the
sqlserversource dialect orSQLServer2BigQuery_Translationtask type.
- For a Databricks metadata archive extracted from Unity Catalog or the
Databricks-managed
Review the generated files: to inspect the translation outputs before you create tables or transfer data, do the following:
- Check
report/translation_report.csvfor translation errors or warnings. For more information, see Explore the translation output. - Locate your generated DDL scripts in
metadata/relations/and schema mapping files inmetadata/config/. For more information, see Output directory structure in this document. - Verify the
targetNameandtargetTypefields, partitioning, and clustering inside the generatedTABLE_NAME.yamlfiles. For more information, see Schema mapping file reference in this document. - If you update your
*.config.yamlrules and rerun metadata translation, specify a new empty Cloud Storage output directory to avoid mixing files from previous runs.
- Check
Use the schema mapping in downstream tools: pass the generated DDL scripts,
*.config.yamlfiles, or Cloud Storagemetadata/config/DATABASE_NAME/SCHEMA_NAME/paths to your table creation, SQL translation, data transfer, or custom automation workflows, or downloadmetadata/config/locally for migration validation.
Configure target schema rules
The translation engine scans input directories only for files ending in
.config.yaml, such as name-mapping.config.yaml. If you include a file with a
bare config.yaml filename, the translator discards it and logs a
ConfigurationError in report/translation_report.csv. Each configuration file
accepts one root YAML document with a single type header, because name
mappings, table layout or column type overrides, and session settings use
separate configuration schemas. To combine experimental_object_rewriter,
object_rewriter, and environment rules, pass multiple *.config.yaml files
in the same job. For more information, see Applying multiple YAML
configurations.
In object_rewriter files, specify unmapped source names for databases,
schemas, tables, and columns in match, partition, and clustering rules,
even when another *.config.yaml file renames those objects. The engine evaluates
object_rewriter selectors against the source catalog before output name
mapping runs, and then writes the mapped target column names to
metadata/config/.
The following table lists the *.config.yaml rule types that customize
generated DDL scripts and schema mapping files, with links to specific examples:
| Target schema change | Configuration header | Effect on generated outputs | Examples |
|---|---|---|---|
| Map database, schema, table, and column names or identifier case | type: experimental_object_rewriter |
Metadata translation updates table and column targetName
values and target DDL identifiers.
|
|
| Configure table partitioning and clustering | type: object_rewriter |
Metadata translation updates the
targetPartitioningColumns and
targetClusteringColumns fields and DDL
PARTITION BY and CLUSTER BY clauses.
|
|
| Override column or global data types |
type: object_rewriter or
type: experimental_object_rewriter
|
Metadata translation updates column targetType definitions
for specific columns with attribute[].type or across all
tables with global.typeConvert.
|
|
| Preserve numeric or string precision, or disable zero-scale integer conversion |
type: statement_rewriter or type: optimizer
|
Metadata translation retains source precision and
scale bounds or keeps zero-scale NUMERIC
columns from converting to INT64.
|
|
| Set table descriptions or external storage locations | type: object_rewriter |
Metadata translation updates the table description and
targetLocations fields and
CREATE EXTERNAL TABLE options in generated DDL.
|
|
Set a default database for two-part schema.table dialects
|
type: environment |
Metadata translation replaces default_database paths and
__DEFAULT_DATABASE__ prefixes for dialects such as
Teradata and Apache Hive.
|
Specifying default database and schema search path |
Example *.config.yaml files for a target schema
The following two *.config.yaml files customize a source
SALES_DB.PUBLIC.ORDERS table and produce an orders.yaml schema mapping file.
For more information, see Example schema mapping file in
this document.
The name-mapping.config.yaml file converts target identifiers to lowercase,
maps SALES_DB.PUBLIC to `my-project`.sales_dataset, and renames
CUST_ID to customer_id:
type: experimental_object_rewriter
global:
outputName:
all:
case: LOWERCASE
schema:
- match:
database: SALES_DB
schema: PUBLIC
outputName:
database: my-project
schema: sales_dataset
attribute:
- match: "SALES_DB.PUBLIC.ORDERS.CUST_ID"
outputName:
attribute: customer_id
The table-layout.config.yaml file matches the unmapped source table and column
names to set a table description, partition by ORDER_DATE, cluster by
CUST_ID, and map PAYLOAD from VARIANT to STRING:
type: object_rewriter
relation:
- match: "SALES_DB.PUBLIC.ORDERS"
description:
text: "Customer orders table"
partition:
simple:
set: [ORDER_DATE]
clustering:
set: [CUST_ID]
attribute:
- match: "SALES_DB.PUBLIC.ORDERS.PAYLOAD"
type:
target: VARCHAR
Output directory structure
For an output prefix
gs://BUCKET_NAME/OUTPUT_PREFIX/, metadata
translation writes files in the following layout:
gs://BUCKET_NAME/OUTPUT_PREFIX/
├── metadata/
│ ├── config/DATABASE_NAME/SCHEMA_NAME/RELATION_NAME.yaml
│ └── relations/db_DATABASE_NAME/schema_SCHEMA_NAME/RELATION_NAME.sql
└── report/
└── translation_report.csv
Replace the following:
- BUCKET_NAME: the name of your Cloud Storage output bucket.
- OUTPUT_PREFIX: the Cloud Storage path prefix for translation outputs.
- DATABASE_NAME: the sanitized source database name.
- SCHEMA_NAME: the sanitized source schema name.
- RELATION_NAME: the sanitized source table or view name.
Metadata translation writes one YAML file and one SQL file per source table or
view, indexed by source database, schema, and relation names rather than
mapped BigQuery target names. Indexing by source coordinates lets
downstream connectors look up a source table's mapping before resolving its
renamed BigQuery destination. For example, if you rename
SALES_DB.PUBLIC.ORDERS to `my-project`.sales_dataset.orders, metadata
translation still writes to metadata/config/sales_db/public/orders.yaml.
To produce valid Cloud Storage object paths, the translator converts
uppercase ASCII letters to lowercase, replaces characters outside
[a-z0-9._+,@-] with underscores, and trims and collapses underscores. In a
sanitized path, the translator writes ORDER$ITEMS to order_items.yaml,
whereas sourceName inside the YAML file preserves
SALES_DB.PUBLIC.ORDER$ITEMS. Configure custom
scripts to identify tables by reading sourceName rather than parsing
filenames.
For two-part schema.table dialects such as Teradata and
Hive, the source archive has no catalog level. As a
result, DATABASE_NAME in the path defaults to
default_database, and sourceName uses __DEFAULT_DATABASE__ unless you set
session.defaultDatabase in a type: environment configuration YAML file.
Schema mapping file reference
Each YAML file under metadata/config/ describes how a single source table or
view maps to BigQuery.
Example schema mapping file
Running metadata translation by using name-mapping.config.yaml and
table-layout.config.yaml from Example *.config.yaml files for a target
schema produces
metadata/config/sales_db/public/orders.yaml. The following example omits
internal staging fields and shows how identifiers, table layout lists, type
overrides, and nested column types fit together:
sourceName: "SALES_DB.PUBLIC.ORDERS"
targetName: "`my-project`.sales_dataset.orders"
targetPartitioningColumns:
- "order_date"
sourceClusteringColumns:
- "ORDER_DATE"
- "CUST_ID"
targetClusteringColumns:
- "customer_id"
sourcePrimaryKeyColumns:
- "ORDER_ID"
description: "Customer orders table"
ddlPath: "gs://my-bucket/translation_output/metadata/relations/db_sales_db/schema_public/orders.sql"
columns:
- sourceName: "ORDER_ID"
sourceType:
name: "NUMBER"
genericName: "NUMERIC"
precision: 38
scale: 0
targetName: "order_id"
targetType:
name: "INT64"
description: "Primary order identifier"
notNull: true
- sourceName: "CUST_ID"
sourceType:
name: "NUMBER"
genericName: "NUMERIC"
precision: 38
scale: 0
targetName: "customer_id"
targetType:
name: "INT64"
- sourceName: "ORDER_DATE"
sourceType:
name: "DATE"
genericName: "DATE"
targetName: "order_date"
targetType:
name: "DATE"
notNull: true
- sourceName: "TOTAL_AMOUNT"
sourceType:
name: "NUMBER"
genericName: "NUMERIC"
precision: 10
scale: 2
targetName: "total_amount"
targetType:
name: "NUMERIC"
precision: 31
scale: 2
- sourceName: "PAYLOAD"
sourceType:
name: "VARIANT"
genericName: "JSON"
targetName: "payload"
targetType:
name: "STRING"
- sourceName: "ORDER_TAGS"
sourceType:
name: "MAP(VARCHAR,VARCHAR)"
genericName: "Map"
targetName: "order_tags"
targetType:
name: "ARRAY"
elementType:
name: "STRUCT"
fields:
- name: "key"
type:
name: "STRING"
- name: "value"
type:
name: "STRING"
Notice how the sections of the file relate to each other:
- The
sourceNamevalueSALES_DB.PUBLIC.ORDERSis unquoted and matches the sanitizeddb_sales_db/schema_public/orders.sqlpath in theddlPathfield. In contrast, thetargetNamevalue encloses the hyphenated project IDmy-projectin backticks. - The
sourceClusteringColumnsandsourcePrimaryKeyColumnslists keep unmapped source column names such asCUST_IDandORDER_ID. By comparison, thetargetPartitioningColumnsandtargetClusteringColumnslists use the mapped target column namesorder_dateandcustomer_idfrom thecolumnslist. - Nullable columns such as
CUST_ID,TOTAL_AMOUNT,PAYLOAD, andORDER_TAGSomit thenotNullfield. ThePAYLOADcolumn reflects theVARCHARtype override fromtable-layout.config.yamlasSTRING. TheORDER_TAGScolumn converts from aMapsource type to anARRAYofSTRUCTvalues withkeyandvaluefields.
Table-level fields
The following table describes the top-level fields in each schema mapping file:
| Field | Type | Presence | Description |
|---|---|---|---|
sourceName |
string |
Always present |
This string specifies the unquoted three-part source identifier in the
format database.schema.relation.
|
targetName |
string |
Always present |
|
sourcePartitioningColumns |
List of string values |
Present when the source table has column-based partitioning | This list records the partitioning column names from the source metadata archive before renames apply. |
targetPartitioningColumns |
List of string values |
Present when the target table is partitioned on a column |
This list specifies the mapped BigQuery partitioning
column names after translation and partition rules apply.
When a source table has multiple partitioning columns, the translator
keeps one column in this list and moves the rest to the
targetClusteringColumns field.
|
sourceClusteringColumns |
List of string values |
Present when the source table is clustered | This list records the deduplicated clustering column names from the source metadata archive before renames apply. Supported sources include Snowflake clustering keys and Amazon Redshift sort keys. |
targetClusteringColumns |
List of string values |
Present when the target table is clustered |
This list specifies the mapped clustering column names in
BigQuery in priority order after translation and
clustering rules apply.
|
sourcePrimaryKeyColumns |
List of string values |
Present when a primary key is extracted | This list records the unmapped source column names of the primary key in constraint order. |
sourceLocations |
List of string values |
Present on external or lakehouse source tables | This list records the storage location URIs extracted from external or lake-backed source tables. |
targetLocations |
List of string values |
Present when storage location URIs exist after translation |
This list records the storage location URIs retained after translation
or set by an external location rule in a
configuration YAML file, including on managed lakehouse tables. To
check whether a table is external, inspect the SQL file at the
ddlPath URI for a CREATE EXTERNAL TABLE
statement.
|
description |
string |
Present when a nonempty table or view comment exists |
This string contains the comment from the source metadata archive or the
text set by a relation description rule in a
configuration YAML file.
|
ddlPath |
string |
Present when DDL is generated |
This string provides the Cloud Storage gs:// URI
of the corresponding CREATE TABLE or
CREATE VIEW SQL file under
metadata/relations/.
|
columns |
List of object values |
Always present | This list contains the ordered column mapping entries for the table or view. |
Column-level fields
Each entry in the columns list contains the following fields:
| Field | Type | Presence | Description |
|---|---|---|---|
sourceName |
string |
Always present | This string specifies the unquoted column name in the source table or view. |
sourceType |
object |
Always present |
|
targetName |
string |
Always present | This string specifies the mapped BigQuery column name after attribute name rules apply. Metadata translation encloses column names that contain reserved keywords or special characters in backticks. |
targetType |
object |
Always present |
|
description |
string |
Present when a nonempty column comment exists | This string contains the column comment extracted from the source metadata archive. |
notNull |
boolean |
Present only when true |
This boolean equals true when the column has a
NOT NULL constraint. Nullable columns omit this field.
|
Serialization and structural conventions
Schema mapping files follow these conventions:
- Metadata translation omits empty lists, null values, and
falsenullability flags from the YAML output, and files don't start with a---document marker. - Schema mapping files don't include a
tableTypefield. Views omit table-only layout, primary key, and location fields and include only thesourceName,targetName,ddlPath,columns, and optionaldescriptionfields. To distinguishCREATE TABLEfromCREATE VIEWstatements, check the SQL file at theddlPathURI. - Base table YAML files also include internal CSV-staging fields such as
externalTableName,externalTableDdlPath,dataViewName, anddataViewDdlPathalongsidemetadata/external_tables/andmetadata/data_view/directories. Downstream BigQuery Migration Service tools ignore those fields.
Limitations
Metadata translation and schema mapping files have the following limitations:
- Metadata translation is in Preview.
- Metadata translation generates
metadata/config/files only from supported metadata ZIP archives that the metadata extractor produces. Greenplum metadata archives and dialects without a metadata archive, such as IBM Db2 and SQLite, don't produce schema mapping files. Primary key andNOT NULLextraction coverage also varies by source platform. - Metadata translation generates per-table schema mapping files in
metadata/config/only for objects in the metadata ZIP archive. If you pass standalone DDL SQL files as translation inputs, the translator converts them into BigQuery DDL scripts undersql/and applies your*.config.yamlrules. However, standalone DDL inputs don't generate YAML schema mapping files.