DETECT SCHEMA

Discovers and saves column schema for a registered table.

Category: catalogDeltaForge extension

Syntax

DETECT SCHEMA FOR [TABLE] <table> [WITH (MAX_ROWS = <n>, FILE_NAME = '<file>')]

Description

## Overview Discovers the column schema of a registered table and saves it to the control plane catalog. The detected columns are returned as a result set so the user can review them immediately. This command supports two code paths depending on the table type: 1. **Delta tables**: Schema is read directly from the Delta transaction log. No data scanning is required, and the operation completes quickly. 2. **External file tables** (CSV, JSON, Parquet, etc.): The format handler executes a probe query against the source files. The schema observer captures discovered columns and syncs them to the catalog. ## Behavior - For Delta tables, the command reads the latest schema from the Delta log at the table's storage location, then syncs the discovered columns to the catalog. - For external file tables, the command builds a probe query (e.g., SELECT * FROM table LIMIT n) and runs it through the format handler. The schema observer flushes discovered columns to the catalog. - MAX_ROWS controls how many rows the probe query scans. Scanning more rows can improve type inference when the source data has inconsistent types across rows. - FILE_NAME allows targeting a specific file within a multi-file external table, which is useful when different files may have different schemas. - The command requires both a valid catalog router connection and, for external tables, a registered format handler for the table's file type. - After execution, the catalog contains the full column list for the table, enabling autocomplete, lineage tracking, and governance. ## Compatibility DETECT SCHEMA is a DeltaForge extension. It provides catalog-level schema introspection for both managed Delta tables and external file sources.

Examples

-- Detect schema for a Delta table (reads from the Delta log directly)
DETECT SCHEMA FOR TABLE gold.analytics.daily_sales;
-- Detect schema for an external CSV table with default settings
DETECT SCHEMA FOR external.csv.sales_feed;
-- Scan more rows for better type inference on a JSON source
DETECT SCHEMA FOR TABLE bronze.landing.events WITH (MAX_ROWS = 500);
-- Target a specific file in a multi-file external table
DETECT SCHEMA FOR external.parquet.logs WITH (FILE_NAME = 'events_2024_01.parquet');
-- Omit the TABLE keyword for brevity
DETECT SCHEMA FOR silver.curated.customers;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →