You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/02/04 04:03:06 UTC

[GitHub] mistercrunch closed pull request #4224: [BugFix]: Creating a PostgresBaseEngineSpec so changes to the Postgre?

mistercrunch closed pull request #4224: [BugFix]: Creating a PostgresBaseEngineSpec so changes to the Postgre?
URL: https://github.com/apache/incubator-superset/pull/4224
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index d26f633bbd..efd37babfc 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -280,8 +280,10 @@ def get_configuration_for_impersonation(cls, uri, impersonate_user, username):
         return {}
 
 
-class PostgresEngineSpec(BaseEngineSpec):
-    engine = 'postgresql'
+class PostgresBaseEngineSpec(BaseEngineSpec):
+    """ Abstract class for Postgres 'like' databases """
+
+    engine = ''
 
     time_grains = (
         Grain('Time Column', _('Time Column'), '{col}'),
@@ -311,6 +313,10 @@ def epoch_to_dttm(cls):
     def convert_dttm(cls, target_type, dttm):
         return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))
 
+
+class PostgresEngineSpec(PostgresBaseEngineSpec):
+    engine = 'postgresql'
+
     @classmethod
     def get_table_names(cls, schema, inspector):
         """Need to consider foreign tables for PostgreSQL"""
@@ -319,6 +325,35 @@ def get_table_names(cls, schema, inspector):
         return sorted(tables)
 
 
+class VerticaEngineSpec(PostgresBaseEngineSpec):
+    engine = 'vertica'
+
+
+class RedshiftEngineSpec(PostgresBaseEngineSpec):
+    engine = 'redshift'
+
+
+class OracleEngineSpec(PostgresBaseEngineSpec):
+    engine = 'oracle'
+
+    time_grains = (
+        Grain('Time Column', _('Time Column'), '{col}'),
+        Grain('minute', _('minute'), "TRUNC(TO_DATE({col}), 'MI')"),
+        Grain('hour', _('hour'), "TRUNC(TO_DATE({col}), 'HH')"),
+        Grain('day', _('day'), "TRUNC(TO_DATE({col}), 'DDD')"),
+        Grain('week', _('week'), "TRUNC(TO_DATE({col}), 'WW')"),
+        Grain('month', _('month'), "TRUNC(TO_DATE({col}), 'MONTH')"),
+        Grain('quarter', _('quarter'), "TRUNC(TO_DATE({col}), 'Q')"),
+        Grain('year', _('year'), "TRUNC(TO_DATE({col}), 'YEAR')"),
+    )
+
+    @classmethod
+    def convert_dttm(cls, target_type, dttm):
+        return (
+            """TO_TIMESTAMP('{}', 'YYYY-MM-DD"T"HH24:MI:SS.ff6')"""
+        ).format(dttm.isoformat())
+
+
 class Db2EngineSpec(BaseEngineSpec):
     engine = 'ibm_db_sa'
     time_grains = (
@@ -1046,42 +1081,6 @@ def convert_dttm(cls, target_type, dttm):
         return "CONVERT(DATETIME, '{}', 126)".format(dttm.isoformat())
 
 
-class RedshiftEngineSpec(PostgresEngineSpec):
-    engine = 'redshift'
-
-
-class OracleEngineSpec(PostgresEngineSpec):
-    engine = 'oracle'
-
-    time_grains = (
-        Grain('Time Column', _('Time Column'), '{col}'),
-        Grain('minute', _('minute'),
-              "TRUNC(TO_DATE({col}), 'MI')"),
-        Grain('hour', _('hour'),
-              "TRUNC(TO_DATE({col}), 'HH')"),
-        Grain('day', _('day'),
-              "TRUNC(TO_DATE({col}), 'DDD')"),
-        Grain('week', _('week'),
-              "TRUNC(TO_DATE({col}), 'WW')"),
-        Grain('month', _('month'),
-              "TRUNC(TO_DATE({col}), 'MONTH')"),
-        Grain('quarter', _('quarter'),
-              "TRUNC(TO_DATE({col}), 'Q')"),
-        Grain('year', _('year'),
-              "TRUNC(TO_DATE({col}), 'YEAR')"),
-    )
-
-    @classmethod
-    def convert_dttm(cls, target_type, dttm):
-        return (
-            """TO_TIMESTAMP('{}', 'YYYY-MM-DD"T"HH24:MI:SS.ff6')"""
-        ).format(dttm.isoformat())
-
-
-class VerticaEngineSpec(PostgresEngineSpec):
-    engine = 'vertica'
-
-
 class AthenaEngineSpec(BaseEngineSpec):
     engine = 'awsathena'
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services