Skip to content

Commit

Permalink
Add basic Impala engine spec (#3225)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Aug 4, 2017
1 parent 7190cf8 commit 166c576
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,31 @@ def convert_dttm(cls, target_type, dttm):
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))


class ImpalaEngineSpec(BaseEngineSpec):
"""Engine spec for Cloudera's Impala"""

engine = 'impala'

time_grains = (
Grain("Time Column", _('Time Column'), "{col}"),
Grain("minute", _('minute'), "TRUNC({col}, 'MI')"),
Grain("hour", _('hour'), "TRUNC({col}, 'HH')"),
Grain("day", _('day'), "TRUNC({col}, 'DD')"),
Grain("week", _('week'), "TRUNC({col}, 'WW')"),
Grain("month", _('month'), "TRUNC({col}, 'MONTH')"),
Grain("quarter", _('quarter'), "TRUNC({col}, 'Q')"),
Grain("year", _('year'), "TRUNC({col}, 'YYYY')"),
)

@classmethod
def convert_dttm(cls, target_type, dttm):
tt = target_type.upper()
if tt == 'DATE':
return "'{}'".format(dttm.strftime('%Y-%m-%d'))
else:
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 166c576

Please sign in to comment.