Skip to content

Commit

Permalink
Merge pull request #2789 from tseaver/bigquery-standard_sql_bool
Browse files Browse the repository at this point in the history
Add support for standard SQL 'BOOL' type.
  • Loading branch information
tseaver authored Dec 1, 2016
2 parents 091c9bd + 5f9f78b commit 7cd1569
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions bigquery/google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions bigquery/unit_tests/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7cd1569

Please sign in to comment.