Skip to content

Commit

Permalink
Fix macro issues for trino (#2449)
Browse files Browse the repository at this point in the history
* Fix macro issues for trino

* add some docs

* format docs
  • Loading branch information
ravenac95 authored Nov 4, 2024
1 parent 298fd0a commit 8b2e7b3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion warehouse/metrics_tools/factory/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def metrics_start(evaluator: MacroEvaluator, _data_type: t.Optional[str] = None)
by taking the end_ds provided by sqlmesh and calculating a
trailing interval back {window} intervals of unit {unit}.
"""
if evaluator.runtime_stage in ["loading", "creating"]:
return parse_one("STR_TO_DATE('1970-01-01', '%Y-%m-%d')")
time_aggregation_interval = evaluator.locals.get("time_aggregation")
if time_aggregation_interval:
start_date = t.cast(
Expand Down Expand Up @@ -218,7 +220,9 @@ def metrics_start(evaluator: MacroEvaluator, _data_type: t.Optional[str] = None)
),
expression=exp.Interval(
this=exp.Paren(
this=exp.Literal(this=str(rolling_window), is_string=False),
# The interval parameter should be a string or some dialects
# have issues parsing
this=exp.Literal(this=str(rolling_window), is_string=True),
),
unit=exp.Var(this=rolling_unit.upper()),
),
Expand All @@ -229,6 +233,8 @@ def metrics_start(evaluator: MacroEvaluator, _data_type: t.Optional[str] = None)
def metrics_end(evaluator: MacroEvaluator, _data_type: t.Optional[str] = None):
"""This has different semantic meanings depending on the mode of the metric query"""

if evaluator.runtime_stage in ["loading", "creating"]:
return parse_one("STR_TO_DATE('1970-01-01', '%Y-%m-%d')")
time_aggregation_interval = evaluator.locals.get("time_aggregation")
if time_aggregation_interval:
to_interval = {
Expand Down

0 comments on commit 8b2e7b3

Please sign in to comment.