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 5bac723  Refactor teradata to new time_grain_functions spec (#6539)
5bac723 is described below

commit 5bac723df42070e3e07cfe2230fa572b96c7b53e
Author: Ville Brofeldt <33317356+ville...@users.noreply.github.com>
AuthorDate: Sun Dec 16 18:53:29 2018 +0200

    Refactor teradata to new time_grain_functions spec (#6539)
    
    * Refactor teradata to new time_grain_functions spec
    
    * Add test for time_grain_functions
---
 superset/db_engine_specs.py   | 20 ++++++++++----------
 tests/db_engine_specs_test.py |  5 ++++-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index edbd1b2..97b6439 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -1541,16 +1541,16 @@ class TeradataEngineSpec(BaseEngineSpec):
     engine = 'teradata'
     limit_method = LimitMethod.WRAP_SQL
 
-    time_grains = (
-        Grain('Time Column', _('Time Column'), '{col}', None),
-        Grain('minute', _('minute'), "TRUNC(CAST({col} as DATE), 'MI')", 
'PT1M'),
-        Grain('hour', _('hour'), "TRUNC(CAST({col} as DATE), 'HH')", 'PT1H'),
-        Grain('day', _('day'), "TRUNC(CAST({col} as DATE), 'DDD')", 'P1D'),
-        Grain('week', _('week'), "TRUNC(CAST({col} as DATE), 'WW')", 'P1W'),
-        Grain('month', _('month'), "TRUNC(CAST({col} as DATE), 'MONTH')", 
'P1M'),
-        Grain('quarter', _('quarter'), "TRUNC(CAST({col} as DATE), 'Q')", 
'P0.25Y'),
-        Grain('year', _('year'), "TRUNC(CAST({col} as DATE), 'YEAR')", 'P1Y'),
-    )
+    time_grain_functions = {
+        None: '{col}',
+        'PT1M': "TRUNC(CAST({col} as DATE), 'MI')",
+        'PT1H': "TRUNC(CAST({col} as DATE), 'HH')",
+        'P1D': "TRUNC(CAST({col} as DATE), 'DDD')",
+        'P1W': "TRUNC(CAST({col} as DATE), 'WW')",
+        'P1M': "TRUNC(CAST({col} as DATE), 'MONTH')",
+        'P0.25Y': "TRUNC(CAST({col} as DATE), 'Q')",
+        'P1Y': "TRUNC(CAST({col} as DATE), 'YEAR')",
+    }
 
 
 engines = {
diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py
index bdee22a..cc2ae70 100644
--- a/tests/db_engine_specs_test.py
+++ b/tests/db_engine_specs_test.py
@@ -281,7 +281,10 @@ class DbEngineSpecsTestCase(SupersetTestCase):
         time_grains = set(db_engine_specs.builtin_time_grains.keys())
         # loop over all subclasses of BaseEngineSpec
         for cls_name, cls in inspect.getmembers(db_engine_specs):
-            if inspect.isclass(cls) and issubclass(cls, BaseEngineSpec):
+            if inspect.isclass(cls) and issubclass(cls, BaseEngineSpec) \
+                    and cls is not BaseEngineSpec:
+                # make sure time grain functions have been defined
+                self.assertGreater(len(cls.time_grain_functions), 0)
                 # make sure that all defined time grains are supported
                 defined_time_grains = {grain.duration for grain in 
cls.get_time_grains()}
                 intersection = time_grains.intersection(defined_time_grains)

Reply via email to