Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit a7fe1f3

Browse files
committed
made requested changes, with one adjustment: check m.group() value
for truth before attempting the int(), since unwinding 1-2 exceptions per column slows down the reflection process, visibly for wide tables.
1 parent 7b059d0 commit a7fe1f3

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

sqla_vertica_python/vertica_python.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -200,44 +200,39 @@ def get_columns(self, connection, table_name, schema=None, **kw):
200200
where table_name = '{table_name}'
201201
{schema_conditional}
202202
""".format(table_name=table_name, schema_conditional=schema_conditional)
203-
colobjs = [
204-
self._get_column_info(
205-
row.column_name,
206-
row.data_type,
207-
row.is_nullable,
208-
row.column_default,
209-
(row.column_name in primary_key_columns)
210-
)
211-
for row in connection.execute(column_select)
212-
]
213-
return [ c for c in colobjs if c ]
203+
colobjs = []
204+
for row in connection.execute(column_select):
205+
colobj = self._get_column_info(
206+
row.column_name,
207+
row.data_type,
208+
row.is_nullable,
209+
row.column_default,
210+
(row.column_name in primary_key_columns)
211+
)
212+
if colobj:
213+
colobjs.append(colobj)
214+
return colobjs
214215

215216
def _get_column_info(self, name, data_type, is_nullable, default, is_primary_key):
216217
m = re.match(r'(\w+)(?:\((\d+)(?:,(\d+))?\))?', data_type)
217218
if not m:
218-
return {}
219+
raise ValueError("data type string not parseable for type name and optional parameters: %s" % data_type)
219220
typename = m.group(1).upper()
220221
typeobj = self.ischema_names[typename]
221222
typeargs = []
222223
typekwargs = {}
223-
if m.group(2):
224-
try:
225-
v = int(m.group(2))
226-
typeargs.append(v)
227-
except ValueError:
228-
pass
229-
if m.group(3):
224+
for arg_group in (2, 3):
230225
try:
231-
v = int(m.group(3))
232-
typeargs.append(v)
233-
except ValueError:
226+
param = m.group(arg_group)
227+
if param:
228+
typeargs.append(int(param))
229+
except (TypeError, ValueError):
234230
pass
235231

236-
if 'TIMEZONE' in typename or 'TIME ZONE' in typename:
232+
if any(tz_string in typename for tz_string in ('TIMEZONE', 'TIME ZONE', 'TIMESTAMPTZ')):
237233
typekwargs['timezone'] = True
238234

239235
if callable(typeobj):
240-
typeargs = tuple(typeargs)
241236
typeobj = typeobj(*typeargs, **typekwargs)
242237

243238
return {

0 commit comments

Comments
 (0)