Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in line-width control in DAG pretty printer #1318

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions metricflow-semantics/metricflow_semantics/dag/dag_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, max_width: int) -> None: # noqa: D107
def update_max_width_for_indented_section(self, indent_prefix: str) -> Iterator[None]:
"""Context manager used to wrap the code that prints an indented section."""
previous_max_width = self._current_max_width
self._current_max_width = max(0, self._current_max_width - len(indent_prefix))
self._current_max_width = max(1, self._current_max_width - len(indent_prefix))
yield None
self._current_max_width = previous_max_width

Expand Down Expand Up @@ -101,7 +101,7 @@ def _format_to_text(self, node: DagNode, inner_contents: Optional[str]) -> str:
displayed_property.value,
# The string representation of displayed_property.value will be wrapped with "<!-- ", " -->" so subtract
# the width of those.
max_line_length=max_width - len("<!-- ") - len(" -->"),
max_line_length=max(1, max_width - len("<!-- ") - len(" -->")),
indent_prefix=self._value_indent_prefix,
)

Expand Down
31 changes: 20 additions & 11 deletions tests_metricflow/mf_logging/test_dag_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,33 @@ def _run_mf_pformat() -> None:
<SqlQueryPlan>
<SqlSelectStatementNode>
<!-- description = -->
<!-- test -->
<!-- node_id = -->
<!-- ss_0 -->
<!-- col0 = -->
<!-- SqlSelectColumn(expr=SqlStringExpression(node_id=str_0 sql_expr='foo'), column_alias='bar') -->
<!-- 'test' -->
<!-- node_id = -->
<!-- NodeId( -->
<!-- id_str='ss_0', -->
<!-- ) -->
<!-- col0 = -->
<!-- SqlSelectColumn( -->
<!-- expr=SqlStringExpression(node_id=str_0 sql_expr='foo'), -->
<!-- column_alias='bar', -->
<!-- ) -->
<!-- from_source = -->
<!-- SqlTableFromClauseNode(node_id=tfc_0) -->
<!-- where = -->
<!-- None -->
<!-- distinct = -->
<!-- False -->
<SqlTableFromClauseNode>
<!-- description = -->
<!-- Read from schema.table -->
<!-- node_id = -->
<!-- tfc_0 -->
<!-- table_id = -->
<!-- schema.table -->
<!-- description = -->
<!-- ('Read ' -->
<!-- 'from ' -->
<!-- 'schema.table') -->
<!-- node_id = -->
<!-- NodeId( -->
<!-- id_str='tfc_0', -->
<!-- ) -->
<!-- table_id = -->
<!-- 'schema.table' -->
</SqlTableFromClauseNode>
</SqlSelectStatementNode>
</SqlQueryPlan>
Expand Down
Loading