Stop Writing Warehouse DDL by Hand: Extracting PostgreSQL, Snowflake, BigQuery & Polars Schemas Straight From Parquet, Avro & Feather

2026-11-24来源 dev.toEnglish

Stop Writing Warehouse DDL by Hand: Extracting PostgreSQL, Snowflake, BigQuery & Polars Schemas Straight From Parquet, Avro & Feather

Every data pipeline handoff seems to start the same way: someone sends you a .parquet, .avro, or .feather file and asks you to load it into Snowflake, PostgreSQL, BigQuery, or ClickHouse. So you open a notebook, print df.dtypes, and spend twenty minutes manually translating INT64, DECIMAL(10,2), TIMESTAMP_MICROS, and nested STRUCT fields into CREATE TABLE DDL—hoping you didn't miss a nullable column.

Before we look at how to skip manual DDL writing, here is a quick refresher on why those three binary formats show up in different parts of your stack:

Format Storage Layout Magic Bytes Best Fit
Apache Parquet (.parquet) Columnar (row groups + column chunks + Thrift footer) PAR1 Data lakes (S3/Iceberg/Delta), OLAP queries, long-term analytical storage
Apache Avro (.avro) Row-oriented (JSON schema header + binary blocks + sync markers) Obj\x01 Kafka event streams, write-heavy ingestion, strict schema evolution
Apache Feather / Arrow IPC (.feather) Columnar in-memory Arrow layout (FlatBuffers) FEA1 / ARROW1 Zero-copy fast interchange between Python (Polars/PyArrow), R, and ML notebooks

Why Type Mapping Trips Teams Up Across Warehouses

All three binary formats embed a real schema—unlike CSV, where every column is a guess. The annoying part is translating physical/logical types accurately across target engines:

  • A Parquet INT64 becomes BIGINT in PostgreSQL/ClickHouse, NUMBER(38,0) or BIGINT in Snowflake, INT64 in BigQuery, pl.Int64 in Polars, and bigint (not number!) in TypeScript.
  • A Parquet LIST or STRUCT maps to JSONB in Postgres, VARIANT in Snowflake, ARRAY<...> / STRUCT<...> in BigQuery, and nested interfaces in TypeScript.

Example generated Snowflake DDL straight from a Parquet schema (no guessing required):

CREATE TABLE IF NOT EXISTS ecommerce_orders_v2 ( order_id INTEGER NOT NULL, customer_snowflake_id BIGINT NOT NULL, customer_email VARCHAR, region VARCHAR, order_status VARCHAR, total_usd DOUBLE, is_prime_member BOOLEAN, created_at TIMESTAMP_NTZ, shipping_meta VARIANT, line_skus VARIANT ); 

Three Quick Checks Before Loading Any File Into a Warehouse

  1. Profile null rates and quantiles first: Check whether a column marked optional actually has 0% nulls or 40% nulls, and verify min/max/P50/P95 ranges before setting NOT NULL constraints.
  2. Check embedded key-value metadata: Parquet footers often tell you which writer created the file (parquet.writer.name, Spark version, or iceberg.table.name) and which compression codec was used.
  3. Sanitize CSV handoffs for Excel: If a stakeholder wants a filtered CSV export, enable a UTF-8 BOM (\uFEFF) for Windows Excel and CWE-1236 formula-injection guarding so cells starting with = or + don't execute as formulas.

Doing It Locally in One Pass (Zero Uploads, Zero Install)

If you already live in DuckDB CLI or Polars, DESCRIBE SELECT * FROM 'file.parquet' is super fast. When you want a visual grid, quantile profiler, Binary X-Ray footer inspector, and instant copy-paste DDL across 10 targets (PostgreSQL, Snowflake, BigQuery, DuckDB SQL, ClickHouse, TypeScript, PyArrow, Polars, Avro .avsc, and JSON Schema) without uploading sensitive local files to a server, KivaroTools' browser-local Parquet, Avro & Feather viewer parses files up to 250 MB / 5M rows inside a Web Worker (with 3 built-in sample datasets so you can test it immediately). You can also check the rest of the local-first KivaroTools developer suite.

Note on Limitations

Keep in mind that browser-native JS parsers typically support UNCOMPRESSED, SNAPPY, GZIP, and LZ4/LZ4_RAW—if your lakehouse writes ZSTD or BROTLI compressed Parquet files or needs full multi-table SQL joins, reach for DuckDB or PyArrow locally.

原文:https://www.a8q9.cn/en/article/stop-writing-warehouse-ddl-by-hand-extracting-postgresql-snowflake-bigquery-pola-60a063.html

相关文章