Skip to content

Commit

Permalink
Rename indent_log_line() -> indent().
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Jan 5, 2024
1 parent 4d38041 commit 0ae5c69
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 78 deletions.
12 changes: 4 additions & 8 deletions metricflow/cli/dbt_connectors/adapter_backed_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dbt_semantic_interfaces.pretty_print import pformat_big_objects

from metricflow.errors.errors import SqlBindParametersNotSupportedError
from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.protocols.sql_client import SqlEngine
from metricflow.random_id import random_id
from metricflow.sql.render.big_query import BigQuerySqlQueryPlanRenderer
Expand Down Expand Up @@ -213,7 +213,7 @@ def dry_run(
start = time.time()
logger.info(
f"Running dry_run of:"
f"\n\n{indent_log_line(stmt)}\n"
f"\n\n{indent(stmt)}\n"
+ (f"\nwith parameters: {dict(sql_bind_parameters.param_dict)}" if sql_bind_parameters.param_dict else "")
)
request_id = SqlRequestId(f"mf_rid__{random_id()}")
Expand Down Expand Up @@ -266,14 +266,10 @@ def render_bind_parameter_key(self, bind_parameter_key: str) -> str:
@staticmethod
def _format_run_query_log_message(statement: str, sql_bind_parameters: SqlBindParameters) -> str:
"""Helper for creating nicely formatted query logging."""
message = f"Running query:\n\n{indent_log_line(statement)}"
message = f"Running query:\n\n{indent(statement)}"
if len(sql_bind_parameters.param_dict) > 0:
message += (
f"\n"
f"\n"
f"with parameters:\n"
f"\n"
f"{indent_log_line(pformat_big_objects(sql_bind_parameters.param_dict))}"
f"\n" f"\n" f"with parameters:\n" f"\n" f"{indent(pformat_big_objects(sql_bind_parameters.param_dict))}"
)
return message

Expand Down
4 changes: 2 additions & 2 deletions metricflow/engine/metricflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from metricflow.execution.execution_plan_to_text import execution_plan_to_text
from metricflow.execution.executor import SequentialPlanExecutor
from metricflow.filters.time_constraint import TimeRangeConstraint
from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow.model.semantics.linkable_element_properties import (
LinkableElementProperties,
Expand Down Expand Up @@ -372,7 +372,7 @@ def __init__(

@log_call(module_name=__name__, telemetry_reporter=_telemetry_reporter)
def query(self, mf_request: MetricFlowQueryRequest) -> MetricFlowQueryResult: # noqa: D
logger.info(f"Starting query request:\n" f"{indent_log_line(pformat_big_objects(mf_request))}")
logger.info(f"Starting query request:\n" f"{indent(pformat_big_objects(mf_request))}")
explain_result = self._create_execution_plan(mf_request)
execution_plan = explain_result.execution_plan

Expand Down
2 changes: 1 addition & 1 deletion metricflow/mf_logging/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import textwrap


def indent_log_line(message: str, indent_level: int = 1, indent_prefix: str = " ") -> str: # noqa: D
def indent(message: str, indent_level: int = 1, indent_prefix: str = " ") -> str: # noqa: D
return textwrap.indent(message, prefix=indent_prefix * indent_level)
12 changes: 5 additions & 7 deletions metricflow/mf_logging/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pydantic import BaseModel

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -101,7 +101,7 @@ def _handle_sequence_obj(self, list_like_obj: Union[list, tuple], remaining_line
item_block = ",\n".join(items_as_str) + ","
# Indent the item_block
if len(item_block) > 0:
lines.append(indent_log_line(item_block, indent_prefix=self._indent_prefix))
lines.append(indent(item_block, indent_prefix=self._indent_prefix))
lines.append(right_enclose_str)
return "\n".join(lines)

Expand Down Expand Up @@ -145,9 +145,7 @@ def _handle_indented_key_value_item( # type: ignore[misc]
result_items_without_limit.append(key_value_seperator)
result_items_without_limit.append(self._handle_any_obj(value, remaining_line_width=None))

result_without_limit = indent_log_line(
"".join(result_items_without_limit), indent_prefix=self._indent_prefix
)
result_without_limit = indent("".join(result_items_without_limit), indent_prefix=self._indent_prefix)
if remaining_line_width is None or len(result_without_limit) <= remaining_line_width:
return result_without_limit

Expand Down Expand Up @@ -223,7 +221,7 @@ def _handle_indented_key_value_item( # type: ignore[misc]
result_lines[-1] = result_lines[-1] + value_lines[0]
result_lines.extend(value_lines[1:])

return indent_log_line("\n".join(result_lines), indent_prefix=self._indent_prefix)
return indent("\n".join(result_lines), indent_prefix=self._indent_prefix)

def _handle_mapping_like_obj(
self,
Expand Down Expand Up @@ -434,7 +432,7 @@ def mf_pformat_many( # type: ignore
for key, value in obj_dict.items():
item_block_lines = (
f"{key}:",
indent_log_line(
indent(
mf_pformat(
obj=value,
max_line_length=max(0, max_line_length - len(indent_prefix)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dbt_semantic_interfaces.type_enums import MetricType
from typing_extensions import override

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.mf_logging.pretty_print import mf_pformat, mf_pformat_many
from metricflow.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow.model.semantics.linkable_element_properties import LinkableElementProperties
Expand Down Expand Up @@ -201,12 +201,12 @@ def visit_measure_node(self, node: MeasureGroupByItemSourceNode) -> PushDownResu

logger.debug(
f"For {node.ui_description}:\n"
+ indent_log_line(
+ indent(
"After applying patterns:\n"
+ indent_log_line(mf_pformat(patterns_to_apply))
+ indent(mf_pformat(patterns_to_apply))
+ "\n"
+ "to inputs, matches are:\n"
+ indent_log_line(mf_pformat(matching_specs))
+ indent(mf_pformat(matching_specs))
)
)

Expand Down Expand Up @@ -302,8 +302,7 @@ def visit_metric_node(self, node: MetricGroupByItemResolutionNode) -> PushDownRe
)
logger.info(f"Handling {node.ui_description}")
logger.debug(
"candidates from parents:\n"
+ indent_log_line(mf_pformat(merged_result_from_parents.candidate_set.specs))
"candidates from parents:\n" + indent(mf_pformat(merged_result_from_parents.candidate_set.specs))
)
if merged_result_from_parents.candidate_set.is_empty:
return merged_result_from_parents
Expand Down Expand Up @@ -337,12 +336,12 @@ def visit_metric_node(self, node: MetricGroupByItemResolutionNode) -> PushDownRe

logger.debug(
f"For {node.ui_description}:\n"
+ indent_log_line(
+ indent(
"After applying patterns:\n"
+ indent_log_line(mf_pformat(patterns_to_apply))
+ indent(mf_pformat(patterns_to_apply))
+ "\n"
+ "to inputs, outputs are:\n"
+ indent_log_line(mf_pformat(matched_specs))
+ indent(mf_pformat(matched_specs))
)
)

Expand Down Expand Up @@ -386,8 +385,7 @@ def visit_query_node(self, node: QueryGroupByItemResolutionNode) -> PushDownResu

logger.info(f"Handling {node.ui_description}")
logger.debug(
"candidates from parents:\n"
+ indent_log_line(mf_pformat(merged_result_from_parents.candidate_set.specs))
"candidates from parents:\n" + indent(mf_pformat(merged_result_from_parents.candidate_set.specs))
)

return merged_result_from_parents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing_extensions import override

from metricflow.collection_helpers.merger import Mergeable
from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.mf_logging.pretty_print import mf_pformat
from metricflow.query.group_by_item.filter_spec_resolution.filter_location import WhereFilterLocation
from metricflow.query.group_by_item.path_prefixable import PathPrefixable
Expand Down Expand Up @@ -69,9 +69,9 @@ def checked_resolved_spec(self, resolved_spec_lookup_key: ResolvedSpecLookUpKey)
raise RuntimeError(
f"Unable to find a resolved spec.\n\n"
f"Expected 1 resolution for:\n\n"
f"{indent_log_line(mf_pformat(resolved_spec_lookup_key))}\n\n"
f"{indent(mf_pformat(resolved_spec_lookup_key))}\n\n"
f"but did not find any. All resolutions are:\n\n"
f"{indent_log_line(mf_pformat(self.spec_resolutions))}"
f"{indent(mf_pformat(self.spec_resolutions))}"
)

# There may be multiple resolutions that match a given key because it's possible the same metric / filter is
Expand Down
8 changes: 4 additions & 4 deletions metricflow/query/group_by_item/group_by_item_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dbt_semantic_interfaces.references import TimeDimensionReference
from dbt_semantic_interfaces.type_enums import TimeGranularity

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.mf_logging.pretty_print import mf_pformat
from metricflow.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow.naming.object_builder_scheme import ObjectBuilderNamingScheme
Expand Down Expand Up @@ -94,9 +94,9 @@ def resolve_matching_item_for_querying(
)
logger.info(
f"Spec pattern:\n"
f"{indent_log_line(mf_pformat(spec_pattern))}\n"
f"{indent(mf_pformat(spec_pattern))}\n"
f"was resolved to:\n"
f"{indent_log_line(mf_pformat(push_down_result.candidate_set.specs))}"
f"{indent(mf_pformat(push_down_result.candidate_set.specs))}"
)
if push_down_result.candidate_set.num_candidates > 1:
return GroupByItemResolution(
Expand Down Expand Up @@ -210,6 +210,6 @@ def resolve_min_metric_time_grain(self) -> TimeGranularity:
raise RuntimeError(
f"The grain for {repr(METRIC_TIME_ELEMENT_NAME)} could not be resolved. Got spec "
f"{metric_time_grain_resolution.spec} and issues:\n\n"
f"{indent_log_line(mf_pformat(metric_time_grain_resolution.issue_set))}"
f"{indent(mf_pformat(metric_time_grain_resolution.issue_set))}"
)
return metric_time_spec_set.time_dimension_specs[0].time_granularity
4 changes: 2 additions & 2 deletions metricflow/query/group_by_item/resolution_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing_extensions import override

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.query.group_by_item.path_prefixable import PathPrefixable
from metricflow.query.group_by_item.resolution_dag.resolution_nodes.base_node import GroupByItemResolutionNode

Expand Down Expand Up @@ -36,7 +36,7 @@ def ui_description(self) -> str: # noqa: D

for i, description in enumerate(descriptions[1:]):
output += "\n"
output += indent_log_line("-> " + description, indent_level=i + 1)
output += indent("-> " + description, indent_level=i + 1)

return output

Expand Down
6 changes: 3 additions & 3 deletions metricflow/query/issues/filter_spec_resolver/invalid_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dbt_semantic_interfaces.protocols import WhereFilter
from typing_extensions import override

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath
from metricflow.query.issues.issues_base import (
MetricFlowQueryIssueType,
Expand Down Expand Up @@ -40,9 +40,9 @@ def from_parameters( # noqa: D
def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str:
return (
f"Error parsing where filter:\n\n"
f"{indent_log_line(repr(self.where_filter.where_sql_template))}\n\n"
f"{indent(repr(self.where_filter.where_sql_template))}\n\n"
f"Got exception:\n\n"
f"{indent_log_line(''.join(traceback.TracebackException.from_exception(self.parse_exception).format()))}"
f"{indent(''.join(traceback.TracebackException.from_exception(self.parse_exception).format()))}"
)

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing_extensions import override

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.mf_logging.pretty_print import mf_pformat
from metricflow.naming.object_builder_scheme import ObjectBuilderNamingScheme
from metricflow.query.group_by_item.candidate_push_down.group_by_item_candidate import GroupByItemCandidateSet
Expand Down Expand Up @@ -51,7 +51,7 @@ def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str:
candidates_str.append(str(spec))
return (
f"The given input is ambiguous and can't be resolved. The input could match:\n\n"
f"{indent_log_line(mf_pformat(candidates_str))}"
f"{indent(mf_pformat(candidates_str))}"
)

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing_extensions import override

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.mf_logging.pretty_print import mf_pformat
from metricflow.naming.object_builder_scheme import ObjectBuilderNamingScheme
from metricflow.query.group_by_item.candidate_push_down.group_by_item_candidate import GroupByItemCandidateSet
Expand Down Expand Up @@ -70,9 +70,9 @@ def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str:
]
return (
f"{last_path_item.ui_description} is built from:\n\n"
f"{indent_log_line(last_path_item_parent_descriptions)}.\n"
f"{indent(last_path_item_parent_descriptions)}.\n"
f"However, the given input does not match to a common item that is available to those parents:\n\n"
f"{indent_log_line(mf_pformat(parent_to_available_items, max_line_length=80))}\n\n"
f"{indent(mf_pformat(parent_to_available_items, max_line_length=80))}\n\n"
f"For time dimension inputs, please specify a time grain as ambiguous resolution only allows "
f"resolution when the parents have the same defined time gain."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from typing_extensions import override

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.mf_logging.pretty_print import mf_pformat
from metricflow.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath
from metricflow.query.issues.issues_base import (
Expand Down Expand Up @@ -45,7 +45,7 @@ def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str:
lines = [
f"The given input does not match any of the available group-by-items for\n"
f"{self.query_resolution_path.last_item.ui_description}. Common issues are:\n",
indent_log_line(
indent(
"* Incorrect names.\n"
"* No valid join paths exist from the measure to the group-by-item.\n"
" (fan-out join support is pending).\n"
Expand All @@ -55,7 +55,7 @@ def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str:
]

if len(self.suggestions) > 0:
lines.append(f"\nSuggestions:\n{indent_log_line(mf_pformat(list(self.suggestions), max_line_length=80))}")
lines.append(f"\nSuggestions:\n{indent(mf_pformat(list(self.suggestions), max_line_length=80))}")
return "\n".join(lines)

@override
Expand Down
4 changes: 2 additions & 2 deletions metricflow/query/issues/parsing/invalid_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing_extensions import override

from metricflow.mf_logging.formatting import indent_log_line
from metricflow.mf_logging.formatting import indent
from metricflow.mf_logging.pretty_print import mf_pformat
from metricflow.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath
from metricflow.query.issues.issues_base import (
Expand Down Expand Up @@ -38,7 +38,7 @@ def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str:
return (
f"The given input does not exactly match any known metrics.\n\n"
f"Suggestions:\n"
f"{indent_log_line(mf_pformat(list(self.metric_suggestions)))}"
f"{indent(mf_pformat(list(self.metric_suggestions)))}"
)

@override
Expand Down
Loading

0 comments on commit 0ae5c69

Please sign in to comment.