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

Commit d381e99

Browse files
committed
Merge branch 'master' of https://github.com/segv/data-diff into segv-master
2 parents 6c610e5 + 92b6d2f commit d381e99

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

data_diff/sqeleton/databases/bigquery.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,31 @@ 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+
if self.default_schema:
163+
return [self.project, self.default_schema, path[0]]
164+
else:
165+
return path
166+
elif len(path) == 2:
167+
return [self.project] + path
168+
elif len(path) == 3:
169+
return path
170+
else:
171+
raise ValueError(f"{self.name}: Bad table path for {self}: '{'.'.join(path)}'. Expected form: [project.]schema.table")
172+
159173
def parse_table_name(self, name: str) -> DbPath:
160174
path = parse_table_name(name)
161175
return tuple(i for i in self._normalize_table_path(path) if i is not None)

0 commit comments

Comments
 (0)