mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
[presto] Smaller granularity units; fallback support for HⓂ️s (#731)
* [presto] Smaller granularity units; fallback support for HⓂ️s
* break lines >90
* cast to DATETIME instead
This commit is contained in:
parent
d11dd83c94
commit
2425b8f614
@ -404,13 +404,26 @@ class Database(Model, AuditMixinNullable):
|
|||||||
db_time_grains = {
|
db_time_grains = {
|
||||||
'presto': (
|
'presto': (
|
||||||
Grain('Time Column', _('Time Column'), '{col}'),
|
Grain('Time Column', _('Time Column'), '{col}'),
|
||||||
Grain('week', _('week'), "date_trunc('week', CAST({col} AS DATE))"),
|
Grain('second', _('second'),
|
||||||
Grain('month', _('month'), "date_trunc('month', CAST({col} AS DATE))"),
|
"date_trunc('second', CAST({col} AS TIMESTAMP))"),
|
||||||
Grain('quarter', _('quarter'), "date_trunc('quarter', CAST({col} AS DATE))"),
|
Grain('minute', _('minute'),
|
||||||
Grain("week_ending_saturday", _('week_ending_saturday'), "date_add('day', 5, "
|
"date_trunc('minute', CAST({col} AS TIMESTAMP))"),
|
||||||
"date_trunc('week', date_add('day', 1, CAST({col} AS DATE))))"),
|
Grain('hour', _('hour'),
|
||||||
Grain("week_start_sunday", _('week_start_sunday'), "date_add('day', -1, "
|
"date_trunc('hour', CAST({col} AS TIMESTAMP))"),
|
||||||
"date_trunc('week', date_add('day', 1, CAST({col} AS DATE))))")
|
Grain('day', _('day'),
|
||||||
|
"date_trunc('day', CAST({col} AS TIMESTAMP))"),
|
||||||
|
Grain('week', _('week'),
|
||||||
|
"date_trunc('week', CAST({col} AS TIMESTAMP))"),
|
||||||
|
Grain('month', _('month'),
|
||||||
|
"date_trunc('month', CAST({col} AS TIMESTAMP))"),
|
||||||
|
Grain('quarter', _('quarter'),
|
||||||
|
"date_trunc('quarter', CAST({col} AS TIMESTAMP))"),
|
||||||
|
Grain("week_ending_saturday", _('week_ending_saturday'),
|
||||||
|
"date_add('day', 5, date_trunc('week', date_add('day', 1, "
|
||||||
|
"CAST({col} AS TIMESTAMP))))"),
|
||||||
|
Grain("week_start_sunday", _('week_start_sunday'),
|
||||||
|
"date_add('day', -1, date_trunc('week', "
|
||||||
|
"date_add('day', 1, CAST({col} AS TIMESTAMP))))"),
|
||||||
),
|
),
|
||||||
'mysql': (
|
'mysql': (
|
||||||
Grain('Time Column', _('Time Column'), '{col}'),
|
Grain('Time Column', _('Time Column'), '{col}'),
|
||||||
@ -430,8 +443,10 @@ class Database(Model, AuditMixinNullable):
|
|||||||
'sqlite': (
|
'sqlite': (
|
||||||
Grain('Time Column', _('Time Column'), '{col}'),
|
Grain('Time Column', _('Time Column'), '{col}'),
|
||||||
Grain('day', _('day'), 'DATE({col})'),
|
Grain('day', _('day'), 'DATE({col})'),
|
||||||
Grain("week", _('week'), "DATE({col}, -strftime('%w', {col}) || ' days')"),
|
Grain("week", _('week'),
|
||||||
Grain("month", _('month'), "DATE({col}, -strftime('%d', {col}) || ' days')"),
|
"DATE({col}, -strftime('%w', {col}) || ' days')"),
|
||||||
|
Grain("month", _('month'),
|
||||||
|
"DATE({col}, -strftime('%d', {col}) || ' days')"),
|
||||||
),
|
),
|
||||||
'postgresql': (
|
'postgresql': (
|
||||||
Grain("Time Column", _('Time Column'), "{col}"),
|
Grain("Time Column", _('Time Column'), "{col}"),
|
||||||
@ -944,11 +959,11 @@ class TableColumn(Model, AuditMixinNullable):
|
|||||||
def dttm_sql_literal(self, dttm):
|
def dttm_sql_literal(self, dttm):
|
||||||
"""Convert datetime object to string
|
"""Convert datetime object to string
|
||||||
|
|
||||||
If datebase_expression is empty, the internal dttm
|
If database_expression is empty, the internal dttm
|
||||||
will be parsed as the string with the pattern that
|
will be parsed as the string with the pattern that
|
||||||
user input (python_date_format)
|
the user inputted (python_date_format)
|
||||||
If database_expression is not empty, the internal dttm
|
If database_expression is not empty, the internal dttm
|
||||||
will be parsed as the sql sentence for datebase to convert
|
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 or '%Y-%m-%d %H:%M:%S.%f'
|
||||||
if self.database_expression:
|
if self.database_expression:
|
||||||
|
Loading…
Reference in New Issue
Block a user