Skip to content

unnest isn't handled correctly #283

Closed
@jimfulton

Description

@jimfulton

Given a table, foo, with schema:
[SchemaField('objects', 'RECORD', 'REPEATED', None, (SchemaField('object_id', 'STRING', 'NULLABLE', None, (), ()),), ())]

>>> foo = Table('foo', metadata, autoload_with=engine)
>>> print(select([func.unnest(foo.c.objects).alias('foo_objects').column]).compile(engine))
SELECT `foo_objects` 
FROM unnest(`foo`.`objects`) AS `foo_objects`

BigQuery needs this select to be spelled:

SELECT foo_objects
FROM `foo`, UNNEST(`foo`.`objects`) as foo_objects

or

SELECT foo_objects
FROM `foo`, UNNEST(`objects`) as foo_objects

The

`foo`

in the FROM is needed to establish an alias for interpreting

`foo`.`objects `

or for providing a default table for

`objects `

But otherwise, there's no special requirement for the extra from.

In particular, consider:

select x from unnest([1,2,3]) as x

which needs no extra from because the expression given to unnest doesn't reference a column.

The fact that unnest takes an expression that may have 0 or more column references (from zero or more tables) makes the fix rather complicated.

(The examples above don't show a dataset, because it's set as a default.)

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/python-bigquery-sqlalchemy API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions