From 721b5d6a15395499201c6e09cefe411b384d5ade Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 10 Dec 2024 18:24:40 -0800 Subject: [PATCH] Move and rename `rendered_sql_without_descriptions`. --- dbt-metricflow/dbt_metricflow/cli/main.py | 2 +- metricflow/execution/execution_plan.py | 13 +++++++++++++ .../validation/data_warehouse_model_validator.py | 4 ++-- tests_metricflow/engine/test_explain.py | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dbt-metricflow/dbt_metricflow/cli/main.py b/dbt-metricflow/dbt_metricflow/cli/main.py index 7def5c146..7c248654b 100644 --- a/dbt-metricflow/dbt_metricflow/cli/main.py +++ b/dbt-metricflow/dbt_metricflow/cli/main.py @@ -298,7 +298,7 @@ def query( if explain: assert explain_result sql = ( - explain_result.rendered_sql_without_descriptions.sql + explain_result.sql_statement.without_descriptions.sql if not show_sql_descriptions else explain_result.sql_statement.sql ) diff --git a/metricflow/execution/execution_plan.py b/metricflow/execution/execution_plan.py index 63e59e69e..a29f956f2 100644 --- a/metricflow/execution/execution_plan.py +++ b/metricflow/execution/execution_plan.py @@ -51,6 +51,19 @@ class SqlStatement: sql: str bind_parameter_set: SqlBindParameterSet + @property + def without_descriptions(self) -> SqlStatement: + """Return the SQL query without the inline descriptions.""" + return SqlStatement( + sql="\n".join( + filter( + lambda line: not line.strip().startswith("--"), + self.sql.split("\n"), + ) + ), + bind_parameter_set=self.bind_parameter_set, + ) + @dataclass(frozen=True) class TaskExecutionError(Exception): diff --git a/metricflow/validation/data_warehouse_model_validator.py b/metricflow/validation/data_warehouse_model_validator.py index b1c69d1d9..95efadcb3 100644 --- a/metricflow/validation/data_warehouse_model_validator.py +++ b/metricflow/validation/data_warehouse_model_validator.py @@ -453,8 +453,8 @@ def _gen_explain_query_task_query_and_params( ) -> Tuple[str, SqlBindParameterSet]: explain_result: MetricFlowExplainResult = mf_engine.explain(mf_request=mf_request) return ( - explain_result.rendered_sql_without_descriptions.sql, - explain_result.rendered_sql_without_descriptions.bind_parameter_set, + explain_result.sql_statement.without_descriptions.sql, + explain_result.sql_statement.without_descriptions.bind_parameter_set, ) @classmethod diff --git a/tests_metricflow/engine/test_explain.py b/tests_metricflow/engine/test_explain.py index 339c7bb2d..92c581733 100644 --- a/tests_metricflow/engine/test_explain.py +++ b/tests_metricflow/engine/test_explain.py @@ -64,7 +64,7 @@ def test_optimization_level( sql_optimization_level=optimization_level, ) ) - results[optimization_level.value] = explain_result.rendered_sql_without_descriptions.sql + results[optimization_level.value] = explain_result.sql_statement.without_descriptions.sql assert_str_snapshot_equal( request=request,