From 8b2e7b3bfb1dc14c4b169396289bd57a1b2b1578 Mon Sep 17 00:00:00 2001 From: Reuven Gonzales Date: Mon, 4 Nov 2024 13:05:40 -0800 Subject: [PATCH] Fix macro issues for trino (#2449) * Fix macro issues for trino * add some docs * format docs --- warehouse/metrics_tools/factory/macros.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/warehouse/metrics_tools/factory/macros.py b/warehouse/metrics_tools/factory/macros.py index af8bd113f..69d5d6627 100644 --- a/warehouse/metrics_tools/factory/macros.py +++ b/warehouse/metrics_tools/factory/macros.py @@ -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( @@ -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()), ), @@ -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 = {