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: Support Apache Kylin in EngineSpec (#4925)
Date Thu, 03 May 2018 15:42:51 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 5d6e59a  Support Apache Kylin in EngineSpec (#4925)
5d6e59a is described below

commit 5d6e59aa8a09294ec66a1e4f52dfc30e8f3b7d46
Author: Yongjie Zhao <yongjie.zhao@gmail.com>
AuthorDate: Thu May 3 23:42:43 2018 +0800

    Support Apache Kylin in EngineSpec (#4925)
    
    * Support Apache Kylin in EngineSpec
    
    * Fix flake8
---
 superset/db_engine_specs.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index 5587ba9..9d2c65d 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -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)}

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message