Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 7ada9ec

Browse files
committed
Refactor and fix query_table_schema
1 parent aedced3 commit 7ada9ec

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

data_diff/sqeleton/databases/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ def select_table_schema(self, path: DbPath) -> str:
339339

340340
def query_table_schema(self, path: DbPath) -> Dict[str, tuple]:
341341
rows = self.query(self.select_table_schema(path), list)
342-
if not rows and self.name == 'Redshift':
343-
rows = self.query(self.select_external_table_schema(path), list)
344342
if not rows:
345343
raise RuntimeError(f"{self.name}: Table '{'.'.join(path)}' does not exist, or has no columns")
346344

data_diff/sqeleton/databases/redshift.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import List, Dict
22
from ..abcs.database_types import Float, TemporalType, FractionalType, DbPath
33
from ..abcs.mixins import AbstractMixin_MD5
44
from .postgresql import (
@@ -85,3 +85,18 @@ def select_external_table_schema(self, path: DbPath) -> str:
8585
WHERE tablename = '{table.lower()}' AND schemaname = '{schema.lower()}'
8686
"""
8787
)
88+
89+
def query_external_table_schema(self, path: DbPath) -> Dict[str, tuple]:
90+
rows = self.query(self.select_external_table_schema(path), list)
91+
if not rows:
92+
raise RuntimeError(f"{self.name}: Table '{'.'.join(path)}' does not exist, or has no columns")
93+
94+
d = {r[0]: r for r in rows}
95+
assert len(d) == len(rows)
96+
return d
97+
98+
def query_table_schema(self, path: DbPath) -> Dict[str, tuple]:
99+
try:
100+
return super().query_table_schema(path)
101+
except RuntimeError:
102+
return self.query_external_table_schema(path)

0 commit comments

Comments
 (0)