Skip to content

Commit

Permalink
Move and rename rendered_sql_without_descriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Dec 12, 2024
1 parent f623a79 commit 721b5d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dbt-metricflow/dbt_metricflow/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
13 changes: 13 additions & 0 deletions metricflow/execution/execution_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions metricflow/validation/data_warehouse_model_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests_metricflow/engine/test_explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 721b5d6

Please sign in to comment.