Skip to content
Open
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
15 changes: 12 additions & 3 deletions sqlmesh/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def wrapper(self: SQLMeshMagics, *args: t.Any, **kwargs: t.Any) -> None:
return wrapper


def parse_expand(value: str) -> t.Union[bool, t.List[str]]:
if value.lower() == "true":
return True
if value.lower() == "false":
return False
return [name.strip() for name in value.split(",") if name.strip()]


def format_arguments(func: t.Callable) -> t.Callable:
"""Decorator to add common format arguments to magic commands."""
func = argument(
Expand Down Expand Up @@ -633,8 +641,8 @@ def evaluate(self, context: Context, line: str) -> None:
@argument("--execution-time", type=str, help="Execution time.")
@argument(
"--expand",
type=t.Union[bool, t.Iterable[str]],
help="Whether or not to use expand materialized models, defaults to False. If True, all referenced models are expanded as raw queries. If a list, only referenced models are expanded as raw queries.",
type=parse_expand,
help="Whether or not to use expand materialized models, defaults to False. If 'true', all referenced models are expanded as raw queries. If a comma-separated list of model names, only those models are expanded as raw queries.",
)
@argument("--dialect", type=str, help="SQL dialect to render.")
@argument("--no-format", action="store_true", help="Disable fancy formatting of the query.")
Expand All @@ -647,6 +655,7 @@ def render(self, context: Context, line: str) -> None:
render_opts = vars(parse_argstring(self.render, line))
model = render_opts.pop("model")
dialect = render_opts.pop("dialect", None)
expand = render_opts.pop("expand", False)

model = context.get_model(model, raise_if_missing=True)

Expand All @@ -655,7 +664,7 @@ def render(self, context: Context, line: str) -> None:
start=render_opts.pop("start", None),
end=render_opts.pop("end", None),
execution_time=render_opts.pop("execution_time", None),
expand=render_opts.pop("expand", False),
expand=expand,
)

no_format = render_opts.pop("no_format", False)
Expand Down