Skip to content

Commit

Permalink
chore(engine): adapt postgres backend connection URI (apache#11233)
Browse files Browse the repository at this point in the history
* chore(engine): adapt postgres backend connection URI

* fix tests

* Update superset/db_engine_specs/__init__.py

Co-authored-by: Ville Brofeldt <[email protected]>

Co-authored-by: Ville Brofeldt <[email protected]>
  • Loading branch information
zhaoyongjie and villebro authored Oct 14, 2020
1 parent 5cbef88 commit 22d8171
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions superset/db_engine_specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@
and attribute.engine != ""
):
engines[attribute.engine] = attribute

# populate engine alias name to engine dictionary
for engine_alias in attribute.engine_aliases or []:
engines[engine_alias] = attribute
1 change: 1 addition & 0 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
"""Abstract class for database engine specific configurations"""

engine = "base" # str as defined in sqlalchemy.engine.engine
engine_aliases: Optional[Tuple[str]] = None
engine_name: Optional[
str
] = None # used for user messages, overridden in child classes
Expand Down
1 change: 1 addition & 0 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def epoch_to_dttm(cls) -> str:

class PostgresEngineSpec(PostgresBaseEngineSpec):
engine = "postgresql"
engine_aliases = ("postgres",)
max_column_name_length = 63
try_remove_schema_from_table_name = False

Expand Down
7 changes: 7 additions & 0 deletions tests/db_engine_specs/postgres_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sqlalchemy import column, literal_column
from sqlalchemy.dialects import postgresql

from superset.db_engine_specs import engines
from superset.db_engine_specs.postgres import PostgresEngineSpec
from tests.db_engine_specs.base_tests import TestDbEngineSpec

Expand Down Expand Up @@ -117,3 +118,9 @@ def test_empty_dbapi_cursor_description(self):
cursor.description = []
results = PostgresEngineSpec.fetch_data(cursor, 1000)
self.assertEqual(results, [])

def test_engine_alias_name(self):
"""
DB Eng Specs (postgres): Test "postgres" in engine spec
"""
self.assertIn("postgres", engines)

0 comments on commit 22d8171

Please sign in to comment.