Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add BigQuery engine specifications #3193

Merged
merged 1 commit into from
Jul 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,34 @@ def convert_dttm(cls, target_type, dttm):
dttm.strftime('%Y-%m-%d %H:%M:%S'))
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))


class BQEngineSpec(BaseEngineSpec):
"""Engine spec for Google's BigQuery

As contributed by @mxmzdlv on issue #945"""
engine = 'bigquery'

time_grains = (
Grain("Time Column", _('Time Column'), "{col}"),
Grain("second", _('second'), "TIMESTAMP_TRUNC({col}, SECOND)"),
Grain("minute", _('minute'), "TIMESTAMP_TRUNC({col}, MINUTE)"),
Grain("hour", _('hour'), "TIMESTAMP_TRUNC({col}, HOUR)"),
Grain("day", _('day'), "TIMESTAMP_TRUNC({col}, DAY)"),
Grain("week", _('week'), "TIMESTAMP_TRUNC({col}, WEEK)"),
Grain("month", _('month'), "TIMESTAMP_TRUNC({col}, MONTH)"),
Grain("quarter", _('quarter'), "TIMESTAMP_TRUNC({col}, QUARTER)"),
Grain("year", _('year'), "TIMESTAMP_TRUNC({col}, YEAR)"),
)

@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)}