-
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
[SIP-15] Adding database level python-date-format #8474
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 |
---|---|---|
|
@@ -169,15 +169,19 @@ def get_time_filter( | |
col = self.get_sqla_col(label="__time") | ||
l = [] | ||
if start_dttm: | ||
l.append(col >= text(self.dttm_sql_literal(start_dttm))) | ||
l.append( | ||
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. If there is now configuration for inclusive/exclusive start points, should we have another 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. @willbarrett per SIP-15 the end state is The 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. OK, thanks for clarifying! |
||
col >= text(self.dttm_sql_literal(start_dttm, time_range_endpoints)) | ||
) | ||
if end_dttm: | ||
if ( | ||
time_range_endpoints | ||
and time_range_endpoints[1] == utils.TimeRangeEndpoint.EXCLUSIVE | ||
): | ||
l.append(col < text(self.dttm_sql_literal(end_dttm))) | ||
l.append( | ||
col < text(self.dttm_sql_literal(end_dttm, time_range_endpoints)) | ||
) | ||
else: | ||
l.append(col <= text(self.dttm_sql_literal(end_dttm))) | ||
l.append(col <= text(self.dttm_sql_literal(end_dttm, None))) | ||
return and_(*l) | ||
|
||
def get_timestamp_expression( | ||
|
@@ -218,7 +222,13 @@ def lookup_obj(lookup_column): | |
|
||
return import_datasource.import_simple_obj(db.session, i_column, lookup_obj) | ||
|
||
def dttm_sql_literal(self, dttm: DateTime) -> str: | ||
def dttm_sql_literal( | ||
self, | ||
dttm: DateTime, | ||
time_range_endpoints: Optional[ | ||
Tuple[utils.TimeRangeEndpoint, utils.TimeRangeEndpoint] | ||
], | ||
) -> str: | ||
"""Convert datetime object to a SQL expression string""" | ||
sql = ( | ||
self.table.database.db_engine_spec.convert_dttm(self.type, dttm) | ||
|
@@ -231,6 +241,18 @@ def dttm_sql_literal(self, dttm: DateTime) -> str: | |
|
||
tf = self.python_date_format | ||
|
||
# Fallback to the default format (if defined) only if the SIP-15 time range | ||
# endpoints, i.e., [start, end) are enabled. | ||
if not tf and time_range_endpoints == ( | ||
utils.TimeRangeEndpoint.INCLUSIVE, | ||
utils.TimeRangeEndpoint.EXCLUSIVE, | ||
): | ||
tf = ( | ||
self.table.database.get_extra() | ||
.get("python_date_format_by_column_name", {}) | ||
.get(self.column_name) | ||
) | ||
|
||
if tf: | ||
if tf in ["epoch_ms", "epoch_s"]: | ||
seconds_since_epoch = int(dttm.timestamp()) | ||
|
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.
Nit: it would be a convenience for the reader to add a link to the SIP issue on Github.
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.
@willbarrett there's a link to the GitHub issue on line #1307.
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.
Whup, I missed the context. Thanks!