mirror of
https://github.com/apache/superset.git
synced 2026-06-05 15:49:27 +00:00
[BUGFIX]: Fixing dttm_sql_literal to use python_date_format when specified. (#3891)
This commit is contained in:
@@ -104,18 +104,19 @@ class TableColumn(Model, BaseColumn):
|
||||
If database_expression is not empty, the internal dttm
|
||||
will be parsed as the sql sentence for the database to convert
|
||||
"""
|
||||
|
||||
tf = self.python_date_format or '%Y-%m-%d %H:%M:%S.%f'
|
||||
tf = self.python_date_format
|
||||
if self.database_expression:
|
||||
return self.database_expression.format(dttm.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
elif tf == 'epoch_s':
|
||||
return str((dttm - datetime(1970, 1, 1)).total_seconds())
|
||||
elif tf == 'epoch_ms':
|
||||
return str((dttm - datetime(1970, 1, 1)).total_seconds() * 1000.0)
|
||||
elif tf:
|
||||
if tf == 'epoch_s':
|
||||
return str((dttm - datetime(1970, 1, 1)).total_seconds())
|
||||
elif tf == 'epoch_ms':
|
||||
return str((dttm - datetime(1970, 1, 1)).total_seconds() * 1000.0)
|
||||
return "'{}'".format(dttm.strftime(tf))
|
||||
else:
|
||||
s = self.table.database.db_engine_spec.convert_dttm(
|
||||
self.type or '', dttm)
|
||||
return s or "'{}'".format(dttm.strftime(tf))
|
||||
return s or "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S.%f'))
|
||||
|
||||
|
||||
class SqlMetric(Model, BaseMetric):
|
||||
|
||||
Reference in New Issue
Block a user