def test_from_api_repr_w_struct_type(self): from google.cloud.bigquery.query import StructQueryParameter RESOURCE = { 'parameterType': { 'type': 'ARRAY', 'arrayType': { 'type': 'STRUCT', 'structTypes': [ { 'name': 'name', 'type': {'type': 'STRING'}, }, { 'name': 'age', 'type': {'type': 'INT64'}, }, ], }, }, 'parameterValue': { 'arrayValues': [ { 'structValues': { 'name': {'value': 'Phred Phlyntstone'}, 'age': {'value': '32'}, }, }, { 'structValues': { 'name': { 'value': 'Bharney Rhubbyl', }, 'age': {'value': '31'}, }, }, ], }, } klass = self._get_target_class() param = klass.from_api_repr(RESOURCE) phred = StructQueryParameter.positional( _make_subparam('name', 'STRING', 'Phred Phlyntstone'), _make_subparam('age', 'INT64', 32)) bharney = StructQueryParameter.positional( _make_subparam('name', 'STRING', 'Bharney Rhubbyl'), _make_subparam('age', 'INT64', 31)) self.assertEqual(param.array_type, 'STRUCT') self.assertEqual(param.values, [phred, bharney])
def test_from_api_repr_w_struct_type(self): from google.cloud.bigquery.query import StructQueryParameter RESOURCE = { 'parameterType': { 'type': 'ARRAY', 'arrayType': { 'type': 'STRUCT', 'structTypes': [ { 'name': 'name', 'type': {'type': 'STRING'}, }, { 'name': 'age', 'type': {'type': 'INT64'}, }, ], }, }, 'parameterValue': { 'arrayValues': [ { 'structValues': { 'name': {'value': 'Phred Phlyntstone'}, 'age': {'value': '32'}, }, }, { 'structValues': { 'name': { 'value': 'Bharney Rhubbyl', }, 'age': {'value': '31'}, }, }, ], }, } klass = self._get_target_class() param = klass.from_api_repr(RESOURCE) phred = StructQueryParameter.positional( _make_subparam('name', 'STRING', 'Phred Phlyntstone'), _make_subparam('age', 'INT64', 32)) bharney = StructQueryParameter.positional( _make_subparam('name', 'STRING', 'Bharney Rhubbyl'), _make_subparam('age', 'INT64', 31)) self.assertEqual(param.array_type, 'STRUCT') self.assertEqual(param.values, [phred, bharney])
def test_to_api_repr_w_record_type(self): from google.cloud.bigquery.query import StructQueryParameter EXPECTED = { "parameterType": { "type": "ARRAY", "arrayType": { "type": "STRUCT", "structTypes": [ {"name": "foo", "type": {"type": "STRING"}}, {"name": "bar", "type": {"type": "INT64"}}, ], }, }, "parameterValue": { "arrayValues": [ {"structValues": {"foo": {"value": "Foo"}, "bar": {"value": "123"}}} ] }, } one = _make_subparam("foo", "STRING", "Foo") another = _make_subparam("bar", "INT64", 123) struct = StructQueryParameter.positional(one, another) klass = self._get_target_class() param = klass.positional(array_type="RECORD", values=[struct]) self.assertEqual(param.to_api_repr(), EXPECTED)
def test_to_api_repr_w_record_type(self): from google.cloud.bigquery.query import StructQueryParameter EXPECTED = { "parameterType": { "type": "ARRAY", "arrayType": { "type": "STRUCT", "structTypes": [ {"name": "foo", "type": {"type": "STRING"}}, {"name": "bar", "type": {"type": "INT64"}}, ], }, }, "parameterValue": { "arrayValues": [ {"structValues": {"foo": {"value": "Foo"}, "bar": {"value": "123"}}} ] }, } one = _make_subparam("foo", "STRING", "Foo") another = _make_subparam("bar", "INT64", 123) struct = StructQueryParameter.positional(one, another) klass = self._get_target_class() param = klass.positional(array_type="RECORD", values=[struct]) self.assertEqual(param.to_api_repr(), EXPECTED)
def test_to_api_repr_w_record_type(self): from google.cloud.bigquery.query import StructQueryParameter EXPECTED = { 'parameterType': { 'type': 'ARRAY', 'arrayType': { 'type': 'STRUCT', 'structTypes': [ {'name': 'foo', 'type': {'type': 'STRING'}}, {'name': 'bar', 'type': {'type': 'INT64'}}, ], }, }, 'parameterValue': { 'arrayValues': [{ 'structValues': { 'foo': {'value': 'Foo'}, 'bar': {'value': '123'}, } }] }, } one = _make_subparam('foo', 'STRING', 'Foo') another = _make_subparam('bar', 'INT64', 123) struct = StructQueryParameter.positional(one, another) klass = self._get_target_class() param = klass.positional(array_type='RECORD', values=[struct]) self.assertEqual(param.to_api_repr(), EXPECTED)
def test_to_api_repr_w_record_type(self): from google.cloud.bigquery.query import StructQueryParameter EXPECTED = { 'parameterType': { 'type': 'ARRAY', 'arrayType': { 'type': 'STRUCT', 'structTypes': [ {'name': 'foo', 'type': {'type': 'STRING'}}, {'name': 'bar', 'type': {'type': 'INT64'}}, ], }, }, 'parameterValue': { 'arrayValues': [{ 'structValues': { 'foo': {'value': 'Foo'}, 'bar': {'value': '123'}, } }] }, } one = _make_subparam('foo', 'STRING', 'Foo') another = _make_subparam('bar', 'INT64', 123) struct = StructQueryParameter.positional(one, another) klass = self._get_target_class() param = klass.positional(array_type='RECORD', values=[struct]) self.assertEqual(param.to_api_repr(), EXPECTED)
def test_from_api_repr_w_struct_type(self): from google.cloud.bigquery.query import StructQueryParameter RESOURCE = { "parameterType": { "type": "ARRAY", "arrayType": { "type": "STRUCT", "structTypes": [ {"name": "name", "type": {"type": "STRING"}}, {"name": "age", "type": {"type": "INT64"}}, ], }, }, "parameterValue": { "arrayValues": [ { "structValues": { "name": {"value": "Phred Phlyntstone"}, "age": {"value": "32"}, } }, { "structValues": { "name": {"value": "Bharney Rhubbyl"}, "age": {"value": "31"}, } }, ] }, } klass = self._get_target_class() param = klass.from_api_repr(RESOURCE) phred = StructQueryParameter.positional( _make_subparam("name", "STRING", "Phred Phlyntstone"), _make_subparam("age", "INT64", 32), ) bharney = StructQueryParameter.positional( _make_subparam("name", "STRING", "Bharney Rhubbyl"), _make_subparam("age", "INT64", 31), ) self.assertEqual(param.array_type, "STRUCT") self.assertEqual(param.values, [phred, bharney])
def test_from_api_repr_w_struct_type(self): from google.cloud.bigquery.query import StructQueryParameter RESOURCE = { "parameterType": { "type": "ARRAY", "arrayType": { "type": "STRUCT", "structTypes": [ {"name": "name", "type": {"type": "STRING"}}, {"name": "age", "type": {"type": "INT64"}}, ], }, }, "parameterValue": { "arrayValues": [ { "structValues": { "name": {"value": "Phred Phlyntstone"}, "age": {"value": "32"}, } }, { "structValues": { "name": {"value": "Bharney Rhubbyl"}, "age": {"value": "31"}, } }, ] }, } klass = self._get_target_class() param = klass.from_api_repr(RESOURCE) phred = StructQueryParameter.positional( _make_subparam("name", "STRING", "Phred Phlyntstone"), _make_subparam("age", "INT64", 32), ) bharney = StructQueryParameter.positional( _make_subparam("name", "STRING", "Bharney Rhubbyl"), _make_subparam("age", "INT64", 31), ) self.assertEqual(param.array_type, "STRUCT") self.assertEqual(param.values, [phred, bharney])