Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BugFix]: Creating a PostgresBaseEngineSpec so changes to the Postgre… #4224

Merged
merged 2 commits into from
Feb 4, 2018
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
75 changes: 37 additions & 38 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'),
Expand Down Expand Up @@ -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"""
Expand All @@ -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 = (
Expand Down Expand Up @@ -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'

Expand Down