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

Support for get_schema_names in Dialect #16

Merged
merged 1 commit into from
May 25, 2018
Merged

Support for get_schema_names in Dialect #16

merged 1 commit into from
May 25, 2018

Conversation

AchilleAsh
Copy link
Contributor

ClickHouseDialect.get_schema_names was not implemented: its role is just to list the databases.

The implementation already exists in cloudfare sqlalchemy-clickhouse driver so it does make sense to also support it here.

@xzkostyan
Copy link
Owner

What's the difference between schema and database then?

It's better not to show schemas at all. There will be less misunderstanding in terminology.

@AchilleAsh
Copy link
Contributor Author

Hi,

Let me give you 2 examples :

MySQL

On MySQL, database is equivalent to schema: one database can only have one schema,
so SHOW schemas is the same as SHOW databases

Details on the documentation: https://mariadb.com/kb/en/library/show-databases/

The SQLA Dialect is therefore straightforward for MySQL:

@reflection.cache  
def get_schema_names(self, connection, **kw):  
    rp = connection.execute("SHOW schemas")  
    return [r[0] for r in rp]

Postgresql

On Postgresql, one database can support multi schemas, then each schema has table: by default the schema is called public and can be omitted in the query. The schema can be see as a namespace/folder to organize tables.
The SQLA Dialect is implemented using the pg_namespace catalog located in the pg_catalog schema.

You can read more details on the official doc: https://www.postgresql.org/docs/current/static/ddl-schemas.html

Now in our case Clickhouse is not multi schemas so it behave like MySQL: one database has one schema.
Clickhouse has no schema awareness, the only namespace-like function we can achieve is by using databases (just like MySQL): That's why as in MySQL Dialect, the Clickhouse Dialect should return the databases as schemas.

SQLA goal is to provide an abstraction layer on top of multiple SQL DB, some with multi schemas, some without: they had to have the notion of schemas, but here we have to take the shortcut schema == database because that's the Clickhouse logic.

I hope my explications were clear,
Timothé

@xzkostyan
Copy link
Owner

Thanks!

@xzkostyan xzkostyan merged commit 0e1b7a0 into xzkostyan:master May 25, 2018
@coveralls
Copy link

coveralls commented May 25, 2018

Coverage Status

Coverage increased (+14.1%) to 96.364% when pulling e4a5b2b on AchilleAsh:master into c35d332 on xzkostyan:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+14.1%) to 96.364% when pulling e4a5b2b on AchilleAsh:master into c35d332 on xzkostyan:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants