Skip to content

Commit

Permalink
Merge pull request #2347 from tseaver/2229-bigquery-standard-sql-data…
Browse files Browse the repository at this point in the history
…-types

Add support for Standard SQL dialect 'INT64' and 'FLOAT64' types.
  • Loading branch information
tseaver authored Sep 19, 2016
2 parents 6fb2d73 + bdb3244 commit 17a82db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def _string_from_json(value, _):

_CELLDATA_FROM_JSON = {
'INTEGER': _int_from_json,
'INT64': _int_from_json,
'FLOAT': _float_from_json,
'FLOAT64': _float_from_json,
'BOOLEAN': _bool_from_json,
'TIMESTAMP': _datetime_from_json,
'DATE': _date_from_json,
Expand Down
31 changes: 31 additions & 0 deletions unit_tests/bigquery/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,37 @@ def test_w_record_subfield(self):
coerced = self._callFUT(rows, schema)
self.assertEqual(coerced, expected)

def test_w_int64_float64(self):
# "Standard" SQL dialect uses 'INT64', 'FLOAT64'.
candidate = _Field('REQUIRED', 'candidate', 'STRING')
votes = _Field('REQUIRED', 'votes', 'INT64')
percentage = _Field('REQUIRED', 'percentage', 'FLOAT64')
schema = [candidate, votes, percentage]
rows = [
{'f': [
{'v': 'Phred Phlyntstone'},
{'v': 8},
{'v': 0.25},
]},
{'f': [
{'v': 'Bharney Rhubble'},
{'v': 4},
{'v': 0.125},
]},
{'f': [
{'v': 'Wylma Phlyntstone'},
{'v': 20},
{'v': 0.625},
]},
]
expected = [
('Phred Phlyntstone', 8, 0.25),
('Bharney Rhubble', 4, 0.125),
('Wylma Phlyntstone', 20, 0.625),
]
coerced = self._callFUT(rows, schema)
self.assertEqual(coerced, expected)


class Test_ConfigurationProperty(unittest.TestCase):

Expand Down

0 comments on commit 17a82db

Please sign in to comment.