-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metrics By Project / Collection and different aggregations (#2125)
* Testing different factory * nasty work in progress * project aggregation working * Remove test file * collections working * Collections and joining views * rename rollup * clean up * getting the active days in there * updated current models * reenable downstream models * some fixes * fixes
- Loading branch information
Showing
39 changed files
with
2,110 additions
and
559 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from sqlmesh import macro | ||
from sqlmesh.core.macros import MacroEvaluator | ||
from sqlglot import expressions as exp | ||
|
||
|
||
@macro() | ||
def daily_bucket(evaluator: MacroEvaluator, timeExp: exp.Expression): | ||
if evaluator.dialect == "duckdb": | ||
return exp.Anonymous( | ||
this="TIME_BUCKET", | ||
expressions=[ | ||
exp.Interval( | ||
this=exp.Literal(this=1, is_string=True), | ||
unit=exp.Var(this="DAY"), | ||
), | ||
timeExp, | ||
], | ||
) | ||
return exp.Anonymous( | ||
this="toStartOfDay", | ||
expressions=[ | ||
timeExp, | ||
], | ||
) | ||
|
||
|
||
@macro() | ||
def weekly_bucket(evaluator: MacroEvaluator, timeExp: exp.Expression): | ||
if evaluator.dialect == "duckdb": | ||
return exp.Anonymous( | ||
this="TIME_BUCKET", | ||
expressions=[ | ||
exp.Interval( | ||
this=exp.Literal(this=1, is_string=True), | ||
unit=exp.Var(this="WEEK"), | ||
), | ||
timeExp, | ||
], | ||
) | ||
return exp.Anonymous( | ||
this="toStartOfWeek", | ||
expressions=[ | ||
timeExp, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from sqlmesh import macro | ||
from sqlmesh.core.macros import MacroEvaluator | ||
from sqlglot import expressions as exp | ||
|
||
|
||
@macro() | ||
def time_aggregation_bucket( | ||
evaluator: MacroEvaluator, timeExp: exp.Expression, rollup: str | ||
): | ||
from sqlmesh.core.dialect import parse_one | ||
|
||
if evaluator.runtime_stage in ["loading", "creating"]: | ||
return parse_one("STR_TO_DATE('1970-01-01', '%Y-%m-%d')") | ||
if evaluator.engine_adapter.dialect == "duckdb": | ||
rollup_to_interval = { | ||
"daily": "DAY", | ||
"weekly": "WEEK", | ||
"monthly": "MONTH", | ||
} | ||
return exp.Anonymous( | ||
this="TIME_BUCKET", | ||
expressions=[ | ||
exp.Interval( | ||
this=exp.Literal(this=1, is_string=False), | ||
unit=exp.Var(this=rollup_to_interval[rollup]), | ||
), | ||
exp.Cast( | ||
this=timeExp, | ||
to=exp.DataType(this=exp.DataType.Type.DATE, nested=False), | ||
), | ||
], | ||
) | ||
rollup_to_clickhouse_function = { | ||
"daily": "toStartOfDay", | ||
"weekly": "toStartOfWeek", | ||
"monthly": "toStartOfMonth", | ||
} | ||
return exp.Anonymous( | ||
this=rollup_to_clickhouse_function[rollup], | ||
expressions=[ | ||
timeExp, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.