Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tswast opened this issue Dec 28, 2016 · 1 comment
Closed
Assignees
Labels
api: bigquery Issues related to the BigQuery API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tswast
Copy link
Contributor

tswast commented Dec 28, 2016

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_'

@tswast tswast added api: bigquery Issues related to the BigQuery API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 28, 2016
@danoscarmike danoscarmike added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. Status: Acknowledged labels Feb 28, 2017
@tseaver
Copy link
Contributor

tseaver commented May 16, 2017

Fixed in #3180.

@tseaver tseaver closed this as completed May 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants