bigquery-migration-data-exporter

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

BigQuery Migration Data Exporter

BigQuery 迁移数据导出器

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
.
此 skill 协调生成类型感知的数据导出 SQL 脚本(
.sql
文件),用于将源数据仓库(如 Snowflake、Databricks、Teradata、Oracle 和 PostgreSQL)导出为目标文件格式(如与 BigQuery 对齐的 Parquet 文件),并以
references/
目录中的 dialect 和格式规范
为指导。
此 skill 中的所有模板均为纯 SQL 生成器,完全不依赖 JDBC 或数据库连接器。
[!TIP] 直接指向 BigQuery Migration Service (BQMS) 的
translation_output/metadata
目录(本地路径或 Cloud Storage URI)。 它会根据
metadata/config/*.yaml
自动发现所有物理表和目标 BigQuery 逻辑类型。

Usage Attribution

使用归因说明

MUST READ: Before executing any
gcloud
, REST API, or MCP command, you MUST read and follow the instructions in Usage Attribution.
必须阅读:在执行任何
gcloud
、REST API 或 MCP 命令前, 必须阅读并遵循 使用归因说明中的说明。

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:
    bash
    gcloud config set project {project_id}
  2. 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
    ):
    bash
    gcloud services enable storage.googleapis.com
  3. 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.
  4. 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):
    bash
    pip install pyyaml==6.0.2
  5. 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).
  6. 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. Google Cloud CLI 与项目设置:从
    gs://
    Cloud Storage URI 读取转换输出或元数据归档时,请确保已安装 Google Cloud CLI,验证 Google Cloud 项目已绑定有效的 Cloud Billing 账户,并配置目标项目:
    bash
    gcloud config set project {project_id}
  2. 启用 API:从 Cloud Storage(
    gs://
    )读取元数据时,先征得用户同意,再启用 Cloud Storage API(
    storage.googleapis.com
    ):
    bash
    gcloud services enable storage.googleapis.com
  3. 身份验证与必需的身份和访问管理 (IAM) 角色: 使用
    gcloud auth login
    和
    gcloud auth application-default login
    进行身份验证(或设置
    GOOGLE_APPLICATION_CREDENTIALS
    以使用服务账户身份验证)。验证你的身份或服务账户对保存输入元数据的 Cloud Storage 桶拥有
    roles/storage.objectViewer
    (Storage Object Viewer)角色。在 Google Cloud 项目中创建暂存桶需要
    roles/storage.admin
    (Storage Admin)角色,删除暂存桶中的暂存文件需要
    roles/storage.objectAdmin
    (Storage Object Admin)角色。
  4. Python 环境:生成器模板要求 Python 3.9 或更高版本。安装 Python 包前须征得用户确认,然后在虚拟环境中安装 PyYAML(生成器模板不依赖任何 JDBC 或数据库连接器):
    bash
    pip install pyyaml==6.0.2
  5. 区域、成本与清理:创建新的 Cloud Storage 桶来暂存导出的 Parquet 文件(
    gcloud storage buckets create gs://{bucket} --location={region}
    )前,须征得用户确认。除非目标 BigQuery 数据集使用其他区域,否则默认使用
    us-central1
    (将桶与数据集部署在同一区域;参见 Google Cloud locations)。暂存大规模导出前,请查看 Google Cloud Pricing。完成 BigQuery 数据导入后,可使用
    gcloud storage rm -r gs://{bucket}/{export_prefix}
    删除临时暂存的 Parquet 前缀。 此删除操作不可恢复:仅在用户明确确认确切 URI 后执行,且切勿使用空的
    {export_prefix}
    (否则将删除桶中的所有对象)。
  6. Snowflake Storage Integration:要将 Snowflake 表直接卸载到私有 Cloud Storage 桶(
    --stage-path 'gcs://...'
    ),Snowflake 必须使用 [storage integration][snowflake_gcs_integration] 授予其服务账户访问桶的权限。询问用户该 integration 的名称,并通过
    --storage-integration
    标志传入;此标志会为每个生成的
    COPY INTO
    语句添加
    STORAGE_INTEGRATION
    子句。卸载到 Snowflake stage(例如
    @~/bqms_export/
    或指定的外部 stage)时不需要此标志。

1. Direct Consumption of Translation Output Metadata

1. 直接使用转换输出元数据

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.

bigquery-migration-data-exporter
使用原生 BigQuery Migration Service (BQMS) 元数据转换输出:
translation_output/metadata/config/<database>/<schema>/<table_name>.yaml
每个配置文件指定:
  1. sourceName
    :源表的完全限定名称。
  2. columns
    :源数据类型、精度、小数位和 BigQuery 目标类型。
  3. 表与视图的区别:既没有
    externalTableName
    也没有
    externalTableDdlPath
    的配置表示视图;该视图会重新创建为 SQL 视图,且不会导出。存在显式
    TableType
    字段时,Databricks 生成器也会遵循该字段。

2. Format-Guided Type-Safe Export Fundamentals

2. 格式驱动的类型安全导出基础

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):
    sql
    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';
  2. Semi-Structured / JSON (
    VARIANT
    ,
    OBJECT
    ,
    STRUCT
    ,
    MAP
    ,
    ARRAY
    ,
    JSON
    ,
    JSONB
    ,
    XMLTYPE
    ,
    XML
    ,
    UUID
    ,
    INET
    )
    :
    • Snowflake:
      TO_VARCHAR(col) AS col
      .
    • Databricks / Spark SQL:
      TO_JSON(col) AS col
      for
      MAP
      (and for
      STRUCT
      /
      ARRAY
      when targeting
      JSON
      or
      STRING
      ; native passthrough
      col
      when targeting
      RECORD
      /
      ARRAY
      );
      CAST(col AS STRING) AS col
      for
      VARIANT
      /
      JSON
      /
      INTERVAL
      .
    • Teradata:
      CAST(col AS CLOB) AS col
      .
    • Oracle:
      JSON_SERIALIZE(col RETURNING CLOB) AS col
      for 21c+ native
      JSON
      , and
      XMLSERIALIZE(CONTENT col AS CLOB) AS col
      for
      XMLTYPE
      .
    • PostgreSQL:
      CAST(col AS TEXT) AS col
      for
      JSON
      ,
      JSONB
      ,
      XML
      ,
      UUID
      ,
      INET
      ,
      CIDR
      ,
      MACADDR
      ,
      INTERVAL
      ,
      BIT
      , and
      ARRAY
      .
  3. Decimals, Numbers, Integers & Floats:
    • NUMBER(p, s)
      /
      DECIMAL(p, s)
      /
      NUMERIC(p, s)
      with
      s > 0
      →
      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).
    • Unbounded or unconstrained
      NUMBER
      /
      NUMBER(*)
      /
      NUMERIC
      /
      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
      .
    • TINYINT
      /
      BYTEINT
      /
      SMALLINT
      /
      INT
      /
      INTEGER
      /
      BIGINT
      /
      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.
    • Databricks / Snowflake
      FLOAT
      /
      REAL
      →
      CAST(col AS DOUBLE) AS col
      ; 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
      ).
  4. Temporal (
    DATE
    ,
    TIME
    ,
    TIMESTAMP
    ,
    TIMESTAMP_NTZ
    ,
    TIMESTAMP WITH TIME ZONE
    )
    :
    • Snowflake:
      CAST(col AS TIMESTAMP_NTZ(6)) AS col
      and
      CAST(CONVERT_TIMEZONE('UTC', col) AS TIMESTAMP_NTZ(6)) AS col
      .
    • Databricks / Spark SQL:
      CAST(col AS TIMESTAMP) AS col
      when targeting
      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]).
    • Teradata:
      CAST(col AS TIMESTAMP(6)) AS col
      ,
      CAST((col AT TIME ZONE 'GMT') AS TIMESTAMP(6)) AS col
      , and
      CAST((col AT TIME ZONE 'GMT') AS TIME(6)) AS col
      .
    • Oracle:
      CAST(col AS TIMESTAMP(6)) AS col
      for
      DATE
      and
      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).
    • PostgreSQL:
      CAST(col AS TIME(6)) AS col
      for
      TIME
      and
      TIMETZ
      ,
      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
      .
  5. 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.
  6. 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 consult the
references/
directory ([Snowflake Parquet mapping reference][snowflake_map], [Databricks and Spark SQL Parquet mapping reference][databricks_map], [Teradata Parquet mapping reference][teradata_map], [Oracle Parquet mapping reference][oracle_map], and [PostgreSQL Parquet mapping reference][postgres_map]) to verify type conversions, formatting options, and dialect-specific export syntax.

在 BigQuery 数据导入(
bq load
)期间,直接执行未经规范指导的
COPY INTO @stage FROM table
或
SELECT *
经常会因序列化器差异而失败,例如
VARIANT
JSON 编码、
CHAR(n)
定宽空格填充、无界 Teradata/Oracle/PostgreSQL
NUMBER
/
NUMERIC
小数位截断、PostgreSQL
MONEY
的区域设置货币格式、Oracle
DATE
的时间部分,或时间戳纳秒计数。
为确保不存在类型漂移并顺利导入 BigQuery,请依据
references/
目录中的目标格式和 dialect 规范
应用类型感知的投影。虽然 Parquet 是 BigQuery 批量数据导入的标准推荐格式,因为它采用列式压缩和严格类型,但导出结构会根据目标格式要求进行调整。
对于 Parquet 数据导出,核心规则总结如下;后续列出的映射参考文档包含各 dialect 的完整类型矩阵:
  1. 会话参数(Snowflake):
    sql
    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';
  2. 半结构化数据 / JSON(
    VARIANT
    、
    OBJECT
    、
    STRUCT
    、
    MAP
    、
    ARRAY
    、
    JSON
    、
    JSONB
    、
    XMLTYPE
    、
    XML
    、
    UUID
    、
    INET
    )
    :
    • Snowflake:
      TO_VARCHAR(col) AS col
      。
    • Databricks / Spark SQL:针对
      MAP
      使用
      TO_JSON(col) AS col
      ;当
      STRUCT
      /
      ARRAY
      的目标为
      JSON
      或
      STRING
      时也使用此方式;目标为
      RECORD
      /
      ARRAY
      时直接透传
      col
      ;针对
      VARIANT
      /
      JSON
      /
      INTERVAL
      使用
      CAST(col AS STRING) AS col
      。
    • Teradata:
      CAST(col AS CLOB) AS col
      。
    • Oracle:针对 21c+ 原生
      JSON
      使用
      JSON_SERIALIZE(col RETURNING CLOB) AS col
      ,针对
      XMLTYPE
      使用
      XMLSERIALIZE(CONTENT col AS CLOB) AS col
      。
    • PostgreSQL:针对
      JSON
      、
      JSONB
      、
      XML
      、
      UUID
      、
      INET
      、
      CIDR
      、
      MACADDR
      、
      INTERVAL
      、
      BIT
      和
      ARRAY
      使用
      CAST(col AS TEXT) AS col
      。
  3. Decimal、Numbers、Integers 与 Floats:
    • 精度为
      s > 0
      的
      NUMBER(p, s)
      /
      DECIMAL(p, s)
      /
      NUMERIC(p, s)
      →
      CAST(col AS DECIMAL(p, s)) AS col
      (Oracle 中为
      CAST(col AS NUMBER(p, s)) AS col
      ,PostgreSQL 中为
      CAST(col AS NUMERIC(p, s)) AS col
      )。
    • 无界或未限制精度的
      NUMBER
      /
      NUMBER(*)
      /
      NUMERIC
      /
      DECIMAL
      → Snowflake 和 Teradata 中为
      CAST(col AS DECIMAL(38, 9)) AS col
      ,Oracle 中为
      CAST(col AS NUMBER(38, 9)) AS col
      ,PostgreSQL 中为
      CAST(col AS NUMERIC(38, 9)) AS col
      (默认支持
      <= 29
      位整数和
      9
      位小数;在 Teradata、Oracle 和 PostgreSQL 中可使用
      --unbounded-number-scale
      覆盖小数位);PostgreSQL
      MONEY
      →
      CAST(col AS NUMERIC(38, 2)) AS col
      。
    • TINYINT
      /
      BYTEINT
      /
      SMALLINT
      /
      INT
      /
      INTEGER
      /
      BIGINT
      /
      SERIAL
      →
      CAST(col AS BIGINT) AS col
      。在 Oracle 中,
      SMALLINT
      →
      CAST(col AS NUMBER(19, 0)) AS col
      ,ANSI
      NUMBER(38)
      别名
      INT
      /
      INTEGER
      →
      CAST(col AS NUMBER(38, 0)) AS col
      。目标类型为
      INT64
      且小数位为 0 的 decimal 会投影为 64 位整数;映射参考文档列出了默认转换为 64 位整数的
      NUMBER(p, 0)
      /
      DECIMAL(p, 0)
      精度。
    • Databricks / Snowflake
      FLOAT
      /
      REAL
      →
      CAST(col AS DOUBLE) AS col
      ;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
      (扩展为 64 位 IEEE-754
      FLOAT64
      )。
  4. 时间类型(
    DATE
    、
    TIME
    、
    TIMESTAMP
    、
    TIMESTAMP_NTZ
    、
    TIMESTAMP WITH TIME ZONE
    )
    :
    • Snowflake:
      CAST(col AS TIMESTAMP_NTZ(6)) AS col
      和
      CAST(CONVERT_TIMEZONE('UTC', col) AS TIMESTAMP_NTZ(6)) AS col
      。
    • Databricks / Spark SQL:目标为
      TIMESTAMP
      时使用
      CAST(col AS TIMESTAMP) AS col
      ;目标为 BigQuery
      DATETIME
      时,不对
      TIMESTAMP_NTZ
      执行 cast。
      TIMESTAMP_NTZ
      与
      TIMESTAMP
      之间的转换会使用会话时区,因此在 UTC 会话中运行脚本(参见 [Databricks reference][databricks_map])。
    • Teradata:
      CAST(col AS TIMESTAMP(6)) AS col
      、
      CAST((col AT TIME ZONE 'GMT') AS TIMESTAMP(6)) AS col
      和
      CAST((col AT TIME ZONE 'GMT') AS TIME(6)) AS col
      。
    • Oracle:针对
      DATE
      和
      TIMESTAMP(p)
      使用
      CAST(col AS TIMESTAMP(6)) AS col
      (当
      DATE
      明确映射到 BigQuery
      DATE
      时使用
      TRUNC(col) AS col
      );针对
      TIMESTAMP WITH TIME ZONE
      使用
      CAST(SYS_EXTRACT_UTC(col) AS TIMESTAMP(6)) AS col
      ;针对
      TIMESTAMP WITH LOCAL TIME ZONE
      使用
      CAST(SYS_EXTRACT_UTC(CAST(col AS TIMESTAMP WITH TIME ZONE)) AS TIMESTAMP(6)) AS col
      ,以确保使用 UTC 而不受会话时区影响。
    • PostgreSQL:针对
      TIME
      和
      TIMETZ
      使用
      CAST(col AS TIME(6)) AS col
      ;针对
      TIMESTAMP [WITHOUT TIME ZONE]
      使用
      CAST(col AS TIMESTAMP(6) WITHOUT TIME ZONE) AS col
      ;针对
      TIMESTAMPTZ
      /
      TIMESTAMP WITH TIME ZONE
      使用
      CAST(col AS TIMESTAMP(6) WITH TIME ZONE) AS col
      。
  5. 定长字符填充(
    CHAR(n)
    /
    NCHAR(n)
    /
    BPCHAR
    /
    GRAPHIC(n)
    )
    :使用
    TRIM(TRAILING FROM col) AS col
    (Teradata)或
    RTRIM(col) AS col
    (Oracle 和 PostgreSQL),去除定长字段末尾的填充空格。
  6. 显式目标类型:BQMS 配置中的 BigQuery
    TargetType
    (例如 schema 覆盖为
    INT64
    、
    NUMERIC
    、
    DATE
    或
    TIMESTAMP
    )优先于上述源类型默认值,以确保 Parquet 列与 BigQuery DDL 匹配。模板无法转换的跨类型覆盖会保留默认投影:Oracle 和 Teradata 中的
    STRING
    、
    JSON
    和
    BYTES
    (文本列保持文本、二进制列保持 bytes、数值或 datetime 列保持原类型);Teradata 和 Oracle 中的
    BOOL
    ;Oracle 和 Databricks 中的
    TIME
    ;Oracle 中除
    DATE
    /
    TIMESTAMP
    之外的列映射到
    DATE
    ;以及 Databricks
    DECIMAL
    列映射到数值或
    STRING
    以外的目标类型。如果
    bq load
    报告类型不匹配,请编辑模板中的
    # CUSTOMIZE: Custom Type Projections
    hook。
[!IMPORTANT] 始终查阅
references/
目录
([Snowflake Parquet mapping reference][snowflake_map]、 [Databricks and Spark SQL Parquet mapping reference][databricks_map]、 [Teradata Parquet mapping reference][teradata_map]、 [Oracle Parquet mapping reference][oracle_map] 和 [PostgreSQL Parquet mapping reference][postgres_map]), 以验证类型转换、格式化选项和特定 dialect 的导出语法。

3. Asset Templates & Agent Workflow

3. 资产模板与 Agent 工作流

This skill provides pure-Python SQL generator asset templates in
assets/
(with no JDBC or warehouse driver dependencies):
  • [Snowflake export SQL generator template][snowflake_exporter_template] (
    assets/export_snowflake_tables_template.py
    )
  • [Databricks export SQL generator template][databricks_exporter_template] (
    assets/export_databricks_tables_template.py
    )
  • [Teradata export SQL generator template][teradata_exporter_template] (
    assets/export_teradata_tables_template.py
    )
  • [Oracle export SQL generator template][oracle_exporter_template] (
    assets/export_oracle_tables_template.py
    )
  • [PostgreSQL export SQL generator template][postgres_exporter_template] (
    assets/export_postgres_tables_template.py
    )
此 skill 在
assets/
中提供纯 Python SQL 生成器资产模板(不依赖任何 JDBC 或数据仓库驱动):
  • [Snowflake 导出 SQL 生成器模板][snowflake_exporter_template] (
    assets/export_snowflake_tables_template.py
    )
  • [Databricks 导出 SQL 生成器模板][databricks_exporter_template] (
    assets/export_databricks_tables_template.py
    )
  • [Teradata 导出 SQL 生成器模板][teradata_exporter_template] (
    assets/export_teradata_tables_template.py
    )
  • [Oracle 导出 SQL 生成器模板][oracle_exporter_template] (
    assets/export_oracle_tables_template.py
    )
  • [PostgreSQL 导出 SQL 生成器模板][postgres_exporter_template] (
    assets/export_postgres_tables_template.py
    )

Agent Workflow: Copy, Conditionally Customize, and Generate SQL

Agent 工作流:复制、按需定制并生成 SQL

  1. Copy the Asset Template: Copy
    assets/<template_name>_template.py
    from this skill's directory (
    <SKILL_DIR>
    ) into your working directory (copy the file; do not paste or re-type the template contents into the response).
    <SKILL_DIR>
    is the directory containing this
    SKILL.md
    :
    bash
    # For Snowflake:
    cp <SKILL_DIR>/assets/export_snowflake_tables_template.py ./export_snowflake_tables.py
    
    # For Databricks:
    cp <SKILL_DIR>/assets/export_databricks_tables_template.py ./export_databricks_tables.py
    
    # For Teradata:
    cp <SKILL_DIR>/assets/export_teradata_tables_template.py ./export_teradata_tables.py
    
    # For Oracle:
    cp <SKILL_DIR>/assets/export_oracle_tables_template.py ./export_oracle_tables.py
    
    # For PostgreSQL:
    cp <SKILL_DIR>/assets/export_postgres_tables_template.py ./export_postgres_tables.py
  2. Conditionally Customize Extension Points: Run the copy as-is. Modify it only if one of the following applies (prefer editing the marked
    # CUSTOMIZE:
    sections;
    # DEFAULT SCAFFOLDING
    sections can be kept unchanged unless deeper orchestration adjustments are needed):
    • Custom Type Projections (
      # CUSTOMIZE: Custom Type Projections
      )
      : Adjust
      format_column_cast()
      in
      export_snowflake_tables.py
      ,
      export_databricks_tables.py
      ,
      export_teradata_tables.py
      ,
      export_oracle_tables.py
      , or
      export_postgres_tables.py
      for non-standard data types, custom precision bounds, or special JSON/geography serialization formats.
    • Stage & Storage Configuration (
      # CUSTOMIZE: Stage & Storage Configuration
      )
      : Customize
      COPY INTO
      file format options (
      MAX_FILE_SIZE
      , compression codecs, or encryption flags) in
      _build_copy_into_query()
      or Spark SQL
      INSERT OVERWRITE DIRECTORY
      options in
      _build_insert_overwrite_query()
      . Pass Snowflake storage integration names with the
      --storage-integration
      flag instead of editing the template.
    • Table & Row Filtering (
      # CUSTOMIZE: Table & Row Filtering
      /
      # CUSTOMIZE: Row Filters
      )
      : Add custom
      WHERE
      clauses, partition predicates, or custom schema/table inclusion/exclusion filters in
      _filter_tables_to_export()
      ,
      _build_select_query()
      , or
      load_tables_from_metadata_path()
      .
  3. Generate the Export SQL Files: Run the copied script with
    python3
    (
    python3 ./export_snowflake_tables.py
    ,
    python3 ./export_databricks_tables.py
    ,
    python3 ./export_teradata_tables.py
    ,
    python3 ./export_oracle_tables.py
    , or
    python3 ./export_postgres_tables.py
    ) to output a unified
    .sql
    script (
    --output-sql
    ) and/or per-table
    *_export.sql
    scripts (
    --output-dir
    ).
  4. Check the Output: Confirm the script exited with status
    0
    , report any
    WARNING:
    lines from stderr (such as skipped duplicate tables), and check that the number of
    -- Unload Table:
    markers (or
    *_export.sql
    files) matches the tables you expect to export.

  1. 复制资产模板:将此 skill 目录(
    <SKILL_DIR>
    )中的
    assets/<template_name>_template.py
    复制到工作目录(复制文件;不要在回复中粘贴或重新输入模板内容)。
    <SKILL_DIR>
    是包含
    SKILL.md
    的目录:
    bash
    # For Snowflake:
    cp <SKILL_DIR>/assets/export_snowflake_tables_template.py ./export_snowflake_tables.py
    
    # For Databricks:
    cp <SKILL_DIR>/assets/export_databricks_tables_template.py ./export_databricks_tables.py
    
    # For Teradata:
    cp <SKILL_DIR>/assets/export_teradata_tables_template.py ./export_teradata_tables.py
    
    # For Oracle:
    cp <SKILL_DIR>/assets/export_oracle_tables_template.py ./export_oracle_tables.py
    
    # For PostgreSQL:
    cp <SKILL_DIR>/assets/export_postgres_tables_template.py ./export_postgres_tables.py
  2. 按需定制扩展点:原样运行复制后的脚本。仅在出现以下情况之一时修改;优先编辑标记为
    # CUSTOMIZE:
    的部分;除非需要更深入的编排调整,否则
    # DEFAULT SCAFFOLDING
    部分可以保持不变:
    • 自定义类型投影(
      # CUSTOMIZE: Custom Type Projections
      )
      : 针对非标准数据类型、自定义精度边界或特殊的 JSON/geography 序列化格式,调整
      export_snowflake_tables.py
      、
      export_databricks_tables.py
      、
      export_teradata_tables.py
      、
      export_oracle_tables.py
      或
      export_postgres_tables.py
      中的
      format_column_cast()
      。
    • Stage 与 Storage 配置(
      # CUSTOMIZE: Stage & Storage Configuration
      )
      :在
      _build_copy_into_query()
      中自定义
      COPY INTO
      文件格式选项(
      MAX_FILE_SIZE
      、压缩编解码器或加密标志),或在
      _build_insert_overwrite_query()
      中自定义 Spark SQL
      INSERT OVERWRITE DIRECTORY
      选项。通过
      --storage-integration
      标志传入 Snowflake storage integration 名称,不要直接编辑模板。
    • 表与行过滤(
      # CUSTOMIZE: Table & Row Filtering
      /
      # CUSTOMIZE: Row Filters
      )
      :在
      _filter_tables_to_export()
      、
      _build_select_query()
      或
      load_tables_from_metadata_path()
      中添加自定义
      WHERE
      子句、分区谓词或自定义 schema/table 包含与排除过滤器。
  3. 生成导出 SQL 文件:使用
    python3
    运行复制后的脚本(
    python3 ./export_snowflake_tables.py
    、
    python3 ./export_databricks_tables.py
    、
    python3 ./export_teradata_tables.py
    、
    python3 ./export_oracle_tables.py
    或
    python3 ./export_postgres_tables.py
    ),以输出统一的
    .sql
    脚本(
    --output-sql
    )和/或每张表对应的
    *_export.sql
    脚本(
    --output-dir
    )。
  4. 检查输出:确认脚本退出状态为
    0
    ,报告 stderr 中出现的任何
    WARNING:
    行(例如跳过了重复表),并检查
    -- Unload Table:
    标记(或
    *_export.sql
    文件)的数量是否与预期导出的表数量一致。

A. Snowflake Export SQL Generator (
./export_snowflake_tables.py
)

A. Snowflake 导出 SQL 生成器(
./export_snowflake_tables.py
)

1. Generate Unified Export SQL Script (
--output-sql
)

1. 生成统一导出 SQL 脚本(
--output-sql
)

Unloading directly to Cloud Storage (
gcs://
) requires a Snowflake storage integration (see Before you begin):
bash
python3 ./export_snowflake_tables.py \
    --translation-metadata-dir gs://my-bucket/translation_output/metadata/ \
    --stage-path 'gcs://my-bucket/data_unload/' \
    --storage-integration my_gcs_integration \
    --output-sql export_snowflake_to_parquet.sql
直接卸载到 Cloud Storage(
gcs://
)需要 Snowflake storage integration(参见开始前):
bash
python3 ./export_snowflake_tables.py \
    --translation-metadata-dir gs://my-bucket/translation_output/metadata/ \
    --stage-path 'gcs://my-bucket/data_unload/' \
    --storage-integration my_gcs_integration \
    --output-sql export_snowflake_to_parquet.sql

2. Generate Per-Table Export SQL Files (
--output-dir
)

2. 生成每张表的导出 SQL 文件(
--output-dir
)

bash
python3 ./export_snowflake_tables.py \
    --translation-metadata-dir ./translated_output/metadata \
    --stage-path '@~/bqms_export/' \
    --output-dir ./export_sql
When the tables span more than one Snowflake database (tables whose metadata omits the database count as
--default-database
), the generator prefixes each unload subpath,
-- Unload Table:
label, and per-table file name with the database (for example,
@~/bqms_export/<DB>/<SCHEMA>/<TABLE>/
) so that identically named
<SCHEMA>.<TABLE>
pairs don't overwrite each other.
Snowflake resolves unquoted identifiers to uppercase, so names that aren't uppercase are double-quoted to keep their exact case. Pass
--default-database
and
--default-schema
exactly as the catalog stores them (usually uppercase, such as
ANALYTICS
).
bash
python3 ./export_snowflake_tables.py \
    --translation-metadata-dir ./translated_output/metadata \
    --stage-path '@~/bqms_export/' \
    --output-dir ./export_sql
当表分布在多个 Snowflake 数据库中时(元数据未指定数据库的表使用
--default-database
),生成器会在每个卸载子路径、
-- Unload Table:
标签和单表文件名前加上数据库名称(例如
@~/bqms_export/<DB>/<SCHEMA>/<TABLE>/
),从而避免同名
<SCHEMA>.<TABLE>
组合相互覆盖。
Snowflake 会将未加引号的标识符解析为大写,因此非大写名称会使用双引号,以保留其精确大小写。请按目录中实际存储的形式传入
--default-database
和
--default-schema
(通常为大写,例如
ANALYTICS
)。

B. Databricks Export SQL Generator (
./export_databricks_tables.py
)

B. Databricks 导出 SQL 生成器(
./export_databricks_tables.py
)

Generates catalog-agnostic 2-part
<schema>.<table>
Spark SQL
INSERT OVERWRITE DIRECTORY ... USING PARQUET
(or standalone
SELECT
by using
--export-mode select
) scripts (
.sql
) with explicit type-safe projections for all discovered Delta / Spark tables. Leave
--catalog
unset so the generated
.sql
files work across both Unity Catalog and
hive_metastore
(activated by using
USE CATALOG
on the target Spark or Databricks session at execution time), or pass
--catalog <CATALOG>
for explicit 3-part table qualification.
--catalog
also exports only the tables of that catalog when the metadata names catalogs (3-part YAML
sourceName
values or the extractor
metadata.zip
); the generator exits with an error that lists the available catalogs when it matches none of them:
bash
python3 ./export_databricks_tables.py \
    --translation-metadata-dir ./translated_output/metadata \
    --stage-path '/tmp/databricks_export' \
    --output-sql export_databricks_to_parquet.sql \
    --output-dir ./export_sql
为所有发现的 Delta / Spark 表生成与 catalog 无关、使用两部分
<schema>.<table>
限定的 Spark SQL
INSERT OVERWRITE DIRECTORY ... USING PARQUET
(或通过
--export-mode select
生成独立的
SELECT
)脚本(
.sql
),并包含显式的类型安全投影。不要设置
--catalog
,这样生成的
.sql
文件便可在 Unity Catalog 和
hive_metastore
中使用(在目标 Spark 或 Databricks 会话执行时通过
USE CATALOG
激活);也可以传入
--catalog <CATALOG>
以显式使用三部分表名限定。当元数据名称包含 catalog(三部分 YAML
sourceName
值或提取器
metadata.zip
)时,
--catalog
还会仅导出该 catalog 下的表;如果未匹配到任何 catalog,生成器将退出并报错列出可用 catalog:
bash
python3 ./export_databricks_tables.py \
    --translation-metadata-dir ./translated_output/metadata \
    --stage-path '/tmp/databricks_export' \
    --output-sql export_databricks_to_parquet.sql \
    --output-dir ./export_sql

C. Teradata Export SQL Generator (
./export_teradata_tables.py
)

C. Teradata 导出 SQL 生成器(
./export_teradata_tables.py
)

Generates explicit-cast Teradata
SELECT
scripts (
.sql
) with
-- Unload Table: <DB>.<TABLE> -> Parquet
and
-- Required Columns:
markers consumed by downstream Python Parquet streaming scripts (for example, by using
teradatasql
and
pyarrow
). Use
--default-database <DB>
as a fallback qualifier when metadata omits
TableSchema
(defaults to
$TERADATA_DATABASE
),
--database <DB>
(repeatable) as an allow-list filter to export only specific databases (the generator exits with an error when it leaves no tables),
--unbounded-number-scale <S>
to adjust the fractional scale for unbounded
NUMBER
/
NUMBER(*)
columns (default
9
), and
--keep-char-padding
if fixed-width
CHAR(n)
trailing spaces must be preserved instead of trimmed:
bash
undefined
生成带显式 cast 的 Teradata
SELECT
脚本(
.sql
),其中包含
-- Unload Table: <DB>.<TABLE> -> Parquet
和
-- Required Columns:
标记,供下游 Python Parquet 流式脚本读取(例如使用
teradatasql
和
pyarrow
)。当元数据缺少
TableSchema
时,使用
--default-database <DB>
作为回退限定符(默认为
$TERADATA_DATABASE
);使用可重复传入的
--database <DB>
作为允许列表过滤器,仅导出指定数据库(如果过滤后没有表,生成器将退出并报错);使用
--unbounded-number-scale <S>
调整无界
NUMBER
/
NUMBER(*)
列的小数位(默认值为
9
);如果必须保留定宽
CHAR(n)
末尾的空格而不进行裁剪,则使用
--keep-char-padding
:
bash
undefined

1. Generate per-table Teradata export SQL files from BQMS translation output:

1. Generate per-table Teradata export SQL files from BQMS translation output:

python3 ./export_teradata_tables.py
--translation-metadata-dir ./translated_output/metadata
--default-database my_db
--output-dir ./export_sql
python3 ./export_teradata_tables.py
--translation-metadata-dir ./translated_output/metadata
--default-database my_db
--output-dir ./export_sql

2. Generate a unified export SQL script from a Teradata extractor metadata.zip:

2. Generate a unified export SQL script from a Teradata extractor metadata.zip:

python3 ./export_teradata_tables.py
--metadata-zip gs://my-bucket/teradata_metadata/dwh-migration-teradata-metadata.zip
--database my_db
--output-sql teradata_export.sql
undefined
python3 ./export_teradata_tables.py
--metadata-zip gs://my-bucket/teradata_metadata/dwh-migration-teradata-metadata.zip
--database my_db
--output-sql teradata_export.sql
undefined

D. Oracle Export SQL Generator (
./export_oracle_tables.py
)

D. Oracle 导出 SQL 生成器(
./export_oracle_tables.py
)

Generates explicit-cast Oracle
SELECT
scripts (
.sql
) with
-- Unload Table: <SCHEMA>.<TABLE> -> Parquet
and
-- Required Columns:
markers consumed by downstream Python Parquet streaming scripts (for example, by using
python-oracledb
and
pyarrow
). Use
--default-schema <SCHEMA>
as a fallback qualifier when metadata omits
TableSchema
(defaults to
$ORACLE_SCHEMA
),
--schema <SCHEMA>
(repeatable) as an allow-list filter to export only specific schemas,
--unbounded-number-scale <S>
to adjust the fractional scale for unconstrained
NUMBER
columns (default
9
), and
--keep-char-padding
if fixed-width
CHAR(n)
/
NCHAR(n)
trailing spaces must be preserved instead of trimmed. Identifiers that aren't uppercase are double-quoted to keep their exact case, so pass
--default-schema
exactly as the catalog stores it (usually uppercase, such as
HR
):
bash
undefined
生成带显式 cast 的 Oracle
SELECT
脚本(
.sql
),其中包含
-- Unload Table: <SCHEMA>.<TABLE> -> Parquet
和
-- Required Columns:
标记,供下游 Python Parquet 流式脚本读取(例如使用
python-oracledb
和
pyarrow
)。当元数据缺少
TableSchema
时,使用
--default-schema <SCHEMA>
作为回退限定符(默认为
$ORACLE_SCHEMA
);使用可重复传入的
--schema <SCHEMA>
作为允许列表过滤器,仅导出指定 schema;使用
--unbounded-number-scale <S>
调整未限制精度的
NUMBER
列的小数位(默认值为
9
);如果必须保留定宽
CHAR(n)
/
NCHAR(n)
末尾的空格而不进行裁剪,则使用
--keep-char-padding
。非大写标识符会使用双引号,以保留其精确大小写,因此请按目录中实际存储的形式传入
--default-schema
(通常为大写,例如
HR
):
bash
undefined

1. Generate per-table Oracle export SQL files from BQMS translation output:

1. Generate per-table Oracle export SQL files from BQMS translation output:

python3 ./export_oracle_tables.py
--translation-metadata-dir ./translated_output/metadata
--default-schema MY_SCHEMA
--output-dir ./export_sql
python3 ./export_oracle_tables.py
--translation-metadata-dir ./translated_output/metadata
--default-schema MY_SCHEMA
--output-dir ./export_sql

2. Generate a unified export SQL script from an Oracle extractor metadata.zip:

2. Generate a unified export SQL script from an Oracle extractor metadata.zip:

python3 ./export_oracle_tables.py
--metadata-zip gs://my-bucket/oracle_metadata/dwh-migration-oracle-metadata.zip
--schema MY_SCHEMA
--output-sql oracle_export.sql
undefined
python3 ./export_oracle_tables.py
--metadata-zip gs://my-bucket/oracle_metadata/dwh-migration-oracle-metadata.zip
--schema MY_SCHEMA
--output-sql oracle_export.sql
undefined

E. PostgreSQL Export SQL Generator (
./export_postgres_tables.py
)

E. PostgreSQL 导出 SQL 生成器(
./export_postgres_tables.py
)

Generates explicit-cast PostgreSQL
SELECT
scripts (
.sql
) with
-- Unload Table: <SCHEMA>.<TABLE> -> Parquet
and
-- Required Columns:
markers consumed by downstream Python Parquet streaming scripts (for example, by using
psycopg2
and
pyarrow
). Use
--default-schema <SCHEMA>
as a fallback qualifier when metadata omits
TableSchema
(defaults to
$PG_SCHEMA
),
--schema <SCHEMA>
(repeatable) as an allow-list filter to export only specific schemas,
--database <DB>
(repeatable) to keep only one database's tables when the metadata spans several PostgreSQL databases (the generator exits with an error when
--schema
/
--database
leave no tables),
--unbounded-number-scale <S>
to adjust the fractional scale for unconstrained
NUMERIC
columns (default
9
), and
--keep-char-padding
if fixed-width
CHAR(n)
/
BPCHAR
trailing spaces must be preserved instead of trimmed. Identifiers that aren't lowercase are double-quoted to keep their exact case, so pass
--default-schema
exactly as the catalog stores it (usually lowercase, such as
public
). BQMS YAML configs record PostgreSQL
NUMERIC
columns as a
NUMERIC(18, 0)
placeholder, so pass the extractor
--metadata-zip
together with
--translation-metadata-dir
(example 3) to restore exact
NUMERIC(p, s)
and
NOT NULL
details:
bash
undefined
生成带显式 cast 的 PostgreSQL
SELECT
脚本(
.sql
),其中包含
-- Unload Table: <SCHEMA>.<TABLE> -> Parquet
和
-- Required Columns:
标记,供下游 Python Parquet 流式脚本读取(例如使用
psycopg2
和
pyarrow
)。当元数据缺少
TableSchema
时,使用
--default-schema <SCHEMA>
作为回退限定符(默认为
$PG_SCHEMA
);使用可重复传入的
--schema <SCHEMA>
作为允许列表过滤器,仅导出指定 schema;使用可重复传入的
--database <DB>
,在元数据涵盖多个 PostgreSQL 数据库时仅保留一个数据库的表(如果
--schema
/
--database
过滤后没有表,生成器将退出并报错);使用
--unbounded-number-scale <S>
调整未限制精度的
NUMERIC
列的小数位(默认值为
9
);如果必须保留定宽
CHAR(n)
/
BPCHAR
末尾的空格而不进行裁剪,则使用
--keep-char-padding
。非小写标识符会使用双引号,以保留其精确大小写,因此请按目录中实际存储的形式传入
--default-schema
(通常为小写,例如
public
)。BQMS YAML 配置将 PostgreSQL
NUMERIC
列记录为
NUMERIC(18, 0)
占位符,因此请将提取器的
--metadata-zip
与
--translation-metadata-dir
一同传入(参见示例 3),以恢复准确的
NUMERIC(p, s)
和
NOT NULL
详情:
bash
undefined

1. Generate per-table PostgreSQL export SQL files from BQMS translation output:

1. Generate per-table PostgreSQL export SQL files from BQMS translation output:

python3 ./export_postgres_tables.py
--translation-metadata-dir ./translated_output/metadata
--default-schema public
--output-dir ./export_sql
python3 ./export_postgres_tables.py
--translation-metadata-dir ./translated_output/metadata
--default-schema public
--output-dir ./export_sql

2. Generate a unified export SQL script from a PostgreSQL extractor metadata.zip:

2. Generate a unified export SQL script from a PostgreSQL extractor metadata.zip:

python3 ./export_postgres_tables.py
--metadata-zip gs://my-bucket/postgres_metadata/postgresql-metadata.zip
--schema public
--output-sql postgres_export.sql
python3 ./export_postgres_tables.py
--metadata-zip gs://my-bucket/postgres_metadata/postgresql-metadata.zip
--schema public
--output-sql postgres_export.sql

3. Combine BQMS translation output with the extractor metadata.zip:

3. Combine BQMS translation output with the extractor metadata.zip:

python3 ./export_postgres_tables.py
--translation-metadata-dir ./translated_output/metadata
--metadata-zip gs://my-bucket/postgres_metadata/postgresql-metadata.zip
--default-schema public
--output-dir ./export_sql

--------------------------------------------------------------------------------
python3 ./export_postgres_tables.py
--translation-metadata-dir ./translated_output/metadata
--metadata-zip gs://my-bucket/postgres_metadata/postgresql-metadata.zip
--default-schema public
--output-dir ./export_sql

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

4. Generated SQL Pattern

4. 生成的 SQL 模式

Snowflake COPY INTO Pattern

Snowflake COPY INTO 模式

sql
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';

COPY INTO 'gcs://my-bucket/data_unload/RAW_POS/MENU/'
FROM (
    SELECT
      CAST(MENU_ID AS BIGINT) AS MENU_ID,
      CAST(COST_OF_GOODS_USD AS DECIMAL(38, 4)) AS COST_OF_GOODS_USD,
      TO_VARCHAR(MENU_ITEM_HEALTH_METRICS_OBJ) AS MENU_ITEM_HEALTH_METRICS_OBJ
    FROM MY_DB.RAW_POS.MENU
  )
  STORAGE_INTEGRATION = my_gcs_integration
FILE_FORMAT = (
  TYPE = PARQUET
  COMPRESSION = SNAPPY
)
HEADER = TRUE
OVERWRITE = TRUE
MAX_FILE_SIZE = 104857600;
sql
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';

COPY INTO 'gcs://my-bucket/data_unload/RAW_POS/MENU/'
FROM (
    SELECT
      CAST(MENU_ID AS BIGINT) AS MENU_ID,
      CAST(COST_OF_GOODS_USD AS DECIMAL(38, 4)) AS COST_OF_GOODS_USD,
      TO_VARCHAR(MENU_ITEM_HEALTH_METRICS_OBJ) AS MENU_ITEM_HEALTH_METRICS_OBJ
    FROM MY_DB.RAW_POS.MENU
  )
  STORAGE_INTEGRATION = my_gcs_integration
FILE_FORMAT = (
  TYPE = PARQUET
  COMPRESSION = SNAPPY
)
HEADER = TRUE
OVERWRITE = TRUE
MAX_FILE_SIZE = 104857600;

Databricks, Teradata, Oracle, and PostgreSQL Patterns

Databricks、Teradata、Oracle 和 PostgreSQL 模式

Section 4 of the Databricks, Teradata, Oracle, and PostgreSQL mapping references shows the complete generated script: Spark SQL
INSERT OVERWRITE DIRECTORY ... USING PARQUET SELECT ...
for Databricks, and explicit-cast
SELECT ...
statements (
LOCKING ROW FOR ACCESS SELECT ...
in Teradata) with
-- Unload Table:
and
-- Required Columns:
markers for the others.
Databricks、Teradata、Oracle 和 PostgreSQL 映射参考文档的第 4 节展示了完整的生成脚本:Databricks 使用 Spark SQL
INSERT OVERWRITE DIRECTORY ... USING PARQUET SELECT ...
,其他数据库使用带显式 cast 的
SELECT ...
语句(Teradata 中为
LOCKING ROW FOR ACCESS SELECT ...
),并带有
-- Unload Table:
和
-- Required Columns:
标记。