Skip to content

bigquery.StructQueryParameter should be able to contain structs and arrays #2905

@tswast

Description

@tswast

I commented that structs can contain structs and arrays, but the client library does not support it yet.

I'm testing this on the master branch.

Sample code:

from google.cloud import bigquery

client = bigquery.Client()
query = 'SELECT @struct_value AS s;'
query_results = client.run_sync_query(
    query,
    query_parameters=[
        bigquery.StructQueryParameter(
            'struct_value',
            bigquery.StructQueryParameter(
                'x',
                bigquery.ScalarQueryParameter('a', 'INT64', 42),
                bigquery.ScalarQueryParameter('b', 'STRING', 'what is the answer?')))
    ])
Stacktrace
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
      9                 'x',
     10                 bigquery.ScalarQueryParameter('a', 'INT64', 42),
---> 11                 bigquery.ScalarQueryParameter('b', 'STRING', 'what is the answer?')))
     12     ])

/Users/swast/venvs/google-cloud-python/lib/python3.5/site-packages/google_cloud_bigquery-0.22.1-py3.5.egg/google/cloud/bigquery/helpers.py in init(self, name, *sub_params)
532 self.name = name
533 self.struct_types = OrderedDict(
--> 534 (sub.name, sub.type
) for sub in sub_params)
535 self.struct_values = {sub.name: sub.value for sub in sub_params}
536

/Users/swast/venvs/google-cloud-python/lib/python3.5/site-packages/google_cloud_bigquery-0.22.1-py3.5.egg/google/cloud/bigquery/helpers.py in (.0)
532 self.name = name
533 self.struct_types = OrderedDict(
--> 534 (sub.name, sub.type
) for sub in sub_params)
535 self.struct_values = {sub.name: sub.value for sub in sub_params}
536

AttributeError: 'StructQueryParameter' object has no attribute 'type_'

Ditto for a struct that contains an array:

query_results = client.run_sync_query(
    query,
    query_parameters=[
        bigquery.StructQueryParameter(
            'struct_value',
            bigquery.ArrayQueryParameter(
                'y',
                'STRING',
                ['hello', 'world']))
    ])
Stacktrace
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
      8                 'y',
      9                 'STRING',
---> 10                 ['hello', 'world']))
     11     ])

/Users/swast/venvs/google-cloud-python/lib/python3.5/site-packages/google_cloud_bigquery-0.22.1-py3.5.egg/google/cloud/bigquery/helpers.py in init(self, name, *sub_params)
532 self.name = name
533 self.struct_types = OrderedDict(
--> 534 (sub.name, sub.type
) for sub in sub_params)
535 self.struct_values = {sub.name: sub.value for sub in sub_params}
536

/Users/swast/venvs/google-cloud-python/lib/python3.5/site-packages/google_cloud_bigquery-0.22.1-py3.5.egg/google/cloud/bigquery/helpers.py in (.0)
532 self.name = name
533 self.struct_types = OrderedDict(
--> 534 (sub.name, sub.type
) for sub in sub_params)
535 self.struct_values = {sub.name: sub.value for sub in sub_params}
536

AttributeError: 'ArrayQueryParameter' object has no attribute 'type_'

Metadata

Metadata

Labels

api: bigqueryIssues related to the BigQuery API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to 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