Skip to content

Commit

Permalink
Backport: Add Column Header to the exported CSV from query command (#…
Browse files Browse the repository at this point in the history
…1354)

This commit is a backport of PR #1313 to dbt-metricflow 0.7.x

This will allow us to deploy @saurabh0402's fix for the following issue:

#1285

Note - efficacy was tested via the CLI by running hatch build and doing
a pip install
of the build package into a clean VM, and running `mf query` with the
`--csv` flag
enabled.

Co-authored-by: Saurabh Kumar <[email protected]>
  • Loading branch information
tlento and saurabh0402 authored Jul 27, 2024
1 parent 2b4b680 commit 67508a8
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 67508a8

Please sign in to comment.