Skip to content

refactor: expose macro evaluator in renderer #4729

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions sqlmesh/core/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def __init__(
self._cache: t.List[t.Optional[exp.Expression]] = []
self._model_fqn = model_fqn
self._optimize_query_flag = optimize_query is not False
# Cache of the macro evaluator to be able to reuse it outside the render method
self._macro_evaluator: t.Optional[MacroEvaluator] = None

@property
def macro_evaluator(self) -> t.Optional[MacroEvaluator]:
"""Returns the cached macro evaluator from the last render operation."""
return self._macro_evaluator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel like a robust way of doing this. Can we instead have a method that constructs the MacroEvaluator instance? And then call it externally AND in _render?


def update_schema(self, schema: t.Dict[str, t.Any]) -> None:
self.schema = d.normalize_mapping_schema(schema, dialect=self._dialect)
Expand Down Expand Up @@ -171,6 +178,7 @@ def _resolve_table(table: str | exp.Table) -> str:
environment_naming_info=environment_naming_info,
model_fqn=self._model_fqn,
)
self._macro_evaluator = macro_evaluator

start_time, end_time = (
make_inclusive(start or c.EPOCH, end or c.EPOCH, self._dialect)
Expand Down