-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing confusion when selecting schema across engines (#2572)
- Loading branch information
1 parent
40b3d3b
commit ac84fc2
Showing
4 changed files
with
83 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,43 +6,51 @@ | |
|
||
|
||
class DatabaseModelTestCase(unittest.TestCase): | ||
def test_database_for_various_backend(self): | ||
|
||
def test_database_schema_presto(self): | ||
sqlalchemy_uri = 'presto://presto.airbnb.io:8080/hive/default' | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
url = make_url(model.sqlalchemy_uri) | ||
db = model.get_database_for_various_backend(url, None) | ||
assert db == 'hive/default' | ||
db = model.get_database_for_various_backend(url, 'raw_data') | ||
assert db == 'hive/raw_data' | ||
|
||
sqlalchemy_uri = 'redshift+psycopg2://superset:[email protected]:5439/prod' | ||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals('hive/default', db) | ||
|
||
db = make_url(model.get_sqla_engine(schema='core_db').url).database | ||
self.assertEquals('hive/core_db', db) | ||
|
||
sqlalchemy_uri = 'presto://presto.airbnb.io:8080/hive' | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
url = make_url(model.sqlalchemy_uri) | ||
db = model.get_database_for_various_backend(url, None) | ||
assert db == 'prod' | ||
db = model.get_database_for_various_backend(url, 'test') | ||
assert db == 'prod' | ||
|
||
sqlalchemy_uri = 'postgresql+psycopg2://superset:[email protected]:5439/prod' | ||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals('hive', db) | ||
|
||
db = make_url(model.get_sqla_engine(schema='core_db').url).database | ||
self.assertEquals('hive/core_db', db) | ||
|
||
def test_database_schema_postgres(self): | ||
sqlalchemy_uri = 'postgresql+psycopg2://postgres.airbnb.io:5439/prod' | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
url = make_url(model.sqlalchemy_uri) | ||
db = model.get_database_for_various_backend(url, None) | ||
assert db == 'prod' | ||
db = model.get_database_for_various_backend(url, 'adhoc') | ||
assert db == 'prod' | ||
|
||
sqlalchemy_uri = 'hive://[email protected]:10000/raw_data' | ||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals('prod', db) | ||
|
||
db = make_url(model.get_sqla_engine(schema='foo').url).database | ||
self.assertEquals('prod', db) | ||
|
||
def test_database_schema_hive(self): | ||
sqlalchemy_uri = 'hive://[email protected]:10000/hive/default' | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
url = make_url(model.sqlalchemy_uri) | ||
db = model.get_database_for_various_backend(url, None) | ||
assert db == 'raw_data' | ||
db = model.get_database_for_various_backend(url, 'adhoc') | ||
assert db == 'adhoc' | ||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals('hive/default', db) | ||
|
||
db = make_url(model.get_sqla_engine(schema='core_db').url).database | ||
self.assertEquals('hive/core_db', db) | ||
|
||
sqlalchemy_uri = 'mysql://superset:[email protected]/superset' | ||
def test_database_schema_mysql(self): | ||
sqlalchemy_uri = 'mysql://root@localhost/superset' | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
url = make_url(model.sqlalchemy_uri) | ||
db = model.get_database_for_various_backend(url, None) | ||
assert db == 'superset' | ||
db = model.get_database_for_various_backend(url, 'adhoc') | ||
assert db == 'adhoc' | ||
|
||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals('superset', db) | ||
|
||
db = make_url(model.get_sqla_engine(schema='staging').url).database | ||
self.assertEquals('staging', db) |