From 08bf43b92cc5b2f1baab9f77391a023d0d0e49d7 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 31 May 2024 10:48:32 -0700 Subject: [PATCH] Update CSV handling in the CLI to not use `pandas`. --- dbt-metricflow/dbt_metricflow/cli/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dbt-metricflow/dbt_metricflow/cli/main.py b/dbt-metricflow/dbt_metricflow/cli/main.py index 0308965e14..cf05ff9f28 100644 --- a/dbt-metricflow/dbt_metricflow/cli/main.py +++ b/dbt-metricflow/dbt_metricflow/cli/main.py @@ -1,5 +1,6 @@ from __future__ import annotations +import csv as csv_module import datetime as dt import logging import pathlib @@ -207,7 +208,7 @@ def tutorial(ctx: click.core.Context, cfg: CLIContext, msg: bool, clean: bool) - @query_options @click.option( "--csv", - type=click.File("wb"), + type=click.File("w"), required=False, help="Provide filepath for data_table output to csv", ) @@ -338,11 +339,12 @@ def query( click.echo("🕳 Successful MQL query returned an empty result set.") elif csv is not None: # csv is a LazyFile that is file-like that works in this case. - df.to_csv(csv, index=False) # type: ignore + csv_writer = csv_module.writer(csv) + for row in df.rows: + csv_writer.writerow(row) click.echo(f"🖨 Successfully written query output to {csv.name}") else: click.echo(df.text_format(decimals)) - if display_plans: temp_path = tempfile.mkdtemp() svg_path = display_dag_as_svg(query_result.dataflow_plan, temp_path)