Add more time grains (#5083)

* Add more time grains

* Use FLOOR

* Fix quotes for lint
This commit is contained in:
Beto Dealmeida 2018-05-29 12:43:48 -07:00 committed by Maxime Beauchemin
parent ae50845843
commit 6c3e469154
1 changed files with 15 additions and 0 deletions

View File

@ -490,6 +490,9 @@ class SqliteEngineSpec(BaseEngineSpec):
Grain('month', _('month'),
"DATE({col}, -strftime('%d', {col}) || ' days', '+1 day')",
'P1M'),
Grain('year', _('year'),
"DATETIME(STRFTIME('%Y-01-01T00:00:00', {col}))",
'P1Y'),
Grain('week_ending_saturday', _('week_ending_saturday'),
"DATE({col}, 'weekday 6')",
'P1W/1970-01-03T00:00:00Z'),
@ -1365,6 +1368,18 @@ class DruidEngineSpec(BaseEngineSpec):
engine = 'druid'
inner_joins = False
time_grains = (
Grain('Time Column', _('Time Column'), '{col}', None),
Grain('second', _('second'), 'FLOOR({col} TO SECOND)', 'PT1S'),
Grain('minute', _('minute'), 'FLOOR({col} TO MINUTE)', 'PT1M'),
Grain('hour', _('hour'), 'FLOOR({col} TO HOUR)', 'PT1H'),
Grain('day', _('day'), 'FLOOR({col} TO DAY)', 'P1D'),
Grain('week', _('week'), 'FLOOR({col} TO WEEK)', 'P1W'),
Grain('month', _('month'), 'FLOOR({col} TO MONTH)', 'P1M'),
Grain('quarter', _('quarter'), 'FLOOR({col} TO QUARTER)', 'P3M'),
Grain('year', _('year'), 'FLOOR({col} TO YEAR)', 'P1Y'),
)
class KylinEngineSpec(BaseEngineSpec):
"""Dialect for Apache Kylin"""