Sub-command implementations for sql-pipe introspection and validation modes: --columns, --validate, --sample, --schema, --stats/--profile.
| File | Mode | Responsibility |
|---|---|---|
columns.zig |
--columns |
List column names from first data row; --verbose adds inferred types |
validate.zig |
--validate |
Parse entire input, print summary: OK: N rows, M columns (col1 TYPE, col2 TYPE, ...) |
sample.zig |
--sample N |
Print schema block to stderr, then first N data rows to stdout |
schema.zig |
--schema |
Load input into temp SQLite table, print CREATE TABLE DDL |
stats.zig |
--stats/--profile |
Load input into temp SQLite, run per-column stats via generated SQL (count, min, max, mean), output as pretty table |
source.zig |
(shared helper) | Uniform file-or-stdin opening with SourceFile return type and needs_close cleanup |
- Shared helpers: All modes import
source.zigfor input opening,csv.zig/json.zig/xml.zigfor parsing,format.zigfor type dispatch - Same loading path:
columns.zig,schema.zig,stats.zig,validate.zigall useloader.loadCsvInput()orjson_mod.loadJsonArray()etc. — same code as the query path - Schema via SQLITE:
schema.zigloads data into SQLite then readssqlite_master.sql— avoids reimplementing DDL generation - Stats via SQL:
stats.ziggenerates a UNION ALL query over all columns with MIN/MAX/AVG — uses SQLite's built-in aggregation
main.zigdetects mode flag → callsrunColumns(),runValidate(), etc.- Mode function determines source (file or stdin) via
source.openInput() - Data parsed according to input format: CSV reader, JSON parse, NDJSON line reader, or XML parser
- Each mode extracts and prints its specific output (column names, row counts, DDL, stats table)
- Stats mode loads into temporary SQLite database with
sqlite_mod.openDb(false)(in-memory)
- Consumed by:
src/main.zig(mode dispatch via args) - Depends on:
src/csv.zig,src/json.zig,src/xml.zig(parsers),src/loader.zig(loading),src/sqlite.zig(DB bridge),src/format.zig(types) - No output format abstraction — these modes write directly rather than using
format.writeOutput()