-
Notifications
You must be signed in to change notification settings - Fork 14k
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
feat: implement time grain in temporal filters #24035
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1288,12 +1288,22 @@ def get_time_filter( # pylint: disable=too-many-arguments | |
time_col: "TableColumn", | ||
start_dttm: Optional[sa.DateTime], | ||
end_dttm: Optional[sa.DateTime], | ||
time_grain: Optional[str] = None, | ||
label: Optional[str] = "__time", | ||
template_processor: Optional[BaseTemplateProcessor] = None, | ||
) -> ColumnElement: | ||
col = self.convert_tbl_column_to_sqla_col( | ||
time_col, label=label, template_processor=template_processor | ||
col = ( | ||
time_col.get_timestamp_expression( | ||
time_grain=time_grain, | ||
label=label, | ||
template_processor=template_processor, | ||
) | ||
if time_grain | ||
else self.convert_tbl_column_to_sqla_col( | ||
time_col, label=label, template_processor=template_processor | ||
) | ||
) | ||
|
||
l = [] | ||
if start_dttm: | ||
l.append( | ||
|
@@ -1353,6 +1363,7 @@ def get_timestamp_expression( | |
""" | ||
Return a SQLAlchemy Core element representation of self to be used in a query. | ||
|
||
:param column: column object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bycatch - missing docstring |
||
:param time_grain: Optional time grain, e.g. P1Y | ||
:param label: alias/label that column is expected to have | ||
:param template_processor: template processor | ||
|
@@ -1699,6 +1710,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma | |
continue | ||
flt_col = flt["col"] | ||
val = flt.get("val") | ||
flt_grain = flt.get("grain") | ||
op = flt["op"].upper() | ||
col_obj: Optional["TableColumn"] = None | ||
sqla_col: Optional[Column] = None | ||
|
@@ -1855,6 +1867,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma | |
time_col=col_obj, | ||
start_dttm=_since, | ||
end_dttm=_until, | ||
time_grain=flt_grain, | ||
label=sqla_col.key, | ||
template_processor=template_processor, | ||
) | ||
|
@@ -1945,7 +1958,6 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma | |
inner_groupby_exprs = [] | ||
inner_select_exprs = [] | ||
for gby_name, gby_obj in groupby_series_columns.items(): | ||
label = get_column_name(gby_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bycatch - this variable was not used anywhere (apparently this function is so bloated nowadays that the linters just give up on it) |
||
inner = self.make_sqla_column_compatible(gby_obj, gby_name + "__") | ||
inner_groupby_exprs.append(inner) | ||
inner_select_exprs.append(inner) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup - that split is no longer needed: