diff --git a/bigquery/google/cloud/bigquery/_helpers.py b/bigquery/google/cloud/bigquery/_helpers.py index 89eb390993c6..fc6683af916a 100644 --- a/bigquery/google/cloud/bigquery/_helpers.py +++ b/bigquery/google/cloud/bigquery/_helpers.py @@ -79,6 +79,7 @@ def _string_from_json(value, _): 'FLOAT': _float_from_json, 'FLOAT64': _float_from_json, 'BOOLEAN': _bool_from_json, + 'BOOL': _bool_from_json, 'TIMESTAMP': _datetime_from_json, 'DATE': _date_from_json, 'RECORD': _record_from_json, diff --git a/bigquery/unit_tests/test__helpers.py b/bigquery/unit_tests/test__helpers.py index 46c58c8ea405..c42ac56f680e 100644 --- a/bigquery/unit_tests/test__helpers.py +++ b/bigquery/unit_tests/test__helpers.py @@ -284,33 +284,37 @@ def test_w_record_subfield(self): coerced = self._call_fut(rows, schema) self.assertEqual(coerced, expected) - def test_w_int64_float64(self): - # "Standard" SQL dialect uses 'INT64', 'FLOAT64'. + def test_w_int64_float64_bool(self): + # "Standard" SQL dialect uses 'INT64', 'FLOAT64', 'BOOL'. candidate = _Field('REQUIRED', 'candidate', 'STRING') votes = _Field('REQUIRED', 'votes', 'INT64') percentage = _Field('REQUIRED', 'percentage', 'FLOAT64') - schema = [candidate, votes, percentage] + incumbent = _Field('REQUIRED', 'incumbent', 'BOOL') + schema = [candidate, votes, percentage, incumbent] rows = [ {'f': [ {'v': 'Phred Phlyntstone'}, {'v': 8}, {'v': 0.25}, + {'v': 'true'}, ]}, {'f': [ {'v': 'Bharney Rhubble'}, {'v': 4}, {'v': 0.125}, + {'v': 'false'}, ]}, {'f': [ {'v': 'Wylma Phlyntstone'}, {'v': 20}, {'v': 0.625}, + {'v': 'false'}, ]}, ] expected = [ - ('Phred Phlyntstone', 8, 0.25), - ('Bharney Rhubble', 4, 0.125), - ('Wylma Phlyntstone', 20, 0.625), + ('Phred Phlyntstone', 8, 0.25, True), + ('Bharney Rhubble', 4, 0.125, False), + ('Wylma Phlyntstone', 20, 0.625, False), ] coerced = self._call_fut(rows, schema) self.assertEqual(coerced, expected)