googleapis / python-bigquery-sqlalchemy

SQLAlchemy dialect for BigQuery
MIT License
426 stars 127 forks source link

BigQuery's unnest function implementation overrides and breaks this function for other dialects #882

Open altvod opened 1 year ago

altvod commented 1 year ago

If bigquery is installed, the unnest function (defined here) overrides the unnest function for all dialects.

In PostgreSQL usage of unnest is allowed with column identifiers (unnesting an array contained in a table column). But the global re-definition of unnest caused by bigquery makes code like this sa.func.unnest(some_column) fail with TypeError: The argument to unnest must have an ARRAY type. because, obviously, a column is not an array literal.

In my case I really do need many dialects installed at the same time.

altvod commented 1 year ago

The best fix I can think of is to move the logic from this class to the visitor that renders functions in the BQ dialect implementation

chalmerlowe commented 1 year ago

Sorry to hear that you are running into this issue. Thank you submitting this bug/feature request.

If you happen to have code OR a patch that you would like to submit to address this issue feel free to submit a PR.

In the meantime, I will consider this feature request and explore where it should fit in our priority list based on current staffing and workloads.

fordhoka commented 3 months ago

Is there an ETA on this? This is complicating our upgrade to sqlalchemy 2.

In case this helps anyone else experiencing this issue, our workaround was to always unregister the unnest function before connecting to postgresql and then always register it again before connecting to bigquery.