joshtemple / harlequin-bigquery

A BigQuery adapter for Harlequin, a SQL IDE for the terminal.
MIT License
8 stars 2 forks source link

Data catalog error caused by parametrised data types #8

Closed christippett closed 10 months ago

christippett commented 10 months ago

Certain BigQuery data types can have parameters attached that constrain their properties (see here). These are currently incompatible with the type definition/patterns used by this adapter.

When launching Harlequin with the BigQuery adapter a catalog error pops up with the following message:

'NUMERIC(5,2)' is not a valid StandardSqlTypeNames

The error is caused when a table includes a parameterised data type in its DDL, e.g:

CREATE TABLE `dataset.table` (
  col1 NUMERIC(5,2)
)

Taking a quick look at the source code, all that might be needed is to update the regex pattern when parsing the column type to include stripping parenthesises as well as angled brackets:

https://github.com/joshtemple/harlequin-bigquery/blob/0d44ff61180ee7517bba2069c69eb8f8eefbebdb/src/harlequin_bigquery/adapter.py#L187

column_type_cleaned = re.sub(r"[\<\(].*[\>\)]", "", row.column_type)

I haven't tested the above though. If I have time over the coming week I can look to testing this more thoroughly and submit a PR.