Skip to content

Commit

Permalink
Support Apache Kylin in EngineSpec (apache#4925)
Browse files Browse the repository at this point in the history
* Support Apache Kylin in EngineSpec

* Fix flake8
  • Loading branch information
zhaoyongjie authored and timifasubaa committed May 31, 2018
1 parent 8a8b4ec commit 964a5f3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,32 @@ class DruidEngineSpec(BaseEngineSpec):
inner_joins = False


class KylinEngineSpec(BaseEngineSpec):
"""Dialect for Apache Kylin"""

engine = 'kylin'

time_grains = (
Grain('Time Column', _('Time Column'), '{col}', None),
Grain('second', _('second'), 'SECOND({col})', 'PT1S'),
Grain('minute', _('minute'), 'MINUTE({col})', 'PT1M'),
Grain('hour', _('hour'), 'HOUR({col})', 'PT1H'),
Grain('month', _('month'), 'MONTH({col})', 'P1M'),
Grain('quarter', _('quarter'), 'QUARTER({col})', 'P0.25Y'),
Grain('year', _('year'), 'YEAR({col})', 'P1Y'),
)

@classmethod
def convert_dttm(cls, target_type, dttm):
tt = target_type.upper()
if tt == 'DATE':
return "CAST('{}' AS DATE)".format(dttm.isoformat()[:10])
if tt == 'TIMESTAMP':
return "CAST('{}' AS TIMESTAMP)".format(
dttm.strftime('%Y-%m-%d %H:%M:%S'))
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))


engines = {
o.engine: o for o in globals().values()
if inspect.isclass(o) and issubclass(o, BaseEngineSpec)}

0 comments on commit 964a5f3

Please sign in to comment.