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

Commit 08629a7

Browse files
authored
Merge pull request #350 from datafold/pr348
Adjustment to PR #348
2 parents f81300f + 4c5f765 commit 08629a7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

data_diff/sqeleton/databases/bigquery.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,30 @@ def close(self):
145145
self._client.close()
146146

147147
def select_table_schema(self, path: DbPath) -> str:
148-
schema, name = self._normalize_table_path(path)
149-
148+
project, schema, name = self._normalize_table_path(path)
150149
return (
151150
"SELECT column_name, data_type, 6 as datetime_precision, 38 as numeric_precision, 9 as numeric_scale "
152-
f"FROM {schema}.INFORMATION_SCHEMA.COLUMNS "
151+
f"FROM `{project}`.`{schema}`.INFORMATION_SCHEMA.COLUMNS "
153152
f"WHERE table_name = '{name}' AND table_schema = '{schema}'"
154153
)
155154

156155
def query_table_unique_columns(self, path: DbPath) -> List[str]:
157156
return []
158157

158+
def _normalize_table_path(self, path: DbPath) -> DbPath:
159+
if len(path) == 0:
160+
raise ValueError(f"{self.name}: Bad table path for {self}: ()")
161+
elif len(path) == 1:
162+
return (self.project, self.default_schema, path[0])
163+
elif len(path) == 2:
164+
return (self.project,) + path
165+
elif len(path) == 3:
166+
return path
167+
else:
168+
raise ValueError(
169+
f"{self.name}: Bad table path for {self}: '{'.'.join(path)}'. Expected form: [project.]schema.table"
170+
)
171+
159172
def parse_table_name(self, name: str) -> DbPath:
160173
path = parse_table_name(name)
161174
return tuple(i for i in self._normalize_table_path(path) if i is not None)

0 commit comments

Comments
 (0)