:py:mod:`bigquery.utils` ======================== .. py:module:: bigquery.utils Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: bigquery.utils.flatten bigquery.utils.parse bigquery.utils.query_response_to_dict Attributes ~~~~~~~~~~ .. autoapisummary:: bigquery.utils.log bigquery.utils.utc .. py:data:: log .. py:data:: utc .. py:function:: flatten(x) Flatten response objects into something we can actually work with. The API returns data of the form: {'f': [{'v': ...}]} to indicate groupings of fields and their potential for having multiple values. We want those to just be plain old objects. .. py:function:: parse(field, value) Parse a given field back to a Python object. This is often trivial: convert the value from a string to the type specified in the field's schema. There's a couple caveats we've identified so far, though: * NULLABLE fields should be handled specially, eg. so as not to accidentally convert them to the schema type. * REPEATED fields are nested a biot differently than expected, so we need to flatten *first*, then convert. `Field = Dict[str, Union[str, 'Field']]`, but wow is that difficult to represent in a backwards-enough compatible fashion. .. py:function:: query_response_to_dict(response) Convert a query response to a dictionary. API responses for job queries are packed into a difficult-to-use format. This method deserializes a response into a List of rows, with each row being a dictionary of field names to the row's value. This method also handles converting the values according to the schema defined in the response (eg. into builtin python types).