Skip to content

Commit

Permalink
fix: Adjust find-tables to properly get Oracle and Postgres schemas (
Browse files Browse the repository at this point in the history
…#1034)

* Debugging find-tables issue

* Remove debugging printing of schemas and table maps

* fix: Add override method to list schemas for Postgres
  • Loading branch information
helensilva14 committed Nov 11, 2023
1 parent 14cc7ef commit 45fb40a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

0 comments on commit 45fb40a

Please sign in to comment.