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

fix: Adjust find-tables to properly get Oracle and Postgres schemas #1034

Merged
merged 4 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions data_validation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def get_table_map(client, allowed_schemas=None):
"""Return dict with searchable keys for table matching."""
table_map = {}
table_objs = clients.get_all_tables(client, allowed_schemas=allowed_schemas)

for table_obj in table_objs:
table_key = ".".join([t for t in table_obj if t])
table_map[table_key] = {
Expand Down
2 changes: 1 addition & 1 deletion data_validation/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def list_schemas(client):

def list_tables(client, schema_name):
"""Return a list of tables in the DB schema."""
if client.name in ["oracle", "postgres", "db2", "mssql", "redshift", "snowflake"]:
if client.name in ["db2", "mssql", "redshift", "snowflake"]:
return client.list_tables()
return client.list_tables(database=schema_name)

Expand Down
13 changes: 13 additions & 0 deletions third_party/ibis/ibis_postgres/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ def _get_type(typestr: str) -> dt.DataType:
return _parse_numeric(typestr)


def list_schemas(self, like=None):
with self.begin() as con:
# Databases on Postgres are not the same as schemas and for this method we need the schema list (SQL query reference: https://dba.stackexchange.com/a/127668)
schemas = [
row.nspname
for row in con.exec_driver_sql(
"SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname !~ '^pg_' AND nspname <> 'information_schema' ORDER BY 1"
).mappings()
]
return self._filter_with_like(schemas, like)


PostgresBackend._metadata = _metadata
PostgresBackend.list_databases = list_schemas