Add CSV output format for SQL query results#4728
Conversation
Add a --format csv flag to the query command for exporting results as CSV. Uses Go's encoding/csv for proper escaping and quoting. Column headers are included as the first row. Co-authored-by: Isaac
…ests Co-authored-by: Isaac
shreyas-goenka
left a comment
There was a problem hiding this comment.
Note: This review was posted by Claude (AI assistant). Shreyas will do a separate, more thorough review pass.
Priority: MEDIUM — Dual-flag design concern
MEDIUM: --format vs --output dual-flag confusion
The PR introduces a --format flag for SQL statement execution that is separate from the existing --output flag used everywhere else in the CLI. This creates two different ways to control output format, which may confuse users. Consider whether --output csv could be extended to handle this case instead, or at minimum document the distinction clearly.
Other Observations
- CSV output implementation is clean and correct
- Good handling of SQL result pagination
- Proper escaping of CSV values with special characters
- Missing test for interaction between
--formatand--outputflags when both are set
The main thing to discuss is whether this warrants a new flag or should extend the existing --output flag.
|
Re: We intentionally use a separate Adding The PR already includes a mutual-exclusion guard that rejects using both flags together with a clear error message. |
Why
The SQL query command supports JSON and table output but not CSV. CSV is the most common format for data export and piping into tools like Excel, pandas, and database imports.
Changes
Before:
databricks sql queryonly supports JSON and table output formats.Now: A
--format csvflag writes results as RFC 4180 CSV with column headers as the first row.Uses Go's
encoding/csvpackage for proper escaping and quoting. The flag bypasses the normal output mode selection (text/json), so it works regardless of terminal interactivity.Test plan
make checkspasses