superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Add BigQuery engine specifications (#3193)
Date Thu, 27 Jul 2017 21:01:15 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new e584a96  Add BigQuery engine specifications (#3193)
e584a96 is described below

commit e584a9673f963a2dfd127114d8fe1a8e99fc731b
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Thu Jul 27 14:01:13 2017 -0700

    Add BigQuery engine specifications (#3193)
    
    As contributed by @mxmzdlv on issue #945
---
 superset/db_engine_specs.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index efe09a2..8481458 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -939,6 +939,34 @@ class ClickHouseEngineSpec(BaseEngineSpec):
                 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)}

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message