Skip to content

Commit

Permalink
Add Column Header to the exported CSV from query command (#1313)
Browse files Browse the repository at this point in the history
# Issue
#1285

The CSV exported from the `mf query <metric> --csv <csv-file-name>`
command does not contain the column header. The CSV thus does not make
too much sense.

# Fix
- The code
[here](https://github.com/dbt-labs/metricflow/blob/main/dbt-metricflow/dbt_metricflow/cli/main.py#L344)
is writing data to the CSV file. The column names aren't getting added
to the file.
- With this PR, we are adding the column names returned from
`df.column_names` to the CSV to fix the issue.
  • Loading branch information
saurabh0402 authored and tlento committed Jul 26, 2024
1 parent 2b4b680 commit eaa4f01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240716-090114.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Add Column header to the exported CSV from query command
time: 2024-07-16T09:01:14.102978+05:30
custom:
Author: saurabh0402
Issue: 1285,1313
1 change: 1 addition & 0 deletions dbt-metricflow/dbt_metricflow/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def query(
elif csv is not None:
# csv is a LazyFile that is file-like that works in this case.
csv_writer = csv_module.writer(csv)
csv_writer.writerow(df.column_names)
for row in df.rows:
csv_writer.writerow(row)
click.echo(f"🖨 Successfully written query output to {csv.name}")
Expand Down

0 comments on commit eaa4f01

Please sign in to comment.